2
0
Fork 0
main
Ducky 2023-08-22 21:51:38 +01:00
parent 80c201e384
commit e9c55702e6
1 changed files with 24 additions and 9 deletions

View File

@ -16,9 +16,11 @@ cache_dir="$(get_config_dir "sh.zio.backup" "/var/cache")/restic"
secrets_dir="$(get_config_dir "sh.zio.backup")/secrets"
host="$(hostname -s)"
now="$(date +"%Y-%m-%d %H:%M:%S")"
restic_mount_path="/mnt/restic"
restic_path=""
restic_repo_file="$secrets_dir/restic-repo"
restic_repo_passwd_file="$secrets_dir/restic-repo-passwd"
restic_version="0.16.0"
function download_restic() {
restic_version="$1"
@ -69,11 +71,10 @@ function invoke_restic() {
;;
esac
if [[ -z $command ]]; then
say warning "No command specified. Not running"
elif [[ $command == "self-update" ]]; then
say warning "Command '$command' not supported. Not running"
elif [[ $command == "generate" || $command == "self-update" ]]; then
say warning "Unsupported command: $command"
else
"$restic_path" \
--cache-dir "$cache_dir" \
@ -230,12 +231,16 @@ Usage:
$me_filename <script>
Run a specific script from a given path
$me_filename dump <snapshot ID>
Restore <snapshot ID> to /srv/dumps/$host/restic/<snapshot ID>/
$me_filename rescue <snapshot ID>
Restore <snapshot ID> to /srv/dumps/$host/restic/<snapshot ID>/.
Use 'restore' to interact directly with restic
$me_filename toggle-mount
Mount (or unmount) restic to /mnt/restic/.
Use 'mount' to interact directly with restic
$me_filename <command> [arguments]
Execute 'restic' with arbitrary commands and optional arguments
Execute restic with arbitrary commands and optional arguments.
This command is bootstrapped with some arguments — which are not
overridable — as follows:
* --cache-dir
@ -261,7 +266,7 @@ mkdir -p "$secrets_dir"
chmod -R 711 "$secrets_dir"
download_restic 0.16.0
download_restic $restic_version
test_file "$restic_repo_file"
test_file "$restic_repo_passwd_file"
@ -290,7 +295,7 @@ if [[ -z "$1" || -f "$1" ]]; then
--host "$host" \
--tag "$(basename "$0")" \
| sed -E ":begin;$!N;s/$(basename "$0")\n\s+?//;tbegin;P;D"
elif [[ "$1" == "dump" ]]; then
elif [[ "$1" == "rescue" ]]; then
snapshot="$2"
[[ -z "$snapshot" ]] && die "No snapshot ID provided"
@ -298,6 +303,16 @@ elif [[ "$1" == "dump" ]]; then
invoke_restic restore \
--target "/srv/dumps/$host/restic/$snapshot" \
"$snapshot"
elif [[ "$1" == "toggle-mount" ]]; then
test_restic_mount="$(mountpoint "$restic_mount_path")"
if [[ $? == 0 ]]; then
umount "$restic_mount_path"
rm -rf "$restic_mount_path"
else
mkdir -fp "$restic_mount_path"
invoke_restic mount "$restic_mount_path" &>/dev/null & disown;
fi
else
command="$1"
arguments="${@:2}"