forked from PhilZ-cwm6/philz_touch_cwm6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
raw-backup.sh
56 lines (47 loc) · 1.31 KB
/
raw-backup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/sbin/sh
#######################################
# Do not remove this credits header #
# Raw backup support through shell #
# First Release: PhilZ-cwm6 #
#######################################
#usage: raw-backup.sh [-br] [path] [volume] [mount point]
# -b backup
# -r restore
#exp: raw-backup.sh -b /sdcard/clockworkmod/.efsbackup/raw /dev/block/mmcblk0p1 /efs
# raw-backup.sh -r /sdcard/clockworkmod/.efsbackup/raw/efs.img /dev/block/mmcblk0p1 /efs
if [ "$1" = "-b" ]
then
# start backup
mkdir -p "$2";
DATE=$(date +%Y%m%d_%H%M%S);
echo "">>"$2"/log.txt;
echo "Backup "$4" ("$3") to "$2""$4"_$DATE.img">>"$2"/log.txt;
(cat "$3" > "$2""$4"_"$DATE".img) 2>> "$2"/log.txt;
if [ $? = 0 ];
then
echo "Success!">>"$2"/log.txt;
exit 0;
else
echo "Error!">>"$2"/log.txt;
exit 1;
fi;
# end backup
# start restore
elif [ "$1" = "-r" ]
then
BACKUP_FOLDER=$(dirname "$2")
echo "">>"$BACKUP_FOLDER"/log.txt;
echo "Restore "$2" to "$3" ("$4")">>"$BACKUP_FOLDER"/log.txt;
(cat "$2" > "$3") 2>> "$BACKUP_FOLDER"/log.txt;
if [ $? = 0 ];
then
echo "Success!">>"$BACKUP_FOLDER"/log.txt;
exit 0;
else
echo "Error!">>"$BACKUP_FOLDER"/log.txt;
exit 1;
fi;
# end restore
#bad call option
else exit 2;
fi;