From 5483502675e2c34897cf486b358e12934c18a9fe Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Mon, 27 May 2024 19:21:20 -0500 Subject: [PATCH] updates to make better use of restic-scripts --- .gitmodules | 3 +++ .python-version | 1 + requirements.txt | 1 + restic-scripts | 1 + scripts/backup.sh | 24 ++++++++++++++++++++++++ scripts/prune_backups.sh | 10 ++++++++++ scripts/restic_prune.sh | 11 ----------- 7 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 .python-version create mode 100644 requirements.txt create mode 160000 restic-scripts create mode 100755 scripts/backup.sh create mode 100755 scripts/prune_backups.sh delete mode 100755 scripts/restic_prune.sh diff --git a/.gitmodules b/.gitmodules index 4f4c91a..10629c8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,3 +2,6 @@ path = docker-observation url = https://gitea.john-stream.com/john/docker-observation.git branch = main +[submodule "restic-scripts"] + path = restic-scripts + url = https://gitea.john-stream.com/john/restic-scripts diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..3c84009 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +json diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..4291c63 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +pydantic>=2,<3 \ No newline at end of file diff --git a/restic-scripts b/restic-scripts new file mode 160000 index 0000000..9127b34 --- /dev/null +++ b/restic-scripts @@ -0,0 +1 @@ +Subproject commit 9127b347392fde986d4c4fc8f1b04f1142be8f50 diff --git a/scripts/backup.sh b/scripts/backup.sh new file mode 100755 index 0000000..0fbab53 --- /dev/null +++ b/scripts/backup.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +set -e + +if [ -z "$BACKUP_DIR" ]; then + echo "Error: BACKUP_DIR is not set." + exit 1 +fi + +if [ -z "$RESTIC_REPOSITORY" ]; then + echo "Error: RESTIC_REPOSITORY is not set." + exit 1 +fi + +if [ -z "$RESTIC_PASSWORD" ]; then + echo "Error: RESTIC_PASSWORD is not set." + exit 1 +fi + +python -m restic.backup --project zigbee-stack --services mqtt,z2m "$@" + +SCRIPT_DIR=$(readlink -f $(dirname "${BASH_SOURCE[0]}")) + +$SCRIPT_DIR/prune_backups.sh diff --git a/scripts/prune_backups.sh b/scripts/prune_backups.sh new file mode 100755 index 0000000..ddc4e26 --- /dev/null +++ b/scripts/prune_backups.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +python -m restic.forget \ +--keep-last 5 \ +--keep-weekly 8 \ +--keep-monthly 12 \ +--keep-yearly 7 +# --json | jq . + +python -m restic.prune \ No newline at end of file diff --git a/scripts/restic_prune.sh b/scripts/restic_prune.sh deleted file mode 100755 index 34fa1f6..0000000 --- a/scripts/restic_prune.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -set -e - -SCRIPT_DIR=$(readlink -f $(dirname "${BASH_SOURCE[0]}")) - -$SCRIPT_DIR/restic_command.sh forget --prune \ ---keep-last 5 \ ---keep-weekly 8 \ ---keep-monthly 12 \ ---keep-yearly 7