Nandroid Backup whilst you sleep with file management

Profile Aim

To take a nandroid backup whilst you sleep and manage the backup files so no more than two are stored.


ROM Manager Free from the market
Locale Execute Plugin Free from the market

Profile Explanantion

Version 2 - (Dropped) (But still good for educational purposes)

There are only a few actions to explain in more detail:

The task **NandroidFiles** deletes the Nandroid backups from two days before. I set this as two days so not to use too much storage space and to make sure there was a spare backup in case the daily backup task failed for any reason.

The back up folder is found in //sdcard/clockworkmod/backup/// and automatically named //scheduledbackup-2011-06-02-05.00.00///

The '2011-06-02' is initially a problem as this is almost the opposite of Tasker's inbuilt **%DATE** variable formatted as '6-2-11'. We need to use Tasker's **%DATE** minus two days to match it to the dated backup file we want to delete.

Following the task through, you'll see that we transfer **%DATE** to the created variable **%NDATE** before 'variable splitting' it by the '-' to leave 6 2 and 11 in **%NDATE1**, **%NDATE2** and ***%NDATE3** respectively.

So, it's the 2nd of June for the sake of this example and using basic maths would mean that two days before this would be the 2-2 of June = 0th of June!? That's obviously no good to us... It should be the 31st May, so how do we easily do that...?!!?

The answer is to use a 'pseudo-array' from [ this thread] with credit to the brains of [ UncleMike]. Now don't take a look at the below and give up reading, because it's actually a very simple and useful process. Honest(!): 

If we are in the 6th month of the year which is June and our -2 days are taking us back to the number of days in May, then we need to quickly reference the 6th month to the 31 days of May. Have a look below and you'll see that between the brackets of (6) is the number 31.


We set the above to a created variable of **%NMONTH** and using a very simple variable split of the current month number of 6, which in the previous split was set to **%NDATE1** we get **%NMONTH1** to be set to 31! 

Using this method we can say that if the current day of the month is less than 3, then we need to use the above to find out the number of days in the previous month. So, we can then add the current day of the month which for this example is the 2nd of June, to the 31 days in May, 31+2=33 Taking 2 from this gives us 31! Sorted! Other than that we now need the month to show as '5' rather than the current '6'. 

We know that if the day of the month is less than 3, we are going to be using a date from the previous month - so that is the **IF** statement we use. **IF** the day of the month **%NDATE1** is less than 3, then we know we need to -1 from the month number **%NDATE2**. Sorted!

I explained that in as much detail as I could for you. I hope it made sense. Once we've done the above maths we 'variable join' the date together in the same format as the clockmod backup folder.

The next problem we have is that the backup, although triggered by a time context of 5am, can actually be delayed. I've had a backup named //scheduledbackup-2011-06-02-05.00.//**07**/. Unfortunately, [ pattern matching] is not yet available in Tasker to use on file names, otherwise using the wildcard of '*' to delete the file //scheduledbackup-2011-06-02-05.00.0*/// would have been a simple option.

Remembering that the date format **%NDATE** of the backup is needed to reference the file, we also cannot simply use locale execute to delete the file //scheduledbackup-**%NDATE**-05.00.0*///. Tasker doesn't pass variables to it in that way. 

The solution is to ask locale execute to delete files that are listed in a .txt file on the storage card. This way, we can tell Tasker to write //scheduledbackup-**%NDATE**-05.00.0*/// to a text file beforehand. That's not strictly true though, as stated above, pattern matching of '*' is not available (yet) in file names.. so as a workaround for now, we write


etc to the text file to make sure all options are covered.

For your reference, locale execute plugin uses the command:

@! xargs rm -rf < /mnt/sdcard/nandroiddel.txt

The '@!' stops the command from being flashed up on the screen. The remainder of the command tells locale to delete the files listed in the file //nandroiddel.txt//.

I think that's about it!? A nandroid backup whilst you sleep, with the backup files managed...


Version 3 - (Very Easy)

Version 2 used a long-winded work-around to manage the backup files. But thanks to those mentioned in the credits below, there is a much, much more simple way using Locale Execute Plugin and a Linux command:

find /mnt/sdcard/clockworkmod/backup -mtime +1 -exec rm -rf {} \;

The '+1' in the above command denotes how many days prior to today the backups will be deleted. It's up to you to alter this number depending on how many backups you wish to keep and how often you make them.

The days and time are configurable within the profiles.

That's it!

heywtf for the discovery of the auto-backup intent
UncleMike for his genius 'pseudo-array'.
crachel the Tasker guru for letting me hijack his thread and agreeing to answer all of your questions ;)

Download the profile here

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License