[Profile] [Root] Auto Nandroid backup Manager


  1. SUroot

    SUroot Well-Known Member

    Inspired by Silentwitness' question here:

    http://androidforums.com/tasker/677671-help-nandroid-backup-via-tasker.html

    I wrote this profile / script and have created a thread for it.Content

    Contents

    Who is this profile for?
    What does this profile do exactly?
    What do I need to know / understand before using this profile?
    What is included in this "Profile"?
    The Script
    Note to S3 users
    Note to Other device users
    I want to change this to use my External SD card. How?
    Download


    Who is this profile for?

    This profile has been created for root users. In particular, those who use a ClockWorkMod (CWM) based recovery to take Nandroid backups. A Nandroid backup is a complete image (or snapshot if you will) of the phone at the time it is taken. When a Nandroid backup is restored, the phone is returned to exactly* as it was when the backup was taken.

    * Some elements aren't backed up on all devices, such as the Radio/Modem/Baseband


    What does this profile do exactly?

    This profile will Automatically create a Nandroid backup, every Saturday at 04:00 (am). It boots into recovery, takes the backup and then boots back into Android.

    This profile has a 2 week backup retention, so you will always have a maximum of 2 backups, the oldest one being deleted before the new one is taken.

    You can also add a widget to the homescreen:

    Long press home screen > Add Widget > Task > nandroid

    This will allow you to take a backup (and reboot automatically) from your homescreen directly. The Schedule will not be overridden, however, the oldest backup will have been replaced.

    WARNING - There is no confirmation on this as yet. Pressing it will immediately boot into recovery. I recommend if you can spare a homescreen to this on its own, please do so.


    What do I need to know / understand before using this profile?

    To use this profile, you need to know the mount points on your phone both in android and recovery.

    For example, on the s3 there is an internal and an external SD card.

    In android (S3) these are:
    internal - /mnt/sdcard
    external - /mnt/extSdCard

    In CWM recovery (S3) these are:
    internal - /data/media
    external - /external_sd

    First you must decide if you are going to use the Internal or External SD card.

    On a phone that has NO external sdcard, you would follow the rationale of the S3's internal sdcard (/mnt/sdcard in android).

    Similarly if you have a phone that has NO internal sdcard, you would still follow the rationale of the internal sdcard (/mnt/sdcard in android).

    Essentially EVERY device will use /mnt/sdcard for their Storage, whether that's an external Micro SD card or Internal SD card. Only devices that have an internal AND external SD card will need to look into that deeper.

    People with root explorers can browse to the root of their device, find the /mnt directory and see what everything is mounted as. You will be able to get everything you need to use for the "in Android" settings. As for recovery, this could vary from device to device so if you don't know, ask in the development thread (Probably XDA) of your device's recovery.

    Note. Mount points are case sensitive. /mnt/extsdcard will not work if it's supposed to be /mnt/extSdCard


    What is included in this "Profile"?

    The profile consists of 2 elements.

    1) The tasker Profile
    2) The nandroid.sh script (that needs to be in /mnt/sdcard/clockworkmod/)

    Both of these elements are in the attached zip file.


    The Script

    This script by default uses /mnt/sdcard/clockworkmod/backup as the backup location.

    This is the Internal SD card for devices that have both an internal AND external SD card.

    This is the External SD card for devices that ONLY have an external SD card.

    The backup MUST go in the clockworkmod/backup folder because if it does not, your recovery will not be able to restore the backups. It works best on the /mnt/sdcard directory because this is universal for all devices. However, some devices wipe the internal SD when factory resetting from the Android menu (Galaxy S3), so only reset from recovery.

    Here is an extract of the script (and what it does):

    Code:
    # Set today's date
    now=$(date +"%d_%m_%y-%H:%M")
    
    # Deletes previous archive (as contained within index1.txt)
    rm -rf $(cat /mnt/sdcard/clockworkmod/backup/index1.txt)
    
    # Moves previous backup to archive (index2 becomes index1 for delete next time)
    mv /mnt/sdcard/clockworkmod/backup/index2.txt /mnt/sdcard/clockworkmod/backup/index1.txt
    
    # Stamps new index 2
    echo '/mnt/sdcard/clockworkmod/backup/'$now > /mnt/sdcard/clockworkmod/backup/index2.txt
    
    # writes a command for recovery to read (creates index2 backup)
    echo 'backup_rom("/data/media/clockworkmod/backup/'$now'");' > /cache/recovery/extendedcommand

    Note to S3 users

    If you are happy with using the internal SD card for backups, this profile and script can be used unmodified.

    Note to Other device users

    If you are happy with using the default location of /mnt/sdcard, this script will require minimal modification. Please note that the last command of the script as show below:

    Code:
    backup_rom("/data/media/clockworkmod/backup/'$now'");
    Is where the S3's CWM recovery mounts the /mnt/sdcard (as /data/media). This will most likely be different on otehr devices so you need ensure you know your equivelant.

    See again: What do I need to know / understand before using this profile?


    I want to change this to use my External SD card. How?

    OK, I'll tell you how. Firstly, I will write this as if it was asked by an S3 user because I know the relevant alternative mount points in Android and recovery for this device.

    If you do not know your mount points, see again: What do I need to know / understand before using this profile?


    1. Modifying the script.

    Its best to do this on a computer. Use a notepad or text application that has a "Find and replace" function.

    Find: mnt/sdcard
    Replace: mnt/extSdCard

    Find: data/media
    Replace: external_sd

    The script now needs to be put into /mnt/extSdCard/clockworkmod/backup

    2. Modifying the profile

    Well, it's actually editing the task but hey ho...

    Open step 1. of the task. Change /mnt/sdcard/ to /mnt/extSdCard/ and save the task / profile.

    That's it...

    [​IMG]

    Downloads

    Attached Files:


    Advertisement
    jobics, D-U-R-X, kennymck and 4 others like this.
  2. DragonSlayer95

    DragonSlayer95 Resident Air Bender Moderator

    Very nice!

    Thanks for this, it'll definitely come in handy :D

    DS
  3. SUroot

    SUroot Well-Known Member

    D'oh. I forgot to mention it uses secure settings pro, but actually I re-uploaded it because now it doesn't need it. I made as glaring omission from the idea that "reboot recovery" works as a command on android. I feel stupid now.
  4. silentwitness

    silentwitness Well-Known Member

    lol i just bought secure settings pro and the profile does not work for me the phone just reboots and goes into recovery but does not do anything after it reboots does not backup anything.

    edit:-

    i cant download the file i get "Invalid Attachment specified. If you followed a valid link, please notify the administrator"
  5. SUroot

    SUroot Well-Known Member

    Fixed the link.

    What do you see in recovery? You may see an error? How long is it in recovery? You will see it backing up if its backing up and will be in recovery for a few minutes. The screen should look exactly the same as if manually backing up. You're using Philz?

    Disable the reboot into recovery part of the task please then play the task. Then using a root explorer of some kind, go to /cache/recovery and check extendedcommand is present (and its contents)

    The updated profile only changes the reboot to recovery action, so it wont fix the issue either, so the issue is something before that.
  6. SUroot

    SUroot Well-Known Member

    Just confirmed profile is definitely working for me. Need to see whats different for you. On the GT-i9300 it should work out of the box, with no additional config or manipulation
  7. silentwitness

    silentwitness Well-Known Member

    my phone reboots into recovery and just stays on the main recovery screen(like it would if u boot into recovery no error or anything) it does not do anything i dont see a screen saying backup in progress or anything like that. I am running siyah kernel and a dual boot if that makes a difference. using philz touch recovery.
  8. SUroot

    SUroot Well-Known Member

    Do what I said 2 posts ago. Sounds like /cache/recovery/extendedcommand is not present.

    Also check index files to see if they're blank inside
  9. SUroot

    SUroot Well-Known Member

    And confirm you have the script in the correct place....

    /sdcard/clockworkmod/nandroid.sh

    No capital letters. Internal sd only
  10. silentwitness

    silentwitness Well-Known Member

    i ended up switching my 1st rom(omega) and 2nd rom(neat rom) after which it started working. I was trying to use it from neatrom.
  11. SUroot

    SUroot Well-Known Member

    Ah good info.

    Yes, I suppose that's because the 2nd ROM is on /sdcard already, so it changes the location of everything else. /sdcard/clockworkmod becomes /sdcard/rom/sdcard/clockworkmod or something
  12. silentwitness

    silentwitness Well-Known Member

    ya maybe but its working now i clicked on the play button and it worked. got another strange issue with free space now i dunno whats happening to my phone one issue after another.
  13. silentwitness

    silentwitness Well-Known Member

    Ok strange issue i had an existing backup on 19 and made another backup today(21st) and it has overwritten the backup i had of the 19th there is however a file in the backup folder called index1.txt which has a path to the old backup but the path does not exist. any ideas?
  14. SUroot

    SUroot Well-Known Member

    Here's what happens.

    1. Delete old backup (index1)
    2. Make last backup an old backup (index2 becomes index1)
    3. Take a new backup (index2)

    You should always have 2 backups with index1 being the oldest.

    Since you ran the profile many times, who knows what's right. The best thing would be to delete all backups and index files. Take ONE backup using the task if you must. That then puts the backup in the index2 slot.


    If you take multiple backups on the same day, they all have the same date so they could all be deleted when index1 has that date in it
  15. SUroot

    SUroot Well-Known Member

    Here's what happens.

    1. Delete old backup (index1)
    2. Make last backup an old backup (index2 becomes index1)
    3. Take a new backup (index2)

    You should always have 2 backups with index1 being the oldest.

    Since you ran the profile many times, who knows what's right. The best thing would be to delete all backups and index files. Take ONE backup using the task if you must. That then puts the backup in the index2 slot.


    If you take multiple backups on the same day, they all have the same date so they could all be deleted when index1 has that date in it
  16. silentwitness

    silentwitness Well-Known Member

    the whole folder i had with the date of 19th is missing now. I ran the profile on 19th and made a backup then ran it again today(21st) and made another backup so technically it should have kept both backups intact.
  17. SUroot

    SUroot Well-Known Member

    Yes it should have, but your script does nothing different to mine.

    You MUST have ran the task another time, to get that folder date in index 1.

    Anyway, action to be taken as previous post. Let the profile do its business. Do not interfere with the profile and task by running it manually all the time.

    Please note if you press play on the task twice in one day, even if it does not backup, the index files will change so you must avoid doing this.

    • Action > Delete all index files and folders in /clockworkmod/backup
    • Take one backup using the task

    Then you will be starting fresh.
    silentwitness likes this.
  18. silentwitness

    silentwitness Well-Known Member

    ok i deleted both index files and ran the backup again now only have 1 index file called index2.txt. It contains information for 21_01_13 which is the new backup i created today. So now when the task runs automatically on the weekend it will create index1.txt i assume?
  19. SUroot

    SUroot Well-Known Member


    So when the task runs, it will delete the folder mentioned in index1 (but this time it doesn't exist).

    Then it renames index2 to index1

    Then it creates a new index2 with the name of the backup its going to take.

    Then it takes a backup.



    To clarify, index2 is always newest backup. Index1 is always the next one to be deleted.

    So it:

    Deletes oldest backup
    Renames newest backup to oldest backup
    Creates new newest backup.

    Its hard to describe. Hope it makes sense
    silentwitness likes this.
  20. silentwitness

    silentwitness Well-Known Member

    ok cool thanks a million for all ure help :) will just check the folder after the next schedule run and see.
  21. SUroot

    SUroot Well-Known Member

    Awesomeness!
  22. SUroot

    SUroot Well-Known Member

    Would it be worth adding time to the backup name and a widget to manually trigger Nandroids?
  23. SUroot

    SUroot Well-Known Member

    OK I did. Added time to backup and a nandroid widget to kick off a backup (means dont have to wait a day between backups)
    silentwitness likes this.
  24. silentwitness

    silentwitness Well-Known Member

    ok quick question now sure if its possible with tasker or not i have this profile setup it is working great but i have setup a pin lock for my phone is there anyway to get tasker to enter the pin lock when it boots again after doing the backup??
  25. SUroot

    SUroot Well-Known Member

    When is the pinlock presented? Is this a different pin lock to the lockscreen? Is it a boot up pin?

Share This Page