various
parent
dd67c165a4
commit
9a199bb515
|
@ -6,6 +6,7 @@ else
|
||||||
. "$(dirname "$(realpath -s "$0")")/../libexec/zio/helpers/bash.sh"
|
. "$(dirname "$(realpath -s "$0")")/../libexec/zio/helpers/bash.sh"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
me_filename="$(basename "$(realpath -s "$0")")"
|
||||||
backup_scripts_dir="$(get_config_dir "sh.zio.backup")/scripts"
|
backup_scripts_dir="$(get_config_dir "sh.zio.backup")/scripts"
|
||||||
cache_dir="/var/cache/sh.zio.backup/restic"
|
cache_dir="/var/cache/sh.zio.backup/restic"
|
||||||
secrets_dir="$(get_config_dir "sh.zio.backup")/secrets"
|
secrets_dir="$(get_config_dir "sh.zio.backup")/secrets"
|
||||||
|
@ -71,6 +72,39 @@ function invoke_restic() {
|
||||||
fi
|
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() {
|
function backup_dir() {
|
||||||
path="$1"
|
path="$1"
|
||||||
args="${@:2}"
|
args="${@:2}"
|
||||||
|
@ -101,6 +135,8 @@ function backup_dir() {
|
||||||
--exclude "containers/storage/overlay-layers" \
|
--exclude "containers/storage/overlay-layers" \
|
||||||
--exclude-if-present ".nobackup" \
|
--exclude-if-present ".nobackup" \
|
||||||
--host "$host" \
|
--host "$host" \
|
||||||
|
--tag "$me_filename" \
|
||||||
|
--tag "$(basename "$0")" \
|
||||||
$args "$path"
|
$args "$path"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -142,6 +178,32 @@ function stop_service() {
|
||||||
systemctl 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_root
|
||||||
test_prog "bzip2"
|
test_prog "bzip2"
|
||||||
test_prog "curl"
|
test_prog "curl"
|
||||||
|
@ -167,36 +229,12 @@ if [[ -z "$1" ]]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for backup_script in $backup_scripts_dir/*; do
|
for backup_script in $backup_scripts_dir/*; do
|
||||||
backup_script_filename="$(basename "$backup_script")"
|
invoke_script $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"
|
|
||||||
done
|
done
|
||||||
|
|
||||||
say primary "$(repeat "-" 80)"
|
say primary "$(repeat "-" 80)"
|
||||||
|
elif [[ -f "$1" ]]; then
|
||||||
|
invoke_script "$1"
|
||||||
else
|
else
|
||||||
command="$1"
|
command="$1"
|
||||||
arguments="${@:2}"
|
arguments="${@:2}"
|
||||||
|
|
Loading…
Reference in New Issue