Merge pull request #7598 from termux/termux-tools

termux-tools: add rudimentary backup/restore tools
This commit is contained in:
Leonid Pliushch 2021-09-25 14:33:21 +03:00 committed by GitHub
commit 6e3e92d625
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 130 additions and 4 deletions

View File

@ -2,7 +2,7 @@ TERMUX_PKG_HOMEPAGE=https://termux.com/
TERMUX_PKG_DESCRIPTION="Basic system tools for Termux"
TERMUX_PKG_LICENSE="GPL-3.0"
TERMUX_PKG_MAINTAINER="@termux"
TERMUX_PKG_VERSION=0.138
TERMUX_PKG_VERSION=0.139
TERMUX_PKG_SKIP_SRC_EXTRACT=true
TERMUX_PKG_PLATFORM_INDEPENDENT=true
TERMUX_PKG_ESSENTIAL=true
@ -34,9 +34,10 @@ termux_step_make_install() {
chmod +x $WRAPPER_FILE
done
for script in chsh dalvikvm login pkg su termux-fix-shebang termux-info \
termux-open termux-open-url termux-reload-settings termux-reset \
termux-setup-storage termux-wake-lock termux-wake-unlock termux-change-repo; do
for script in chsh dalvikvm login pkg su termux-fix-shebang termux-backup \
termux-info termux-open termux-open-url termux-reload-settings \
termux-reset termux-restore termux-setup-storage termux-wake-lock \
termux-wake-unlock termux-change-repo; do
install -Dm700 $TERMUX_PKG_BUILDER_DIR/$script $TERMUX_PREFIX/bin/$script
sed -i -e "s%\@TERMUX_APP_PACKAGE\@%${TERMUX_APP_PACKAGE}%g" \
-e "s%\@TERMUX_BASE_DIR\@%${TERMUX_BASE_DIR}%g" \

View File

@ -0,0 +1,62 @@
#!@TERMUX_PREFIX@/bin/bash
set -e -u
export PREFIX=@TERMUX_PREFIX@
msg() {
echo "$@" >&2
}
show_usage() {
msg
msg "Usage: termux-backup [output file]"
msg
msg "Script for backing up Termux installation directory, \$PREFIX."
msg "It WILL NOT backup your home directory."
msg
msg "Backup is performed as TAR archive. Compression is determined"
msg "by output file extension. If file name is '-', then tarball is"
msg "written to stdout and is uncompressed."
msg
}
if [ $# -lt 1 ]; then
msg
msg "[!] Output file path is not specified."
show_usage
exit 1
fi
if [ $# -gt 1 ]; then
shift 1
msg
msg "[!] Got extra arguments: $@"
show_usage
exit 1
fi
if [ ! -d "$PREFIX" ]; then
msg "[!] $PREFIX: directory does not exist."
exit 1
fi
case "$1" in
-?|-h|--help|--usage) show_usage; exit 0;;
*) BACKUP_FILE_PATH=$1;;
esac
if [ "$BACKUP_FILE_PATH" != "-" ]; then
CAN_AUTOCOMPRESS=yes
if [ -e "$BACKUP_FILE_PATH" ]; then
msg
msg "[!] Refusing to overwrite already existing file '$BACKUP_FILE_PATH'."
msg
exit 1
fi
else
CAN_AUTOCOMPRESS=
fi
tar --warning=no-file-ignored -f "$BACKUP_FILE_PATH" \
-c ${CAN_AUTOCOMPRESS+--auto-compress} \
-C "@TERMUX_BASE_DIR@" ./usr

View File

@ -0,0 +1,63 @@
#!@TERMUX_PREFIX@/bin/bash
set -e -u
export PREFIX=@TERMUX_PREFIX@
msg() {
echo "$@" >&2
}
show_usage() {
msg
msg "Usage: termux-restore [input file]"
msg
msg "Script for restoring Termux installation directory (\$PREFIX)"
msg "from the given TAR archive."
msg
msg "It is expected that backup file was made by 'termux-backup'."
msg "Restoring procedure will erase all files in \$PREFIX directory"
msg "that are not present in the given backup file. Be careful."
msg
msg "Backup contents may be supplied via stdin by specifying input"
msg "file as '-'. Note that piped TAR archive must be uncompressed."
msg
}
if [ $# -lt 1 ]; then
msg
msg "[!] Input file path is not specified."
show_usage
exit 1
fi
if [ $# -gt 1 ]; then
shift 1
msg
msg "[!] Got extra arguments: $@"
show_usage
exit 1
fi
case "$1" in
-?|-h|--help|--usage) show_usage; exit 0;;
*) BACKUP_FILE_PATH=$1;;
esac
if [ "$BACKUP_FILE_PATH" != "-" ] && [ ! -e "$BACKUP_FILE_PATH" ]; then
msg
msg "[!] File '$BACKUP_FILE_PATH' does not exist."
msg
exit 1
else
if [ "$BACKUP_FILE_PATH" != "-" ] && [ ! -f "$BACKUP_FILE_PATH" ]; then
msg
msg "[!] Path '$BACKUP_FILE_PATH' is not a regular file."
msg
exit 1
fi
fi
# --recursive-unlink is added intentionally to delete all orphan/extra files
# in $PREFIX. It must be restored to a clean state as in backup tarball.
tar -x -C "@TERMUX_BASE_DIR@" -f "$BACKUP_FILE_PATH" \
--recursive-unlink --preserve-permissions ./usr