From 5173e5f33bd033a87108f1cdf943fc5259306eca Mon Sep 17 00:00:00 2001 From: Marco Kundt Date: Wed, 11 Nov 2020 14:17:19 +0100 Subject: [PATCH] Revert "restic isn't usable for me yet" This reverts commit 28ad0db799f55bc14294daf78d8fb2dc8bad308c. --- restic/.bin/restic_backup | 7 +++ restic/.bin/restic_common | 50 +++++++++++++++++++ restic/.bin/restic_prune | 11 ++++ .../systemd/user/restic-backup.service | 10 ++++ .../.config/systemd/user/restic-backup.timer | 10 ++++ .../.config/systemd/user/restic-prune.service | 10 ++++ .../.config/systemd/user/restic-prune.timer | 10 ++++ 7 files changed, 108 insertions(+) create mode 100755 restic/.bin/restic_backup create mode 100755 restic/.bin/restic_common create mode 100755 restic/.bin/restic_prune create mode 100644 restic/.config/systemd/user/restic-backup.service create mode 100644 restic/.config/systemd/user/restic-backup.timer create mode 100644 restic/.config/systemd/user/restic-prune.service create 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..64866c1 --- /dev/null +++ b/restic/.bin/restic_backup @@ -0,0 +1,7 @@ +#!/bin/bash + +source $HOME/.bin/restic_common + +info "Starting backup" +restic -r $RESTIC_REPOSITORY unlock +restic --cache-dir $CACHE_DIR -r $RESTIC_REPOSITORY backup $BACKUP_PATHS $BACKUP_EXCLUDES diff --git a/restic/.bin/restic_common b/restic/.bin/restic_common new file mode 100755 index 0000000..564ad4d --- /dev/null +++ b/restic/.bin/restic_common @@ -0,0 +1,50 @@ +#!/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_REPOSITORY="b2:backup" + #RESTIC_PASSWORD="PASSWORD" + #B2_ACCOUNT_ID="ID" + #B2_ACCOUNT_KEY="KEY" + + if [[ ! -f "/etc/restic/env" && ! -f "$HOME/.config/restic/env" && ! -f "./env" ]]; then + echo "no config provided" + exit 1 + fi + + source ./env 2> /dev/null || source $HOME/.config/restic/env 2> /dev/null || source /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 "Testing connection..." +ping -c 3 192.168.178.100 &> /dev/null + +if [[ $? > 0 ]]; then + + ping -c 3 1.1.1.1 &> /dev/null + + if [[ $? > 0 ]]; then + info "Not connected." + exit 1 + fi +fi +echo "Done" + +read_config diff --git a/restic/.bin/restic_prune b/restic/.bin/restic_prune new file mode 100755 index 0000000..53ba722 --- /dev/null +++ b/restic/.bin/restic_prune @@ -0,0 +1,11 @@ +#!/bin/bash + +source $HOME/.bin/restic_common + +info "Forgetting snapshots" +restic -r $RESTIC_REPOSITORY unlock +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 + +info "Pruning snapshots" +restic -r $RESTIC_REPOSITORY unlock +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 new file mode 100644 index 0000000..8c65abf --- /dev/null +++ b/restic/.config/systemd/user/restic-backup.service @@ -0,0 +1,10 @@ +[Unit] +Description=borg backup +Before=restic-prune.service + +[Service] +Type=oneshot +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 new file mode 100644 index 0000000..e9373b6 --- /dev/null +++ b/restic/.config/systemd/user/restic-backup.timer @@ -0,0 +1,10 @@ +[Unit] +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 new file mode 100644 index 0000000..ea3929b --- /dev/null +++ b/restic/.config/systemd/user/restic-prune.service @@ -0,0 +1,10 @@ +[Unit] +Description=prune borg snapshots +After=restic-backup.service + +[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 new file mode 100644 index 0000000..e0a69cf --- /dev/null +++ b/restic/.config/systemd/user/restic-prune.timer @@ -0,0 +1,10 @@ +[Unit] +Description=prune restic snapshots + +[Timer] +Persistent=true +OnCalendar=daily +Unit=restic-prune.service + +[Install] +WantedBy=timers.target