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