Skip to content
This repository was archived by the owner on Jan 5, 2022. It is now read-only.

Commit ec02556

Browse files
committed
Feature improvements
- creating target directories if they don't exist - better formatting of created script files - automatically making generated script files executable by owner - adding usage hints (comments) to generated script files - generating restore scripts as well - xml2 (to generate simple list of disabled receivers) only called when available
1 parent 05c4bcc commit ec02556

File tree

2 files changed

+63
-13
lines changed

2 files changed

+63
-13
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
## What makes *Adebar* specific?
66
There are plenty of backup solutions available for Android, including such intended as front-end for ADB. So what is specific for *Adebar* that I wrote it, knowing of those other solutions?
77

8-
The task I wrote *Adebar* for is to be able to quickly backup a device, and restore the backup again – e.g. when I need to factory-reset a device. That includes the case where I have to send a device to be serviced, and need to use a different device meanwhile: that would rule out a "complete restore" due to the side-effects system-apps might cause, especially when the second device is from a completely different manufacturer, and/or runs a different version of Android or even a completely different ROM.
8+
The task I wrote *Adebar* for is to be able to quickly backup a device, and restore the backup again – e.g. when I need to factory-reset a device. That includes the case where I have to send a device to be serviced, and need to use a different device meanwhile: that would rule out a "complete restore" due to the side-effects system-apps might cause, especially when the second device is from a completely different manufacturer, and/or runs a different version of Android or even a completely different ROM. That's one of the reasons why *Adebar* creates one backup file per app (instead of one huge `backup.ab` holding them all) – while the other is to be able to select what to restore in general.
99

1010

1111
## What kind of backup does *Adebar* create?
@@ -14,7 +14,7 @@ The task I wrote *Adebar* for is to be able to quickly backup a device, and rest
1414
* a [shell script](http://en.wikipedia.org/wiki/Shell_script "Wikipedia: Shell script") to create separate ADB backups for the apps you've installed yourself ("user-apps"), including their `.apk` files and their data
1515
* a shell script to create ADB backups of system apps, only containing their data
1616
* a shell script to disable (freeze) all apps you had disabled/frozen on your device
17-
* it pulls the `wpa_supplicant.conf` from your device, which holds information on all WiFi APs you've configured
17+
* it pulls the `wpa_supplicant.conf` from your device, which holds information on all WiFi APs you've configured (requires the ADB daemon to run in root mode)
1818
* it pulls the `packages.xml` from your device, which holds all information about apps installed on your device
1919

2020
Optionally, if you have the PHP [CLI](http://en.wikipedia.org/wiki/Command-line_interface "Wikipedia: Command-line interface") available on your computer, it parses the `packages.xml` and creates additional files:

adebar-cli

+61-11
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,97 @@ else
99
OUTDIR="$1"
1010
fi
1111

12+
if [ ! -d "$OUTDIR" ]; then
13+
mkdir -p "$OUTDIR" || {
14+
echo "Output directory does not exist, and I cannot create it. Sorry."
15+
echo
16+
exit
17+
}
18+
fi
19+
1220
# Configuration
1321
#OUTDIR='.'
22+
USERDIR="userApps"
23+
SYSDIR="sysApps"
1424

1525
#########################################[ Helpers ]###
1626

1727
# Create script for disabled apps
1828
getDisabled() {
19-
echo "#!/bin/bash" > $OUTDIR/disable
20-
echo "# Disabled apps as of $(date '+%Y-%m-%d %H:%M')" >> $OUTDIR/disable
29+
local scriptname="$OUTDIR/disable"
30+
echo "#!/bin/bash" > "${scriptname}"
31+
echo "# Disabled apps as of $(date '+%Y-%m-%d %H:%M')" >> "${scriptname}"
32+
echo >> "${scriptname}"
33+
2134
for app in $(adb shell "pm list packages -d"); do
2235
app=$(echo $app | tr -d '\r' | awk -F : '{print $2}')
23-
echo "adb shell \"pm disable $app\"" >> $OUTDIR/disable
36+
echo "adb shell \"pm disable $app\"" >> "${scriptname}"
2437
done
38+
39+
chmod u+x "${scriptname}"
2540
}
2641

42+
2743
# Create script to backup all user-apps
2844
getUserAppBackup() {
29-
echo "#!/bin/bash" > $OUTDIR/userbackup
30-
echo "# Backup script as of $(date '+%Y-%m-%d %H:%M')" >> $OUTDIR/userbackup
31-
echo "# Backs up all user apps including their .apk files and data" >> $OUTDIR/userbackup
45+
local backupscript="$OUTDIR/userbackup"
46+
local restorescript="$OUTDIR/userrestore"
47+
echo "#!/bin/bash" > "$backupscript"
48+
echo "# Backup script as of $(date '+%Y-%m-%d %H:%M')" >> "$backupscript"
49+
echo "# Backs up all user apps including their .apk files and data" >> "$backupscript"
50+
echo "# Feel free to comment out/remove apps you don't want/need to be backed up." >> "$backupscript"
51+
echo >> "$backupscript"
52+
echo "[ ! -d \"${USERDIR}\" ] && mkdir \"${USERDIR}\"" >> "$backupscript"
53+
echo >> "$backupscript"
54+
55+
echo "#!/bin/bash" > "$restorescript"
56+
echo "# Restore script as of $(date '+%Y-%m-%d %H:%M')" >> "$restorescript"
57+
echo "# Restores all app backups. Comment out (or delete) those you do not wish to restore." >> "$restorescript"
58+
echo >> "$restorescript"
59+
3260
for app in $(adb shell "pm list packages -3"); do
3361
app=$(echo $app | tr -d '\r' | awk -F : '{print $2}')
34-
echo -e "adb backup -f ${app}.ab -apk $app" >> $OUTDIR/userbackup
62+
echo -e "adb backup -f \"${USERDIR}/${app}.ab\" -apk $app" >> "$backupscript"
63+
echo "sleep 1" >> "$backupscript" # prevent ADB daemon from being "blocked" (e.g. on LG P880)
64+
echo -e "adb restore \"${USERDIR}/${app}.ab\"" >> "$restorescript"
3565
done
66+
67+
chmod u+x "$backupscript" "$restorescript"
3668
}
3769

70+
3871
# Create script to backup all system-app data
3972
getSystemAppBackup() {
40-
echo "#!/bin/bash" > $OUTDIR/sysbackup
41-
echo "# Backup script as of $(date '+%Y-%m-%d %H:%M')" >> $OUTDIR/sysbackup
73+
local backupscript="$OUTDIR/sysbackup"
74+
local restorescript="$OUTDIR/sysrestore"
75+
echo "#!/bin/bash" > "$backupscript"
76+
echo "# Backup script as of $(date '+%Y-%m-%d %H:%M')" >> "$backupscript"
77+
echo "# Backs up the data (not the .apk files) of all your system apps" >> "$backupscript"
78+
echo "# Feel free to comment out/remove apps you don't want/need to be backed up." >> "$backupscript"
79+
echo >> "$backupscript"
80+
echo "[ ! -d \"${SYSDIR}\" ] && mkdir \"${SYSDIR}\"" >> "$backupscript"
81+
echo >> "$backupscript"
82+
83+
echo "#!/bin/bash" > "$restorescript"
84+
echo "# Restore script as of $(date '+%Y-%m-%d %H:%M')" >> "$restorescript"
85+
echo -e "# Restores all system app data backups.\n# DRAGONS HERE: this might fail if you restore to a different\n# device/Android version/ROM, so be careful!\n# Comment out/delete what you do not wish to restore." >> "$restorescript"
86+
echo >> "$restorescript"
87+
4288
for app in $(adb shell "pm list packages -s"); do
4389
app=$(echo $app | tr -d '\r' | awk -F : '{print $2}')
44-
echo -e "adb backup -f ${app}.ab -noapk $app" >> $OUTDIR/sysbackup
90+
echo -e "adb backup -f \"${SYSDIR}/${app}.ab\" -noapk $app" >> "$backupscript"
91+
echo "sleep 1" >> "$backupscript" # prevent ADB daemon from being "blocked" (e.g. on LG P880)
92+
echo -e "adb restore \"${SYSDIR}/${app}.ab\"" >> "$restorescript"
4593
done
94+
95+
chmod u+x "$backupscript" "$restorescript"
4696
}
4797

4898
# Get disabled broadcast receivers
4999
# Requires xml2 package (apt-get install xml2)
50100
getFrozenComponents() {
51101
adb pull /data/system/packages.xml $OUTDIR/packages.xml
52-
xml2 < $OUTDIR/packages.xml |grep "disabled-components/item/@name" > $OUTDIR/deadreceivers
102+
[ -n "$(which xml2)" ] && xml2 < $OUTDIR/packages.xml |grep "disabled-components/item/@name" > $OUTDIR/deadreceivers
53103
}
54104

55105
# Get settings

0 commit comments

Comments
 (0)