9to5cynic
Android Expert
Okay, so this is a script to backup the nandroids on your phone.
Requirements:
I thought of this as kinda an automated process, so a cronjob.
It seems to be working with both AMON RA and CLOCKWORKMOD recoveries. I sent it off to marc12868 to see if clockwork works with someone who actually *has* clockwork installed [if he says it doesn't work, then i'll fix it]. I just set up a folder to mimic the folder structures. It should work.
If you want to run it each time, which works, then you only need to change the two variables phone and backup. $phone is just where your device is mounted. Mine was /media/0A00-1234 or something like that. $backup is the (you guessed it) backup directory.
Steps
Okay, so if that's your first cronjob, it'll ask you to pick an editor, 2 (default) is fine (nano), but if you're hardcore go with vi
then add this line to it (at the bottom)
Nandroid Backup Script:
I'm sure there are a lot of better ways to do this, but I don't know them. :vroam:
more words
:five:
Requirements:
- Linux (it's a bash script)
- USB mode for your phone
I thought of this as kinda an automated process, so a cronjob.
It seems to be working with both AMON RA and CLOCKWORKMOD recoveries. I sent it off to marc12868 to see if clockwork works with someone who actually *has* clockwork installed [if he says it doesn't work, then i'll fix it]. I just set up a folder to mimic the folder structures. It should work.
If you want to run it each time, which works, then you only need to change the two variables phone and backup. $phone is just where your device is mounted. Mine was /media/0A00-1234 or something like that. $backup is the (you guessed it) backup directory.
Steps
- Save this script somewhere ($HOME/nandroid.sh)
- grant it execute permissions (chmod +x nandroid.sh)
- either run it (./nandroid.sh) or
- get it working with cron (below)
Code:
crontab -e
then add this line to it (at the bottom)
Code:
* * * * * /home/YOURNAME/nandroid.sh
Nandroid Backup Script:
Code:
#!/bin/bash
#############
#9to5cynic
#provided as is and all that shit.
#####################################################
# Nandroid Backup Script
# This will copy, tar.gz and remove nandroids from your phone's SD card
# and place them in your backup directory.
######################################################
#Okay, to set this up, just change your phone variable to the what your device is
# mine was something like /media/A001-3214 or something similar.
# backup is just your backup directory.
######################################################
phone='/media/1gb'
backup='/home/kyle/nandroid/'
######################################################
df -k | grep $phone &>/dev/null
grep_phone=$?
if [[ $grep_phone -eq 0 ]]
then
# phone lock file, see if this is running alread.
ls /tmp | grep "backup.lock" 1>/dev/null
grep_lock=$?
if [[ $grep_lock -eq 0 ]]
then
echo ":::: FILE LOCK FOUND ::::"
exit 10
else
touch /tmp/backup.lock
# looking for amon-ra style recoveries - /sdcard/nandroid/SERIAL-NO/
ls $phone | grep 'nandroid' 1>/dev/null
type=$?
if [[ $type -eq 0 ]]
then
uid=$( ls ${phone}/nandroid/ )
phonepath="${phone}/nandroid/${uid}"
unset type
fi
# looking for clockworkmod recoveries - /sdcard/clockworkmod/backup/
ls $phone | grep "clockwork" 1>/dev/null
type=$?
if [[ $type -eq 0 ]]
then
phonepath="${phone}/clockworkmod/backup/"
unset type
fi
mkdir /tmp/nand
#checks the contents of the backup folder, so it doesn't copy already backed up files
ls ${backup} > /tmp/backup.list
# copy files from sd card to temp folder
content=$( ls $phonepath )
for line in $content
do
grep ${line}.tar.gz /tmp/backup.list 1>/dev/null
grep_check=$?
if [[ $grep_check -eq 1 ]]
then
cp -Rp ${phonepath}${line} /tmp/nand 1>/dev/null
fi
done
nand=$( ls /tmp/nand/)
pwd=$(pwd)
#tar.gz the files
for line in $nand
do
cd /tmp/nand/
tar czfv ${backup}${line}.tar.gz ${line} 1>/dev/null
rm -r ${phonepath}${line}
done
#house cleaning, remove temp files and other shit.
cd $pwd
unset {phone,backup,pwd,uid,nand,grep_check,grep_lock,grep_phone}
rm /tmp/backup.lock
rm /tmp/backup.list
rm -r /tmp/nand
exit 20
fi
else
echo "::::::::::PHONE NOT FOUND!:::::::::::::"
exit 0
fi
more words
Well, I tried this several times on my computer and with my phone, seems to work fine. It'll backup the nandroid folder to the backup folder (after tar.gz). It also removes all the contents of the nandroid folder, so you might want to copy one back over (after un tar.gz'ing it)....
but, if it sees that you already have a backup of a nandroid, it won't copy them so - that's nice.
Code:
tar zxvf 2012-04-30.tar.gz