From de46d03444dcaa738c25948b4d7c6d4f0b76274f Mon Sep 17 00:00:00 2001 From: Marco Kundt Date: Sun, 4 Apr 2021 00:49:41 +0200 Subject: [PATCH] slim down --- restic/.bin/restic-backup | 62 +++++++++++++++++++ restic/.bin/restic_backup | 12 ---- restic/.bin/restic_common | 46 -------------- restic/.bin/restic_prune | 8 --- .../systemd/user/restic-backup.service | 6 +- .../.config/systemd/user/restic-backup.timer | 1 - .../.config/systemd/user/restic-prune.service | 12 ---- .../.config/systemd/user/restic-prune.timer | 10 --- 8 files changed, 64 insertions(+), 93 deletions(-) create mode 100755 restic/.bin/restic-backup delete mode 100755 restic/.bin/restic_backup delete mode 100755 restic/.bin/restic_common delete mode 100755 restic/.bin/restic_prune delete mode 100644 restic/.config/systemd/user/restic-prune.service delete mode 100644 restic/.config/systemd/user/restic-prune.timer diff --git a/restic/.bin/restic-backup b/restic/.bin/restic-backup new file mode 100755 index 0000000..e7449ee --- /dev/null +++ b/restic/.bin/restic-backup @@ -0,0 +1,62 @@ +#!/bin/bash + +read_config() { + # variables + #CACHE_DIR="$HOME/.cache/restic" + #BACKUP_PATHS="/etc /home/docker/volumes /root" + #EXCLUDES_FILE="$HOME/.config/restic/excludes" + #KEEP_HOURS=96 + #KEEP_DAYS=31 + #KEEP_WEEKS=8 + #KEEP_MONTHS=12 + #KEEP_YEARS=3 + #RESTIC_PASSWORD="PASSWORD" + #RESTIC_REPOSITORY="sftp://foo@192.168.0.1:22//home/bar" + # or for b2 + #RESTIC_REPOSITORY="b2:backup" + #B2_ACCOUNT_ID="ID" + #B2_ACCOUNT_KEY="KEY" + + if [[ ! -f "$HOME/.config/restic/env" && ! -f "/etc/restic/env" ]]; then + echo "no config provided" + exit 1 + fi + + . $HOME/.config/restic/env 2> /dev/null || . /etc/restic/env 2> /dev/null + export RESTIC_PASSWORD="${RESTIC_PASSWORD}" +} + +info() { printf "\n\e[1m%s\e[0m\n" "$*" >&2; } + +info "Testing if restic is already running..." +if pgrep -x "restic" &> /dev/null; then + echo "-> Restic is already runnning" + exit 1 +fi +info "Done" + +info "Updating restic..." +restic self-update +info "Done" + +read_config + +#restic -r ${RESTIC_REPOSITORY} unlock +if [[ $1 == 'prune' ]]; then + info "Pruning snapshots..." + restic --cache-dir ${CACHE_DIR} -r ${RESTIC_REPOSITORY} prune --max-unused 0 + info "Done" +else + info "Starting backup..." + restic --cache-dir ${CACHE_DIR} -r ${RESTIC_REPOSITORY} backup ${BACKUP_PATHS} \ + --exclude-file ${EXCLUDES_FILE} + info "Done" + + info "Forgetting snapshots..." + restic --cache-dir ${CACHE_DIR} -r ${RESTIC_REPOSITORY} forget \ + --keep-hourly ${KEEP_HOURS} --keep-daily ${KEEP_DAYS} \ + --keep-weekly ${KEEP_WEEKS} --keep-monthly ${KEEP_WEEKS} \ + --keep-yearly ${KEEP_YEARS} \ + --prune + info "Done" +fi diff --git a/restic/.bin/restic_backup b/restic/.bin/restic_backup deleted file mode 100755 index 589409d..0000000 --- a/restic/.bin/restic_backup +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -. $HOME/.bin/restic_common -export RESTIC_PASSWORD="${RESTIC_PASSWORD}" -export PATH="$HOME/.local/bin:$PATH" - -info "Starting backup" -restic -r ${RESTIC_REPOSITORY} unlock -restic --cache-dir ${CACHE_DIR} -r ${RESTIC_REPOSITORY} backup ${BACKUP_PATHS} --exclude ${BACKUP_EXCLUDES} - -info "Forgetting snapshots" -restic --cache-dir ${CACHE_DIR} -r ${RESTIC_REPOSITORY} forget --keep-hourly ${KEEP_HOURS} --keep-daily ${KEEP_DAYS} --keep-weekly ${KEEP_WEEKS} --keep-monthly ${KEEP_WEEKS} --keep-yearly ${KEEP_YEARS} diff --git a/restic/.bin/restic_common b/restic/.bin/restic_common deleted file mode 100755 index bf55826..0000000 --- a/restic/.bin/restic_common +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash - -read_config() { - # variables - - #CACHE_DIR="$HOME/.cache/restic" - #BACKUP_PATHS="/etc /home/docker/volumes /root" - #BACKUP_EXCLUDES="-e /home/docker/volumes/syncthing" - #KEEP_HOURS=96 - #KEEP_DAYS=31 - #KEEP_WEEKS=8 - #KEEP_MONTHS=12 - #KEEP_YEARS=3 - #RESTIC_PASSWORD="PASSWORD" - #RESTIC_REPOSITORY="sftp://foo@${BACKUP_SERVER}:22//home/bar" - # or for b2 - #RESTIC_REPOSITORY="b2:backup" - #B2_ACCOUNT_ID="ID" - #B2_ACCOUNT_KEY="KEY" - - if [[ ! -f "/etc/restic/env" && ! -f "$HOME/.config/restic/env" ]]; then - echo "no config provided" - exit 1 - fi - - . $HOME/.config/restic/env 2> /dev/null || . /etc/restic/env 2> /dev/null -} - -info() { printf "\n\e[1m%s\e[0m\n" "$*" >&2; } - -info "Testing if restic is already running..." -if pgrep -x "restic" &> /dev/null; then - echo "Restic is already runnning" - exit 1 -fi -echo "Done" - -info "Updating restic..." -restic self-update -echo "Done" - -info "60s delay (in case we just woke up)..." -sleep 60 -echo "Done" - -read_config diff --git a/restic/.bin/restic_prune b/restic/.bin/restic_prune deleted file mode 100755 index 65b9bf0..0000000 --- a/restic/.bin/restic_prune +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -. $HOME/.bin/restic_common -export RESTIC_PASSWORD="${RESTIC_PASSWORD}" -export PATH="$HOME/.local/bin:$PATH" - -info "Pruning snapshots" -restic --cache-dir ${CACHE_DIR} -r ${RESTIC_REPOSITORY} prune diff --git a/restic/.config/systemd/user/restic-backup.service b/restic/.config/systemd/user/restic-backup.service index 957d695..a6a22f1 100644 --- a/restic/.config/systemd/user/restic-backup.service +++ b/restic/.config/systemd/user/restic-backup.service @@ -1,12 +1,10 @@ [Unit] Description=restic backup -Before=restic-prune.service -Wants=network-online.target -After=network-online.target [Service] Type=oneshot -ExecStart=%h/.bin/restic_backup +ExecStartPre=/usr/bin/nm-online -q +ExecStart=%h/.bin/restic-backup [Install] WantedBy=multi-user.target diff --git a/restic/.config/systemd/user/restic-backup.timer b/restic/.config/systemd/user/restic-backup.timer index e9373b6..defa16e 100644 --- a/restic/.config/systemd/user/restic-backup.timer +++ b/restic/.config/systemd/user/restic-backup.timer @@ -4,7 +4,6 @@ Description=restic backup [Timer] Persistent=true OnCalendar=hourly -Unit=restic-backup.service [Install] WantedBy=timers.target diff --git a/restic/.config/systemd/user/restic-prune.service b/restic/.config/systemd/user/restic-prune.service deleted file mode 100644 index 96c08ef..0000000 --- a/restic/.config/systemd/user/restic-prune.service +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description=restic prune snapshots -After=restic-backup.service -Wants=network-online.target -After=network-online.target - -[Service] -Type=oneshot -ExecStart=%h/.bin/restic_prune - -[Install] -WantedBy=multi-user.target diff --git a/restic/.config/systemd/user/restic-prune.timer b/restic/.config/systemd/user/restic-prune.timer deleted file mode 100644 index d77a753..0000000 --- a/restic/.config/systemd/user/restic-prune.timer +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=restic prune snapshots - -[Timer] -Persistent=true -OnCalendar=weekly -Unit=restic-prune.service - -[Install] -WantedBy=timers.target \ No newline at end of file