Commit 805b9816 authored by Ameer Dawood's avatar Ameer Dawood
Browse files

v1.0

Initial release.
parents
Nandroid backups are usually performed in recovery mode. This means you would have to turn off your phone and reboot in recovery mode, which wastes a whole lot of time rebooting and a lot more time offline. For me, this has been a killer as I do regular nandroid backups. Having to reboot in recovery and finding missed calls, sms from my wife and friends is totally not accepatable for me. So, I set to develop an online nandroid backup tool which can do nandroid backups without switching off my phone.
This tool backups /system , /data , /cache , .android_secure & sd-ext (from version 3) partitions to /sdcard/clockworkmod/backup directory. The date format used for folder name is the same used by CWM itself and nandroid backups created with this tool can safely be restored using CWM. If you would want to have a custom name for backup folder, pass an argument with the name to the script and it will use the name.
\ No newline at end of file
#!/sbin/sh
# Usage instructions
if [ $1 == "--help" ]; then
echo "Usage: 'onandroid desired_backup_name'"
echo "Note: A default backup name consisting of the current date and time is used if no backup name is provided."
exit 0
fi
echo "##########################################"
echo "Online Nandroid Backup v1.0"
echo "* A tool to perform a nandroid backup"
echo " without booting into recovery. It can"
echo " be run via adb shell or terminal"
echo " emulator in Android, thus allowing"
echo " you to do a live nandroid backup"
echo " within Android."
echo "* This tool backups /system , /data , "
echo " /cache & .android_secure partitions."
echo "* It is fully compatible with nandroid."
echo "* Pass an argument to customize"
echo " backup name."
echo "* Created by Ameer Dawood"
echo "##########################################"
echo ""
# Start timer
start_time=`date +%s`
# Define constants
def_name=`date -u +%Y-%m-%d.%H.%M.%S`
path="/sdcard/clockworkmod/backup"
# Check for required tools
echo "`date +%T` Checking for required tools..."
mkyaffs2image=`which mkyaffs2image`
if [ "$mkyaffs2image" == "" ]; then
echo "`date +%T` Error: mkyaffs2image not found in path."
exit 1
fi
md5sum=`which md5sum`
if [ "$md5sum" == "" ]; then
echo "`date +%T` Error: md5sum not found in path."
exit 1
fi
tar==`which tar`
if [ "$tar" == "" ]; then
echo "`date +%T` Error: tar not found in path."
exit 1
fi
sleep 1
echo "`date +%T` All required tools available."
# Disk space check (in MB)
safety=4
echo "`date +%T` Checking disk space..."
entry=`df -m /system | tail -1`
u_system=`echo $entry | cut -d' ' -f3 | cut -d'%' -f1`
entry=`df -m /data | tail -1`
u_data=`echo $entry | cut -d' ' -f3 | cut -d'%' -f1`
entry=`df -m /cache | tail -1`
u_cache=`echo $entry | cut -d' ' -f3 | cut -d'%' -f1`
entry=`df -ma /sdcard/.android_secure | tail -1`
u_as=`echo $entry | cut -d' ' -f3 | cut -d'%' -f1`
req_space=`expr $u_system + $u_data + $u_cache + $u_as + $safety`
entry=`df -m /mnt/sdcard | tail -1`
freespace=`echo $entry | cut -d' ' -f3 | cut -d'%' -f1`
echo "`date +%T` SD Card Free Space: $freespace MB"
echo "`date +%T` Required Space: $req_space MB"
if [ $freespace -lt $req_space ]; then
echo "`date +%T` Not enough disk space! Exiting!"
exit 1
else
echo "`date +%T` Necessary disk space available! Continuing..."
fi
# Change to backup directory
cd $path
# Deny file names with spaces
if [ $# -gt 1 ]; then
echo "`date +%T` Filenames with spaces are not allowed!"
name=$def_name
else
name="$1"
fi
# Grab backup name, if provided, or generate name with current date & time
if [ $# == 0 ]; then
name=$def_name
else
name="$1"
fi
# Create directory for backup
echo "`date +%T` Creating backup directory..."
if [ ! -d $name ]; then
mkdir -p $name
if [ ! -d $name ]; then
echo "`date +%T` Error: Cannot create $name"
exit 1
fi
else
touch $name/.nandroidwritable
if [ ! -e $name/.nandroidwritable ]; then
echo "`date +%T` Error: Cannot write to $name"
exit 1
fi
rm $name/.nandroidwritable
fi
echo "`date +%T` Backing up to $path/$name"
echo "`date +%T` Opening backup directory..."
cd $name
# Backup system
echo -e "`date +%T` Backing up /system...\c"
mkyaffs2image /system system.yaffs2.img &
while [ `pidof mkyaffs2image` ]; do
echo -n "."
sleep 2
done
echo ""
# Backup data
echo -e "`date +%T` Backing up /data...\c"
mkyaffs2image /data data.yaffs2.img &
while [ `pidof mkyaffs2image` ]; do
echo -n "."
sleep 2
done
echo ""
# Backup cache
echo -e "`date +%T` Backing up /cache...\c"
mkyaffs2image /cache cache.yaffs2.img &
while [ `pidof mkyaffs2image` ]; do
echo -n "."
sleep 2
done
echo ""
# Backup .android_secure
echo -e "`date +%T` Backing up .android_secure...\c"
cd /sdcard
tar -cf $path/$name/.android_secure.vfat.tar .android_secure &
while [ `pidof tar` ]; do
echo -n "."
sleep 2
done
echo ""
cd $path/$name
# Generate md5
echo -e "`date +%T` Generating md5sum...\c"
md5sum .android_secure.vfat.tar * > nandroid.md5 &
while [ `pidof md5sum` ]; do
echo -n "."
sleep 2
done
echo ""
# End timer
end_time=`date +%s`
elapsed=`expr $end_time - $start_time`
# Announce
echo "`date +%T` Online Nandroid Backup Completed in $elapsed seconds!"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment