Skip to content

Commit

Permalink
Add an option to disable 7zip archiving
Browse files Browse the repository at this point in the history
  • Loading branch information
mrrfv committed Dec 1, 2023
1 parent 12de42a commit d386a22
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
10 changes: 10 additions & 0 deletions .github/test-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,13 @@ export export_method="tar"
cp .github/test-hook.sh ./hooks.sh
create_dummy_files
./backup.sh

# discouraged_disable_archive enabled, ADB exporting method
export discouraged_disable_archive="yes"
export use_hooks="no"
export export_method="adb"
create_dummy_files
./backup.sh

# Show the contents of the backup location
ls -la $archive_path
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ You need 3 functions in your hook for it to be properly initialized by the scrip

Please keep in mind that this project has minimal support for automation and very little support will be provided. In order to export contacts, you still need to have physical access to the device you're backing up as an "unattended mode" for the companion app hasn't been implemented yet.

There are 8 environment variables that control what the script does without user input:
There are 9 environment variables that control what the script does without user input:

1. `unattended_mode` - Instead of waiting for a key press, sleeps for 5 seconds. Can be any value.
2. `selected_action` - What the script should do when run. Possible values are `Backup` and `Restore` (case sensitive).
Expand All @@ -127,6 +127,7 @@ There are 8 environment variables that control what the script does without user
6. `export_method` - The method Open Android Backup should use to export data from the device. Possible values are `tar` and `adb` (case sensitive) - the former is fast & very stable but might not work on all devices, and the latter is widely compatible but has stability issues.
7. `use_hooks` - Whether to use hooks or not. Possible values are `yes` or `no` (case sensitive).
8. `data_erase_choice` - Whether to securely erase temporary files or not. Possible values are `Fast`, `Slow` and `Extra Slow` (case sensitive). The value of this variable is ignored if the command `srm` isn't present on your computer.
9. `discouraged_disable_archive` - Disables the creation of a backup archive, only creates a backup *directory* with no compression, encryption or other features. This is not recommended, although some may find it useful to deduplicate backups and save space. Restoring backups created with this option enabled is not supported by default; you must manually create an archive from the backup directory and then restore it. Possible values are `yes` or `no` (case sensitive).

Examples:

Expand Down
30 changes: 20 additions & 10 deletions functions/backup_func.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,26 @@ function backup_func() {
cp "$DIR/extras/backup_archive_info.txt" ./backup-tmp/PLEASE_READ.txt
echo "$APP_VERSION" > ./backup-tmp/version.txt

# Compress
cecho "Compressing & encrypting data - this will take a while."
# 7-Zip options:
# -p: encrypt backup
# -mhe=on: encrypt headers (metadata)
# -mx=9: ultra compression
# -bb3: verbose logging
# The undefined variable (archive_password) is set by the user if they're using unattended mode
declare backup_archive="$archive_path/open-android-backup-$(date +%m-%d-%Y-%H-%M-%S).7z"
retry 5 7z a -p"$archive_password" -mhe=on -mx=7 -bb3 "$backup_archive" backup-tmp/*
# If the "discouraged_disable_archive" is set to "yes", then we'll only create a directory with the backup files.
if [ "$discouraged_disable_archive" = "yes" ]; then
cecho "Skipping compression & encryption due to the 'discouraged_disable_archive' option being set to 'yes'."
cecho "The backup data will be stored in a directory instead."
# TODO: clean up the code, i.e. remove the repetition
declare backup_archive="$archive_path/open-android-backup-$(date +%m-%d-%Y-%H-%M-%S)"
mkdir -p "$archive_path/open-android-backup-$(date +%m-%d-%Y-%H-%M-%S)"
mv ./backup-tmp "$archive_path/open-android-backup-$(date +%m-%d-%Y-%H-%M-%S)"
else
# Compress
cecho "Compressing & encrypting data - this will take a while."
# 7-Zip options:
# -p: encrypt backup
# -mhe=on: encrypt headers (metadata)
# -mx=9: ultra compression
# -bb3: verbose logging
# The undefined variable (archive_password) is set by the user if they're using unattended mode
declare backup_archive="$archive_path/open-android-backup-$(date +%m-%d-%Y-%H-%M-%S).7z"
retry 5 7z a -p"$archive_password" -mhe=on -mx=7 -bb3 "$backup_archive" backup-tmp/*
fi

# We're not using 7-Zip's -sdel option (delete files after compression) to honor the user's choice to securely delete temporary files after a backup
remove_backup_tmp
Expand Down

0 comments on commit d386a22

Please sign in to comment.