Skip to content

Commit 8981f8d

Browse files
committed
Restore backup using tar
1 parent 721ff88 commit 8981f8d

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

backup.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ fi
8383
clear
8484

8585
if [ ! -v export_method ]; then
86-
cecho "Choose the exporting method."
86+
cecho "Choose the exporting/importing method."
8787
cecho "- Pick 'tar' first, as it is fast and most reliable, but might not work on all devices."
8888
cecho "- If the script crashes, pick 'adb' instead, which works on all devices."
8989
cecho "Press Enter to pick your preferred method."
9090
wait_for_enter
9191

9292
export_methods=( 'tar' 'adb' )
93-
select_option_from_list "Choose the exporting method." export_methods[@] export_method
93+
select_option_from_list "Choose the exporting/importing method." export_methods[@] export_method
9494
fi
9595

9696
clear

functions/helper.sh

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

211+
# Usage: send_file <directory> <file> <destination>
212+
function send_file() {
213+
if [ "$export_method" = 'tar' ]; then
214+
(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
215+
else # we're falling back to adb push if the variable is empty/unset
216+
adb push "$1"/"$2" "$3" || cecho "Errors occurred while restoring $2 - this file (or multiple files) might've been ignored." 1>&2
217+
fi
218+
}
219+
211220
# Usage: directory_ok <directory>
212221
# Returns 0 (true) or 1 (false)
213222
function directory_ok() {

functions/restore_func.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,9 @@ function restore_func() {
9090
fi
9191
set -e
9292

93-
# TODO: use tar to restore data to internal storage instead of adb push
94-
9593
# Restore internal storage
9694
cecho "Restoring internal storage."
97-
adb push ./backup-tmp/Storage/* /storage/emulated/0
95+
send_file ./backup-tmp/Storage . /storage/emulated/0
9896

9997
# Restore contacts
10098
cecho "Pushing backed up contacts to device."

0 commit comments

Comments
 (0)