Tasker - Scheduled Nandroid Backup with File Management [V4]
Profile Aim
DUE TO CHANGES IN ROM MANAGER THIS IS CURRENTLY NOT WORKING!
Working on a fix....
To take a nandroid backup whilst you sleep and manage the backup files so no more than two are stored.
Downloads
ROM Manager Free from the market
Locale Execute Plugin Free from the market
Icons used are Glossy Silver HD free from 'Download more icons' prompt in Tasker
Profile Explanantion
V2 - [Dropped] (But good for educational purposes)
Code:
There are only a few actions to explain in more detail:
The task [B]NandroidFiles[/B] 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 [I]sdcard/clockworkmod/backup/[/I] and automatically named [I]scheduledbackup-2011-06-02-05.00.00/[/I]
The '2011-06-02' is initially a problem as this is almost the opposite of Tasker's inbuilt [B]%DATE[/B] variable formatted as '6-2-11'. We need to use Tasker's [B]%DATE[/B] 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 [B]%DATE[/B] to the created variable [B][B]%NDATE[/B][/B] before 'variable splitting' it by the '-' to leave 6 2 and 11 in [B]%NDATE1[/B], [B]%NDATE2[/B] and [B]%NDATE3[/B] 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...?!!? :eek:
The answer is to use a 'pseudo-array' from [URL="http://groups.google.com/group/tasker/browse_thread/thread/1e1c531b900312e9#"]this thread[/URL] with credit to the brains of [URL="http://androidforums.com/members/unclemike.html"]UncleMike [/URL]. 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.
[CODE]x(1)31(1)(2)31(2)(3)28(3)(4)31(4)(5)30(5)(6)31(6)(7)30(7)(8)31(8)(9)31(9)(10)30(10)(11)31(11)(12)30(12)x
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
scheduledbackup-%NDATE-05.00.01/,
scheduledbackup-%NDATE-05.00.02/,
scheduledbackup-%NDATE-05.00.03/ etc to the text file to make sure all options are covered.
For your reference, locale execute plugin uses the command:
Code:
@! 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...
Sorted?[/CODE]
V4 - (Very Easy)
Forces closes on the latest release, when trying to use the ROM manager intents have meant another way was needed to get Tasker to manage this. BIG thanks to
waydownsouth who cracked it in style.
The first profile will check the version number you are running before writing a file to the cache/recovery folder, which will trigger the automatic backup when booting into recovery.
The file management is done in the same way as version 3.
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:
Code:
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.
Any questions, let me know!
Credits
waydownsouth for sharing the auto-backup work-around and help with syntax
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
As always, the thanks button is the only way I know I should keep posting this stuff
And please don't forget the users above too!
Note:
You will need to grant SuperUser permissions for each command prior to the profile running correctly. I would suggest you add a STOP action above the final 'execute reboot' command, then keep pressing 'test' until SuperUser has stopped requesting permissions - remove the STOP action and the task will run automatically thereafter.
IMPORTANT NOTE:
After importing the profiles ensure you 'apply' out of Tasker so they are saved. If you run the profiles without doing this, the profiles will not be there after the reboot! Please always backup your Tasker profiles initially too. Thanks to waydownsouth for pointing this out!