[Epic 4G Android Development] SenseiSimple:
UNIFIED BACKUP SCRIPT - INSTRUCTIONS/DIFFERENCES

SUMMARY The motivation is threefold, as Toadlife initiated with the purpose of modernizing the backup scripts to better protect the data file attributes in backup by using Tar rather than streaming to Cpio, it's possible with adding this improvement to add new functionality and prevent cluttering up users' sdcards with various ROM folders/editions. They will now all be located by ROM name (i.e. SleeperROM, CleanGB, StarskyROM, RandomROM, LegendaryROM *.tgz) in the /sdcard/ROMBackup-EI22/*.tgz directory.

In your ROM package

1. REPLACE /tools/data-backup and /tools/data-restore

2. WITH /tools/tar-backup (script below)

3. UPDATE ROMName=CleanGB with your rom name

in your updater-script, replace

package_extract_file("tools/data-backup", "/tmp/data-backup");
package_extract_file("tools/data-restore", "/tmp/data-restore");

set_perm(0, 0, 0755, "/tmp/data-backup");
set_perm(0, 0, 0755, "/tmp/data-restore");

with

package_extract_file("tools/tar-backup", "/tmp/tar-backup");
set_perm(0, 0, 0755, "/tmp/tar-backup");

updater-script USAGE:

1. REPLACE: run_program("/tmp/data-backup");

2. WITH run_program("/tmp/tar-backup", "backup");

3. REPLACE: run_program("/tmp/data-restore");

4a. WITH run_program("/tmp/tar-backup", "recover"); - Leave the backup in place, will be overwritten in the future

4b. OR run_program("/tmp/tar-backup", "recover","delete"); To delete the backup file when complete

4c. OR run_program("/tmp/tar-backup", "recover","archive"); To archive (with date) the backup file when complete

MINIMAL updater-script BACKUP EXAMPLE

ui_print("************************************************");
ui_print(" TAR BACK UP / RESTORE EXAMPLE");
ui_print("************************************************");
show_progress(1.000, 0);
set_progress (0.100);

#EXTRACT BACKUP SCRIPT
ui_print("Preparing tools...");
package_extract_file("tools/busybox", "/tmp/busybox");
[B]package_extract_file("tools/tar-backup", "/tmp/tar-backup");[/B]

[B]set_perm(0, 0, 0755, "/tmp/tar-backup");[/B]
set_perm(0, 0, 0755, "/tmp/busybox");

#CREATE BACKUP
set_progress (0.350);
ui_print("Backing up - this may take a while...");
run_program("/sbin/mount","/sdcard");
run_program("/sbin/mount","/data");
[B]run_program("/tmp/tar-backup","backup");[/B]
unmount("/data");

#RECOVER BACKUP
set_progress (0.600);
ui_print("Recovering backed up data...");
run_program("/sbin/mount","/data");
[B]run_program("/tmp/tar-backup","recover");
# run_program("/tmp/tar-backup","recover","delete");
# run_program("/tmp/tar-backup","recover","archive");[/B]
unmount("/data");

set_progress(1.000);
show_progress(1.000, 0);

FILE: /tools/tar-backup

edit the value of ROMName=YOURROMNAME (you should only have to edit this file once for all your ROM versions, it's not version-dependent), that's it.

#!/tmp/busybox sh
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU Library General Public License as published
# by the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# License GPLv2+: GNU GPL version 2 <http://gnu.org/licenses/gpl.html>
#

# toadlife, SenseiSimple, XDA Community, Bonsai
# invoke with
# run_program("/tmp/tar-backup","backup");
# run_program("/tmp/tar-backup","recover" [,"delete"|"archive"]);

# - "delete" option deletes the backup file
# - "archive" option renames the backup file for archiving (otherwise, it is left alone and replaced on next backup/flash)

[B]ROMName=CleanGB[/B]
platbuild=EI22

PATH=/tmp:/sbin:$PATH
datadir=/data
backdir=/sdcard/ROMBackup-$platbuild
backfile=$backdir/$ROMName.tgz
TEST="busybox test"; TAR="busybox tar"; MKDIR="busybox mkdir"

if [ "$1" = "backup" ]; then
rm /data/dalvik-cache/*
rm /data/lost+found/*
rm $backfile
if $TEST -d $datadir ; then
$TEST ! -d $backdir && $MKDIR $backdir
$TAR pczf $backfile $datadir
if $TEST $? -ne 0 ; then
echo "Backup failed!"; exit 1
else
echo "Backup completed"; exit 0
fi
fi
elif [ "$1" = "recover" ]; then
if $TEST -f $backfile; then
$TAR pxzf $backfile
if [ "$2" = "delete" ]; then
rm $backfile;
elif [ "$2" = "archive" ]; then
archdate=`date +%Y%m%d-%I%M`
archfile=$backdir/$ROMName-$archdate.tgz
mv $backfile $archfile
fi
echo "Restore Completed!"; exit 0
else
echo "Restore failed!"; exit 1
fi

else
echo "Backup - Invalid argument"; exit 1
fi

Example CWM package (unsigned) to augment these instructions - pay attention to your version of Busybox vs the one included.