Interesting. What's the ro.build.id on the stock ROM? Same as ro.build.display.id?
Yes, same
Interesting. What's the ro.build.id on the stock ROM? Same as ro.build.display.id?
You should reword this to "that are not more than 14 days old."Edit: Method 2 – Check the Modified Date of Backup Folders
So the other way is to just go through each of the folders and see if their date of modification is older than X days. If so, then delete them. This method doesn't require that you've set up the names in any specific way; only that they're in separate folders, so you can just add %DATE without the other steps in the post above. This method goes as follows:
Instead of the Files --> Delete Directory action, you need to add several actions, which will delete all the backup folders that are not the 3 latest.
Here are the actions:
?Code:1. List Files: [i]dir[/i] [B]TWRP/BACKUPS/YOURDEVICEUNIQUEID[/B] [i]variable[/i] [B]%dirs[/B] [COLOR="DimGray"](where YOURDEVICEUNIQUEID needs to be set appropriately, as described in OP)[/COLOR][/QUOTE] If I wanted to only check the scheduled backups, and not any manual backups I may have done in TWRP, and assuming that I named my scheduled backups with the prefix "auto-", would I just have to change the above line to: [CODE][i]dir[/i] [B]TWRP/BACKUPS/YOURDEVICEUNIQUEID/auto*[/B]
K, sure. Turns out the names method is simpler but requires more setup in the backup naming. I'll add in the end of the post the other method.
Method 1 – Check the Name Backup Folders
First you need to add the date to the backup dir's name. But it has to be formatted in a way that, when sorted alphabetically, it'll sort the backups chronologically. So the format I'm showing is yyyy-mm-dd (same as %DATE but reversed, so years are in front). Here's the actions to set up that name:
Following that, instead of Tasker's built-in %DATE, you can use %date, and it'll represent the current date in yyyy-mm-dd format (so today is 2016-03-11).Code:1. Variable Set: [i]name[/i] [B]%date[/B] [i]to[/i] [B]%DATE[/B] 2. Variable Split: [i]name[/i] [B]%date[/B] [i]splitter[/i] - [COLOR="DimGray"](dash)[/COLOR] 3. Variable Set: [i]name[/i] [B]%date[/B] [i]to[/i] [B]%date3-%date2-%date1[/B]
After that definition, add the tasks, described in the OP with the following corrections:
1. instead of backup SDBOM weeklybackup use backup SDBOM Backup-%date – adding the %date variable, set up above
2. instead of the Files --> Delete Directory action, you need to add several actions, which will delete all the backup folders that are not the 3 latest. The logic behind the loop is get the names of all directories in alphabetical order (which arranges them from oldest to newest), and deleting all folders except the last 3 (which are the 3 latest). Here are the actions:
And then you can set the SecureSettings Reboot to Recovery action, as described in OP.Code:1. List Files: [i]dir[/i] [B]TWRP/BACKUPS/YOURDEVICEUNIQUEID[/B] [i]variable[/i] [B]%dirs[/B] [COLOR="DimGray"] (where YOURDEVICEUNIQUEID needs to be set appropriately, as described in OP)[/COLOR] 2. Variable Set: [i]name[/i] [B]%end[/B] [i]to[/i] [B]%dirs(#)-3[/B] [i]do maths[/i] [B]checked[/B] [COLOR="DimGray"](That'll gives the number of directories-3. Change that number to the amount of backups you want to save)[/COLOR] 3. For: [i]variable[/i] [B]%del[/B] [i]items[/i] [B]%dirs(:%end)[/B] [COLOR="DimGray"](For each of the directories from the first to the n-th last, defined in the action above, perform the following actions)[/COLOR] 4. Delete Directory: [i]dir[/i] [B]%del[/B] [i]recurse[/i] [B]checked[/B] [COLOR="DimGray"](this deletes the directory taken from the action above)[/COLOR] 5. End For [COLOR="DimGray"](ends the loop)[/COLOR]
Hope that helps. Haven't tested the whole thing with TWRP backups and reboot – only quickly test with some made-up directories. If you want to use this, it's not a bad idea to test yourself in a separate task before going all-in and incorporating everything in the main task. Though, that said, it should work fine.
PS: A quick note: TWRP will make a backup after that, so if you leave 3 backups, then you'll end up with 4. So keep that in mind, because you may not have enough space and in that case TWRP wont make the backup.
Not all that thoroughly tested but should work fine. Again – test yourself first before using it.
Hey there. I really appreciate the effort you've put in this. I was stunned about your knowledge and wanted this to work on my phone too.
I used method 1, but everytime I run the task it boots into TWRP and doesn't create a backup. There's just a short error message and then it goes back to the TWRP homescreen.
Do you know what may cause the problem? I've set it up just like you did. Unfortunately it's quite too difficult for me to figure out what the problem is, since I don't have any clue what all these tasks are doing :laugh: (I'm a noob).
Ah yeah and it doesn't reboot from TWRP, I have to do it manually.
Any help would be greatly appreciated
Hey there,
It's probably be one of two things: Either you've typed the twrp script wrong and it doesn't regognize the commands, or (more likely) you don't have enough free space for the backup. While in twrp, after unsuccessful execution of the task, tap the button to show the log and you should see exactly what the error is.
Also, the reason it doesn't reboot is probably because it starts the backup command but is interrupted by the error (lack of free space) and thus doesn't get to the reboot command.
Take a look into that, that should probably fix it
Cheers
Thank you for your reply. I was so frustrated that it didn't work that I went back to the original script in the OP.
But I will have a look after what you said when I have time this evening and will report back
I think it's the shell command that I got wrong. Could you give me the whole shell command with the new "Backup-%dates" line? That would be awesome
Thank you very much!
chmod 0777 /cache/recovery
echo "wipe cache\nwipe dalvik\nbackup SDBOM Backup-%date \ncmd reboot" > /cache/recovery/openrecoveryscript
Suddenly the task stopped working. Now am getting the error that tasker could not delete the folder on my ext card
Running AOSP 6.0.1 JDCTeam
Anyone with similar problem? Any solution to that?
Any chance that the folder doesn't exist? If Tasker tries to delete a folder that doesn't exist, the action will return error. If "Continue on error" is not checked, the task will stop and not finish.
Hmm... I've been running this task manually for a while and finally decided to automate it, but I can't seem to get it to trigger on the time I specify. Any ideas why?
You would need to give more info. What are you doing exactly and what is happening?
[…]So let me ask you again, how could I have the For loop just delete old automatic backups, and leave any manual backups I may have done, regardless of age?
In the beginning, in the action "List Files", enter a matching pattern that collects your autobackups but excludes your manual ones. That's it.
dir TWRP/BACKUPS/YOURDEVICEUNIQUEID/auto*
dir TWRP/BACKUPS/YOURDEVICEUNIQUEID/
auto*
What I tried before was this:
but that didn't work. It prevented the task from completing and the phone didn't reboot and complete the backup.Code:dir TWRP/BACKUPS/YOURDEVICEUNIQUEID/auto*
What I am trying now is this:
and below this line, there is a line called Match, and so there I added:Code:dir TWRP/BACKUPS/YOURDEVICEUNIQUEID/
Code:auto*
This allowed the task to complete and for the phone to do the TWRP backup. Now to wait a few days and see if the older "auto" backups gets deleted.
UPDATEIt does exist. I think I found the culprit: MM gives a lot of headache in terms of permissions to access extSD, so I started using Apps2SD in order to link folders from extSD to intSD, thus to save space on my internal storage. One of the linked folders was TWRP. I just unlinked it. Will need to wait 1 day to see, if the delete option works
UPDATE
Tasker is not able to delete files on my ext card on MM ;-(
Could you please elaborate on that? I am a real n00b when it comes to Tasker
With Tasker you can execute Linux commands. Thus, you can execute a command to tell the OS to delete a folder, regardless of where it is (given you have the right permissions). I can't test it but open Tasker, open Run Shell, and use any Linux command you want there. For example to delete a directory, you can use rmdir ( read more here http://www.mediacollege.com/cgi-bin/man/page.cgi?topic=rmdir ). Have a look on google for the native Linux commands that you can use in a terminal and that'll open your opportunities in Tasker quite a lot. All the "File" actions in Tasker can be done via commands.Could you please elaborate on that? I am a real n00b when it comes to Tasker
chmod 0777 /cache/recovery
echo "wipe cache\nwipe dalvik\nbackup SDBOM weeklybackup \ncmd reboot" > /cache/recovery/openrecoveryscript
Ok, but I'll be a little shorter in description, hope it's still clear:/me raises his hand
I've been meaning to get around to creating my own version of this profile to suit my needs. Some of the things you mentioned are of interest; however they are more advanced than my current knowledge. I've gotten pretty good at using If, Else and Stop If statements involving simple variables, though. Bring it on!
Sent from my LG-D850 using XDA Labs
input tap 540 910
input tap 540 910
input tap 540 910
input tap 540 910
K, sure. Turns out the names method is simpler but requires more setup in the backup naming. I'll add in the end of the post the other method.Are you saying that you know how to do this with tasker? If so, how? That's the real question.
1. Variable Set: [i]name[/i] [B]%date[/B] [i]to[/i] [B]%DATE[/B]
2. Variable Split: [i]name[/i] [B]%date[/B] [i]splitter[/i] - [COLOR="DimGray"](dash)[/COLOR]
3. Variable Set: [i]name[/i] [B]%date[/B] [i]to[/i] [B]%date3-%date2-%date1[/B]
1. List Files: [i]dir[/i] [B]TWRP/BACKUPS/YOURDEVICEUNIQUEID[/B] [i]variable[/i] [B]%dirs[/B]
[COLOR="DimGray"] (where YOURDEVICEUNIQUEID needs to be set appropriately, as described in OP)[/COLOR]
2. Variable Set: [i]name[/i] [B]%end[/B] [i]to[/i] [B]%dirs(#)-3[/B] [i]do maths[/i] [B]checked[/B]
[COLOR="DimGray"](That'll gives the number of directories-3. Change that number to the amount of backups you want to save)[/COLOR]
3. For: [i]variable[/i] [B]%del[/B] [i]items[/i] [B]%dirs(:%end)[/B]
[COLOR="DimGray"](For each of the directories from the first to the n-th last, defined in the action above, perform the following actions)[/COLOR]
4. Delete Directory: [i]dir[/i] [B]%del[/B] [i]recurse[/i] [B]checked[/B]
[COLOR="DimGray"](this deletes the directory taken from the action above)[/COLOR]
5. End For
[COLOR="DimGray"](ends the loop)[/COLOR]
1. List Files: [i]dir[/i] [B]TWRP/BACKUPS/YOURDEVICEUNIQUEID[/B] [i]variable[/i] [B]%dirs[/B]
[COLOR="DimGray"](where YOURDEVICEUNIQUEID needs to be set appropriately, as described in OP)[/COLOR]
2. For: [i]variable[/i] [B]%processed_item[/B] [i]items[/i] [B]%dirs()[/B]
[COLOR="DimGray"](starting the loop – going through each of the backup directories)[/COLOR]
3. Test File: [i]type[/i] [B]Modified[/B] [i]data[/i] [B]%processed_item[/B] [i]store result in[/i] [B]%mod_date[/B]
[COLOR="DimGray"](for each of the directories check the modified date)[/COLOR]
4. Variable Set: [i]name[/i] [B]%days_old[/B] [i]to[/i] [B](%TIMES - %mod_date) / (60*60*24)[/B] [i]do maths[/i] [B]checked[/B]
[COLOR="DimGray"](the result is in seconds, so here we convert it to days)[/COLOR]
5. Delete Directory: [i]dir[/i] [B]%processed_item[/B] [i]recurse[/i] [B]checked[/B] [i]if[/i] [B]%days_old > 14[/B]
[COLOR="DimGray"](Delete the directory, if the modified date is from more than 14 days ago. Change the days to whatever you want)[/COLOR]
6. End For
No idea.. what I DO know is that this script gave me a hang on boot :<
Make a complete backup before running the script for the first time!
I am not sure yet why, but maybe someone (OP?) can help me out here..
I'm using an HTC One M8 with Marshmallow rom (ViperOneM8) which is stock HTC Sense based.
I use TWRP 2.7.8.0
Did you try: http://wiki.rootzwiki.com/OpenRecoveryScriptI do my backup to a usb-otg drive though. What do I need to modify in this profile to make sure that the backup gets stored only on the otg drive and skips entirely if no otg drive is mounted?