forked from AndDiSa/android_backup_project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
full-restore.sh
executable file
·111 lines (92 loc) · 2.58 KB
/
full-restore.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
102
103
104
105
106
107
108
109
110
111
#!/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 1 ]]; 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
;;
*)
break
;;
esac
shift
done
fi
if [[ $# -gt 0 ]]; then
echo "parm: $1"
RESTOREDIR=$1
if test ! -d "$RESTOREDIR"; then
echo "$RESTOREDIR does not exist, exiting"
exit 2
fi
else
echo "Missing directory from which to restore ..."
exit 1
fi
checkPrerequisites
updateBusybox
lookForAdbDevice
checkRootType
checkForCleanData
pushBusybox
echo "restoring from $RESTOREDIR"
stopRuntime
pushd $RESTOREDIR
if $data_backup; then
echo "Restoring full tar backup of /data excluding /data/media ... "
cat data.tar.gz | pv -trab | $AS '/dev/busybox tar -xzpf - -C /data --exclude=./vendor/var/run || true'
$AS "restorecon -FRDv /data/data"
fi
if $media_backup; then
echo "Restoring full tar backup of /data/media ... "
$AS mkdir -p /data/media
cat data_media.tar.gz | pv -trab | $AS '/dev/busybox tar -xzpf - -C /data/media --exclude=./vendor/var/run || true'
echo "Restoring full tar backup of /data/mediadrm ... "
$AS mkdir -p /data/mediadrm
cat data_mediadrm.tar.gz | pv -trab | $AS '/dev/busybox tar -xzpf - -C /data/mediadrm --exclude=./vendor/var/run || true'
fi
if $image_backup; then
echo "Restoring image backup..."
#get data image location
PARTITION=$($AS mount | grep " /data " | cut -d ' ' -f1)
echo "Restoring to $PARTITION"
zcat data.img.gz 2>/dev/null | pv -trab | $AS "/dev/busybox dd of=$PARTITION 2>/dev/null || true"
fi
cleanup
startRuntime