Skip to content

Commit 6095300

Browse files
authored
Merge pull request #115 from nuxa17/master
Restore backup using tar
2 parents d8a428f + 3d5457f commit 6095300

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ Open Android Backup doesn't automatically load hooks, and you have to allow the
104104
- `cecho <text>` lets you have yellow terminal output.
105105
- `wait_for_enter` waits for a keypress, and is compatible with unattended mode.
106106
- `get_file <phone_directory> <phone_file> <destination>` lets you copy files off the device with the best reliability and speed, an alternative to `adb pull`. Useful for backing up data.
107+
- `send_file <directory> <file> <destination>` is used to send files to the device, utilizing either `adb` or `tar` depending on user preference.
107108
- `adb push <file> <destination>` lets you upload files to the device, useful when restoring your data.
108109

109110
*Required functions*

backup.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ fi
9191
clear
9292

9393
if [ ! -v export_method ]; then
94-
cecho "Choose the exporting method."
94+
cecho "Choose the exporting/importing method."
9595
cecho "- Pick 'tar' first, as it is fast and most reliable, but might not work on all devices."
9696
cecho "- If the script crashes, pick 'adb' instead, which works on all devices."
9797
cecho "Press Enter to pick your preferred method."
9898
wait_for_enter
9999

100100
export_methods=( 'tar' 'adb' )
101-
select_option_from_list "Choose the exporting method." export_methods[@] export_method
101+
select_option_from_list "Choose the exporting/importing method." export_methods[@] export_method
102102
fi
103103

104104
clear

functions/helper.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,15 @@ function get_file() {
207207
fi
208208
}
209209

210+
# Usage: send_file <directory> <file> <destination>
211+
function send_file() {
212+
if [ "$export_method" = 'tar' ]; then
213+
(tar -c -C "$1" "$2" 2> /dev/null | pv -p --timer --rate --bytes | adb exec-in tar -C "$3" -xf -) || cecho "Errors occurred while restoring $2 - this file (or multiple files) might've been ignored." 1>&2
214+
else # we're falling back to adb push if the variable is empty/unset
215+
adb push "$1"/"$2" "$3" || cecho "Errors occurred while restoring $2 - this file (or multiple files) might've been ignored." 1>&2
216+
fi
217+
}
218+
210219
# Usage: directory_ok <directory>
211220
# Returns 0 (true) or 1 (false)
212221
function directory_ok() {

functions/restore_func.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,14 @@ function restore_func() {
126126
set -e
127127
fi
128128

129-
# TODO: use tar to restore data to internal storage instead of adb push
130129

131130
if [ "$restore_storage" = "yes" ]; then
132131
# Restore internal storage
133132
cecho "Restoring internal storage."
134-
adb push ./backup-tmp/Storage/ /storage/emulated/0/
133+
send_file ./backup-tmp/Storage/ . /storage/emulated/0/
135134
fi
136135

136+
137137
if [ "$restore_contacts" = "yes" ]; then
138138
# Restore contacts
139139
cecho "Pushing backed up contacts to device."

0 commit comments

Comments
 (0)