forked from mad-ady/OdroidC1-tripleboot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup_from_sdcard
executable file
·187 lines (154 loc) · 4.56 KB
/
backup_from_sdcard
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/bash
if [ "$(id -u)" != "0" ]; then
echo "Script must be run as root !"
exit 0
fi
. params.sh
. func.sh
echo ""
date
echo "**************************"
echo "Backup triple boot sd card"
echo "**************************"
echo ""
umount ${sdcard}* > /dev/null 2>&1
sleep 2
mkdir $bkpdir > /dev/null 2>&1
#--- CHECK --------------------------------------------------------------------------
check_sdcard "nocreate"
if [ $? -ne 0 ]; then
exit $?
fi
get_partstruct
if [ "${system_start}" = "" ] || [ "${userdata_start}" = "" ] || [ "${cache_start}" = "" ] || [ "${storage_start}" = "" ]; then
echo "Bad SDCard partition structure !"
exit 1
fi
if [ "${dualb}" = "" ]; then
echo "Bad SDCard partition structure 2!"
else
if [ ! "${storage_start}" = "${storage_offset}" ]; then
echo "Bad SDCard partition structure 3!"
exit 1
fi
fi
#------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------
echo -n "WARNING: Data in $bkpdir WILL BE UPDATED !, Continue (y/N)? "
read -n 1 ANSWER
if [ ! "${ANSWER}" = "y" ] ; then
echo "."
echo "Canceled.."
exit 0
fi
echo "."
#------------------------------------------------------------------------------------
mkdir _mnt > /dev/null 2>&1
if [ "${_isimage}" = "yes" ] ; then
map_image
if [ $? -ne 0 ]; then
exit 1
fi
partmap=$loop_mapp
else
partmap=$sdcard
fi
echo ""
echo "Extracting android sections, $storage_start, $(expr $storage_start / 2048 )M ..."
read_uboot_section
echo "OK."
mkdir _mnt > /dev/null 2>&1
umount _mnt > /dev/null 2>&1
mkdir ${bkpdir}/system > /dev/null 2>&1
mount ${partmap}2 _mnt > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR mounting ${partmap}2"
exit 1
fi
echo "Copying system partition ..."
rsync -r -t -p -o -g -x --delete -l -H -D --numeric-ids -s --stats _mnt/ ${bkpdir}/system/ > /dev/null 2>&1
sync
fs_size=`du -s -h ${bkpdir}/system | awk '{print $1}'`
echo "File system size: $fs_size"
umount _mnt
mkdir ${bkpdir}/userdata > /dev/null 2>&1
mount ${partmap}3 _mnt > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR mounting ${partmap}3"
exit 1
fi
echo ""
echo "Copying userdata partition ..."
rsync -r -t -p -o -g -x --delete -l -H -D --numeric-ids -s --stats _mnt/ ${bkpdir}/userdata/ > /dev/null 2>&1
sync
fs_size=`du -s -h ${bkpdir}/userdata | awk '{print $1}'`
echo "File system size: $fs_size"
umount _mnt
mkdir ${bkpdir}/cache > /dev/null 2>&1
mount ${partmap}${ncache} _mnt > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR mounting ${partmap}${ncache}"
exit 1
fi
echo ""
echo "Copying cache partition ..."
rsync -r -t -p -o -g -x --delete -l -H -D --numeric-ids -s --stats _mnt/ ${bkpdir}/cache/ > /dev/null 2>&1
sync
fs_size=`du -s -h ${bkpdir}/cache | awk '{print $1}'`
echo "File system size: $fs_size"
umount _mnt
mkdir ${bkpdir}/storage > /dev/null 2>&1
mount ${partmap}1 _mnt > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR mounting ${partmap}1"
exit 1
fi
echo ""
echo "Copying storage partition ..."
rsync -r -t -p -o -g -x --delete -l -H -D --numeric-ids -s --stats _mnt/ ${bkpdir}/storage/ > /dev/null 2>&1
sync
fs_size=`du -s -h ${bkpdir}/storage | awk '{print $1}'`
echo "File system size: $fs_size"
umount _mnt
if [ ! "${skip_OpenELEC}" = "yes" ]; then
mkdir ${bkpdir}/openElec > /dev/null 2>&1
mount ${partmap}6 _mnt > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR mounting ${partmap}6"
exit 1
fi
echo ""
echo "Copying openElec partition ..."
rsync -r -t -p -o -g -x --delete -l -H -D --numeric-ids -s --stats _mnt/ ${bkpdir}/openElec/ > /dev/null 2>&1
sync
fs_size=`du -s -h ${bkpdir}/openElec | awk '{print $1}'`
echo "File system size: $fs_size"
umount _mnt
fi
if [ ! "${skip_linux}" = "yes" ]; then
mkdir ${bkpdir}/linux > /dev/null 2>&1
mount ${partmap}7 _mnt > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR mounting ${partmap}7"
exit 1
fi
echo ""
echo "Copying Linux partition ..."
rsync -r -t -p -o -g -x --delete -l -H -D --numeric-ids -s --stats _mnt/ ${bkpdir}/linux/ > /dev/null 2>&1
sync
fs_size=`du -s -h ${bkpdir}/linux | awk '{print $1}'`
echo "File system size: $fs_size"
umount _mnt
fi
echo ""
echo "=================================================================="
echo "Triple sd card $sdcard saved to $bkpdir."
echo "=================================================================="
echo ""
#==================================
if [ "${_isimage}" = "yes" ] ; then
unmap_image
fi
#==================================
exit 0
# -------------------------------------------------------------------