Automagic Backup

Share and discuss your flows and ideas with other users.

Moderator: Martin

Post Reply
User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Automagic Backup

Post by Desmanto » 20 Jan 2019 17:59

This is an automated Automagic Flows, Widgets, glovar and other helper folder backup. I haven't completely finish this flow yet. (20190121)
AM Backup 20190121
AM Backup.png
AM Backup.png (247.92 KiB) Viewed 24471 times
The concept of the backup flow is inspired by my nightmare here : viewtopic.php?f=4&t=7272

Backup concept
- We choose the files/folder to backup. In Automagic case, the essential ones are flows.xml, widgets.xml and variables.bin. But I include 2 of my resource and helper folder too, since I store data and configuration at there.
- The flow should backup everyday at certain time, ideally at 00:00 everyday. You can change the time if you turn off your phone at night.
- The flow retain the last 7 days backup, even though nothing has changed. Actually everytime any flow is executed, the flows.xml is modified, since it contains the last executed time and duration. So, daily backup is highly recommended. Number of days retained backup can be increased if you don't change the flows much everyday
- There is no notification that the backup is success, since we will assume it is successful everyday. Just like Whatsapp backup, it never notify us that the backup is success. The flow should be one time set and forget, which is the sign of a good technology.
- But we will create a secondary check, at another time, to check if the backup is successful. I put it at 8 o'clock at the morning (can be changed to other time). If the previous backup is not found, it will notify the error and inform us to do the backup manually at that time. So only errors will notify, successful backup will be silent.
- There is manual backup option, and retain the last 3 manual backup. (you can increase this). This is separated from the daily backup and can retain as long as you want, but only the last 3. You need this maybe before try to factory reset (remember to copy the backup to somewhere else before reset) or before trying something dangerous such as deleting or messing up with a lot of flows at once.
- There is option to check current backup list, to know the summary of available backup.
- Manual backup and secondary check backup will have message to show current backup list too (daily one doesn't show it)
- For safety reason, there is no direct way to delete the backup. I use MiXplorer to browse to the folder and we have to manually delete the excess (outside of 7 days and 3 manual backups).

- I have planned to create the restore version, but not yet finish
- Glovar is harder to restore, I planned to make the separate backup/restore choice using json.
- I have the method to upload to Gdrive or local samba/FTP server. But you can just replace the unusual init file and the zip menu with MiXplorer zip task too.

Flow trigger
This backup flow currently contains 4 triggers
1. {tshorcut} Shortcut: AM Backup, is used to backup manually, manage the backup, and browse the folder to delete it manually. Further addition in the future (I don't know when), I plan to add restore per flow/widget, backup/restore for individual glovar
2. {tdaily} Time: everyday 00:00, is used to perform daily backup. Ideally should be at the beginning of each day, hence 00:00.
3. {tcheck} Time: everyday 08:00, is used to check if the daily backup is successful. Ideally should be at the time when you start your daily activity, so you will be notified immediately when it fails.
4. {tnotif} Notification on Statusbar Selected: ID 15, used to perform the manual backup when the 08:00 check notify the backup unsuccessful. This is manual backup, but used to replaced the missed daily backup.

Branches
1. Shortcut branch, is feed to input dialog, to choose the menu. The menu is splitted to 4 branches.
a. Backup Now, is to perform the backup manually, save the backup with tag Manual
b. Check Backup, to check current list of backup, size and time
c. Restore Flows and Restore widgets, haven't implemented yet
d. Browse Backup, open the backup folder using file manager (I used MiXplorer). From there you can delete unnecessary backup manually

2. Time 08:00, check the last daily backup. If there is no backup during the last 9 hours (up to 23:00 yesterday), it will create notification

3. Time 00:00 and Notification tapped, to perform the daily backup and missed daily backup if the notification is tapped. This branch will use the same "Backup Now" branch form 1a, but have additional check at the end. If it comes from the Backup Now or the notification, both are manual backup. Auto daily backup have no notif on statusbar, only toast message. But manual backup will perform Check Backup after the backup is finish. So you have feedback to confirm the backup is done. (see the last backup datetime).

Variable and configuration
There is script action in the beginning of the flow to declare all available variable. I made this so it is easier for you to modify the rest of the configuration simply by changing the variables in here.

tshortcut, tdaily, tcheck, tnotif = all the triggers name. If you change your trigger (example the schedule) or the trigger name, make sure you copy the name and put it here according to the trigger
notifid = the ID you use for the notif. I use 15, you can use other if 15 is used up in yours. Change both the trigger name and this notifid.

ziplist = list of files to be backup. I have additional 2 folders, Resources and Speech to backup. If you don't need this, remove these 2 lines.
path = path to store the backup. Make sure it is not in the same folder as Automagic default folder.

retdaily = retained daily backup, default is 7 days
retmanual = retained manual backup, default is 3 last backups
hourcheck = secondary check for failed backup. Change the last x hours to check. If you check at 08:00, and backup at 00:00. use 9 (hours)

Other thing you can change
backup time = change the 00:00 and 08:00 to the time you can perform the backup automatically
File manager = change the file manager to the one you use. If you use MiXplorer as I do, you can leave it there. But remember, MiXplorer now has 3 packagename, the regular one (that I use), beta and silver. Make sure you choose the correct package name, using the ellipsis button.
Action zip files can be added to upload the zip directly to your gdrive or any other server. I don't add it in here. You can use MiXplorer for the copying/zipping : viewtopic.php?f=6&t=7849#p23452

Initialization
This flow doesn't use any glovar. All you have to do is to modify the triggers to suit your need and enable the flow. The flow has been protected from manual execution (3 dot menu > execute). To execute this flow, you must add the trigger shortcut to the home screen and execute from there.

Testing
- Try the shortcut and perform manual backup. You should see the notif that the backup is done and the list of the backup.
- Tap again and choose check backup.
- Restore flow/widget are not finished yet, so you only see toast message.
- Tap browse backup, you should open the backup folder in your file manager you choose.

The catch
During editing and testing, If you perform the daily backup and have error especially with deletion, it is possible that your daily backup becomes more than 7. The script will remove the last 7 days backup, so don't worry, all excess backups will be deleted after 7 days. Only the last 7 days are retained. Same with manual backups, if you have more than 3 (4 backups or more), the script only delete the oldest one. So your backup still 4. You can delete the manual backup, leaving only 3. I don't plan to make a check for this, you need to delete the excess backup manually. Since this happen only if you run the flow outside of the designated logic.

Epilog
Hopefully this will help you to backup your important flow/widget/glovar and save you from disaster as I have experience here : viewtopic.php?f=4&t=7272
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

yxd0018
Posts: 85
Joined: 05 Dec 2018 15:14

Re: Automagic Backup

Post by yxd0018 » 06 Mar 2019 20:55

I like to read your code. Wish my coworker has half of your style.

heliosone
Posts: 39
Joined: 26 Mar 2016 08:39

Re: Automagic Backup

Post by heliosone » 23 Jun 2019 14:50

can you help me create a (much simplier) backup flow so I can backup each flow group into a seperate folder,and within this folder,each group-flow as a seperate xml file ?
i.e. /mnt/sdcard/automagic/backup/<groupname>/<flow1.xml>
as automagic still doesnt have an import wizard,that allows you to choose which flows to import from a large xml backup file,this is the only way to seperate flows during backup.

ideal addon would be to create a <date>-folder on top,so each backup cycle creates its own backup folder.
i.e. /mnt/sdcard/automagic/backup/<triggertime>/<groupname>/<flow1.xml>

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Automagic Backup

Post by Desmanto » 23 Jun 2019 17:38

That is one of my to do list actually. I am thinking to export each flows into single xml, grouped by their flow group, then by date, then zip it, just like what you want.
But I have digress so long, that I need to relearn my flow in order to add that feature. I even haven't finish my glovar manager flow, which is quite crucial now. Since my glovar started to piled up quickly.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

heliosone
Posts: 39
Joined: 26 Mar 2016 08:39

Re: Automagic Backup

Post by heliosone » 24 Jun 2019 05:47

until then I can live with my complete flow backup,but of course a seperate backup would be great !

rubaboo
Posts: 10
Joined: 20 Oct 2019 19:50

Re: Automagic Backup

Post by rubaboo » 03 Nov 2019 07:27

Could you make it possible to run the backup manually from Automagic by selecting "Execute". I'd rather not have a shortcut in my launcher just for this. Thanks a lot!

Post Reply