0

I am using Cyanogenmod with CWM and am currently doing a manual weekly Nandroid backup (plus daily scheduled TitaniumBackup runs). Needless to say, it is easy to skip or forget.

Is there a way to have the nandroid backups automated? I.e., I would like the phone to shutdown into recovery once a week, do a backup, and reboot.

2
  • I don't know about CWM but it is quite easy to do through TWRP using OpenRecoveryScript. Let me know, should you want the details.
    – Firelord
    Commented Sep 30, 2016 at 14:36
  • A quick google shows it to be promising; it seems to be compatible with my device (i9100 / Galaxy S2) and OS (CM 11) and the install seems to be as easy as firing up CWM and flashing a ZIP. Do you now whether TWRP nandroid backups are 100% compatible with CWM and vice versa (i.e. can I restore a backup made in either of those recoveries with the other one)? If you can add an answer with more details on how to get the backup to run automatically (without manually having to enter recovery; say every Sunday at 4am or something like that), that would be great.
    – AnoE
    Commented Sep 30, 2016 at 15:48

1 Answer 1

1

Provided that you're using TWRP with version 2.1 (might work for higher versions too) and your data partition is not encrypted, you can make good use of OpenRecoveryScript.

The concept: When booted into recovery mode TWRP looks for a file named openrecoveryscript under the location /cache/recovery/. If the file is found, it is read and the instructions therewith executed accordingly. Once all the instructions are finished executing, the device reboots normally. All of this happens automatically the moment TWRP is fired up.

The important steps to make an automatic nandroid backup using TWRP are:

  1. Create the file openrecoveryscript under /cache/recovery. You would need root access to write into that location.
  2. Write into that file the instructions you want TWRP to execute. In my case I write:
backup SDCBM WeeklyBackup

You can understand the details about the command here. In short, I'm simply backing up System(S), Data(D), Cache(C), Boot(B) without creating MD5sums(M) and saving the backup with the name WeeklyBackup. The backup would automatically be saved under /sdcard/TWRP/BACKUPS/<device_serial>.

  1. Afterwards, I set the appropriate permission on that script using the command:

    chmod 664 /cache/recovery/openrecoveryscript; 
    

Here's what I use to make an automatic backup in my Nexus 6:

  1. I found an automation app which allows editing a file, copying a file to directories with privileged access, or provides command-line access with superuser/root privileges. (I personally use Tasker, but MacroDroid and Automate may also work.)
  2. I created a day based profile in conjunction with a time based profile to trigger the backup on a certain day of the week/month and at a specific time.

Related: How to create a profile with multiple context in Tasker? 3. I added a task in that profile with following actions:

  1. Code → Run Shell:

    • Command:

      <pre>
      

echo backup SDCBM WeeklyBackup > /cache/recovery/openrecoveryscript; chmod 664 /cache/recovery/openrecoveryscript;

     The first command would create the file openrecoveryscript and write the backup instruction in it. 
 * tick Use Root.
  1. System → Reboot → Type: Recovery.

The profile and task is very flexible, so you can make it more convenient to you, such as by pushing a notification or a toast with a time wait action at the beginning that the system would now make backup, so you should save your work or stop doing any important task and more...

2
  • 1
    With Android using encryption by default these days, this method results in TWRP asking for the password, even when using the decrypt my_password instruction in the openrecoveryscript. Have you found a way to automate this anyway?
    – Forivin
    Commented May 29 at 12:03
  • 1
    @Forivin I have not been using any automation to make TWRP backups. I don't have anything to offer at the moment. I'll update this answer to inform other users that the answer does not work for encrypted Android phones.
    – Firelord
    Commented May 29 at 14:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .