From 147df3c3a6347404941dfbe4b7f04e39691864ca Mon Sep 17 00:00:00 2001 From: maride Date: Fri, 9 Aug 2024 13:46:40 +0200 Subject: [PATCH] Add 'initialize' command, define 'backup' command --- etc/cron.daily/tupper | 2 +- usr/sbin/tupper | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/etc/cron.daily/tupper b/etc/cron.daily/tupper index 824aac8..919ae57 100755 --- a/etc/cron.daily/tupper +++ b/etc/cron.daily/tupper @@ -1,4 +1,4 @@ #!/bin/bash -/usr/sbin/tupper 2>&1 | tee --append /var/log/tupper.log +/usr/sbin/tupper backup 2>&1 | tee --append /var/log/tupper.log diff --git a/usr/sbin/tupper b/usr/sbin/tupper index 081b00a..4a9ed94 100755 --- a/usr/sbin/tupper +++ b/usr/sbin/tupper @@ -3,6 +3,14 @@ # Inform user echo "Welcome to tupper! Running on $(date)" +# Check if it is clear what to do +ACTION="$1" +if [ "$ACTION" != "backup" ] && [ "$ACTION" != "initialize" ]; then + echo "tupper requires an action: $0 { initialize | backup }" 1>&2 + echo "Unrecognized action: $ACTION" 1>&2 + exit 1 +fi + # Check access rights of config file CONF="/etc/tupper.conf" if [ "$(stat -c '%U' $CONF)" != "root" ] && [ "$(stat -c '%A' $CONF)" = "*------" ]; then @@ -35,8 +43,12 @@ fi # Backup export BORG_PASSPHRASE export BORG_RELOCATED_REPO_ACCESS_IS_OK=yes -borg create --stats "$MOUNTPOINT::"'{now}' "$TARGET" -borg list "$MOUNTPOINT" +if [ "$ACTION" = "initialize" ]; then + borg init --encryption=repokey "$TARGET" +elif [ "$ACTION" = "backup" ]; then + borg create --stats "$MOUNTPOINT::"'{now}' "$TARGET" + borg list "$MOUNTPOINT" +fi # Unmount and clean up mountpoint fusermount -u "$MOUNTPOINT" && \