various
parent
dd67c165a4
commit
9a199bb515
|
@ -6,6 +6,7 @@ else
|
|||
. "$(dirname "$(realpath -s "$0")")/../libexec/zio/helpers/bash.sh"
|
||||
fi
|
||||
|
||||
me_filename="$(basename "$(realpath -s "$0")")"
|
||||
backup_scripts_dir="$(get_config_dir "sh.zio.backup")/scripts"
|
||||
cache_dir="/var/cache/sh.zio.backup/restic"
|
||||
secrets_dir="$(get_config_dir "sh.zio.backup")/secrets"
|
||||
|
@ -71,6 +72,39 @@ function invoke_restic() {
|
|||
fi
|
||||
}
|
||||
|
||||
function invoke_script() {
|
||||
backup_script="$1"
|
||||
|
||||
backup_script_filename="$(basename "$backup_script")"
|
||||
backup_script_name="${backup_script_filename%.*}"
|
||||
backup_script_name_length="${#backup_script_name}"
|
||||
|
||||
say primary "-[$backup_script_name]$(repeat "-" $((80-3-$backup_script_name_length)))"
|
||||
chmod +x "$backup_script"
|
||||
|
||||
export -f backup_dir
|
||||
export -f die
|
||||
export -f forget_backup
|
||||
export -f get_config_dir
|
||||
export -f get_real_path
|
||||
export -f invoke_restic
|
||||
export -f prune_backup
|
||||
export -f say
|
||||
export -f start_service
|
||||
export -f stop_service
|
||||
export -f test_file
|
||||
export backup_scripts_dir
|
||||
export cache_dir
|
||||
export host
|
||||
export me_filename
|
||||
export restic_repo_file
|
||||
export restic_repo_passwd_file
|
||||
export restic_path
|
||||
export secrets_dir
|
||||
|
||||
"$backup_scripts_dir/$backup_script_filename"
|
||||
}
|
||||
|
||||
function backup_dir() {
|
||||
path="$1"
|
||||
args="${@:2}"
|
||||
|
@ -101,6 +135,8 @@ function backup_dir() {
|
|||
--exclude "containers/storage/overlay-layers" \
|
||||
--exclude-if-present ".nobackup" \
|
||||
--host "$host" \
|
||||
--tag "$me_filename" \
|
||||
--tag "$(basename "$0")" \
|
||||
$args "$path"
|
||||
fi
|
||||
}
|
||||
|
@ -142,6 +178,32 @@ function stop_service() {
|
|||
systemctl stop $service
|
||||
}
|
||||
|
||||
if [[ "$@" == "help" ]]; then
|
||||
echo "$me_filename
|
||||
|
||||
Usage:
|
||||
$me_filename
|
||||
Run all backup scripts available in $backup_scripts_dir
|
||||
|
||||
$me_filename <script>
|
||||
Run a specific script from a given path
|
||||
|
||||
$me_filename <command> [arguments]
|
||||
Execute 'restic' with arbitrary commands and optional arguments.
|
||||
|
||||
This command is bootstrapped with some arguments — which are not
|
||||
overridable — as follows:
|
||||
* --cache-dir
|
||||
* --password-file
|
||||
* --repo
|
||||
|
||||
$me_filename help
|
||||
Output this usage text. Use '--help' or 'help <command>' to output
|
||||
restic's help text.
|
||||
"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
test_root
|
||||
test_prog "bzip2"
|
||||
test_prog "curl"
|
||||
|
@ -167,36 +229,12 @@ if [[ -z "$1" ]]; then
|
|||
fi
|
||||
|
||||
for backup_script in $backup_scripts_dir/*; do
|
||||
backup_script_filename="$(basename "$backup_script")"
|
||||
backup_script_name="${backup_script_filename%.*}"
|
||||
backup_script_name_length="${#backup_script_name}"
|
||||
|
||||
say primary "-[$backup_script_name]$(repeat "-" $((80-3-$backup_script_name_length)))"
|
||||
chmod +x "$backup_script"
|
||||
|
||||
export -f backup_dir
|
||||
export -f die
|
||||
export -f forget_backup
|
||||
export -f get_config_dir
|
||||
export -f get_real_path
|
||||
export -f invoke_restic
|
||||
export -f prune_backup
|
||||
export -f say
|
||||
export -f start_service
|
||||
export -f stop_service
|
||||
export -f test_file
|
||||
export backup_scripts_dir
|
||||
export cache_dir
|
||||
export host
|
||||
export restic_repo_file
|
||||
export restic_repo_passwd_file
|
||||
export restic_path
|
||||
export secrets_dir
|
||||
|
||||
"$backup_scripts_dir/$backup_script_filename"
|
||||
invoke_script $backup_script
|
||||
done
|
||||
|
||||
say primary "$(repeat "-" 80)"
|
||||
elif [[ -f "$1" ]]; then
|
||||
invoke_script "$1"
|
||||
else
|
||||
command="$1"
|
||||
arguments="${@:2}"
|
||||
|
|
Loading…
Reference in New Issue