forked from AndDiSa/android_backup_project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup-partitions.sh
executable file
·102 lines (83 loc) · 2.23 KB
/
backup-partitions.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
# License; Apache-2
# [email protected] 2019/12
curr_dir="$(dirname "$0")"
. "$curr_dir/functions.sh"
set -e # fail early
use_adb_root=false
data_backup=true
media_backup=false
image_backup=false
extra_backup=false
if [[ $# -gt 0 ]]; then
for param in $@; do
case "$param" in
help|-h|--help)
echo "Makes a full backup over ADB"
echo "tar /data, binary img /data block"
exit 0
;;
--data-backup)
data_backup=true
;;
--no-data-backup)
data_backup=false
;;
--media-backup)
media_backup=true
;;
--no-media-backup)
media_backup=false
;;
--image-backup)
image_backup=true
;;
--no-image-backup)
image_backup=false
;;
--extra-backup)
extra_backup=true
;;
--no-extra-backup)
extra_backup=false
;;
*)
echo "Unknown argument $1"
exit 1
;;
esac
done
fi
checkPrerequisites
updateBusybox
lookForAdbDevice
checkRootType
pushBusybox
mkBackupDir
pushd "$DIR"
PARTITIONS=$($A shell "ls /dev/block/by-name/")
echo $PARTITIONS
stopRuntime
if $image_backup; then
echo "Creating partition image backups ..."
for i in $PARTITIONS; do
PARTITION="/dev/block/by-name/$i"
echo "getting $PARTITION ..."
$AS "/dev/busybox dd if=$PARTITION bs=4096 2>/dev/null" > $i.img
echo "Verifying image backup..."
echo -n " Calculate checksum on device: "
device_checksum="$($AS /dev/busybox sha256sum $PARTITION | cut -d ' ' -f1)"
echo "$device_checksum"
echo -n " Calculate checksum locally: "
local_checksum="$(sha256sum $i.img | cut -d ' ' -f1)"
echo "$local_checksum"
if [ "$local_checksum" == "$device_checksum" ]; then
echo "Checksums match."
else
echo -e "\033[1mChecksums don't match! $local_checksum != $device_checksum\033[0m"
fi
done
fi
cleanup
startRuntime
popd # $DIR