Add 'initialize' command, define 'backup' command

This commit is contained in:
maride 2024-08-09 13:46:40 +02:00
parent b0df927e75
commit 147df3c3a6
2 changed files with 15 additions and 3 deletions

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/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

View File

@ -3,6 +3,14 @@
# Inform user # Inform user
echo "Welcome to tupper! Running on $(date)" 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 # Check access rights of config file
CONF="/etc/tupper.conf" CONF="/etc/tupper.conf"
if [ "$(stat -c '%U' $CONF)" != "root" ] && [ "$(stat -c '%A' $CONF)" = "*------" ]; then if [ "$(stat -c '%U' $CONF)" != "root" ] && [ "$(stat -c '%A' $CONF)" = "*------" ]; then
@ -35,8 +43,12 @@ fi
# Backup # Backup
export BORG_PASSPHRASE export BORG_PASSPHRASE
export BORG_RELOCATED_REPO_ACCESS_IS_OK=yes export BORG_RELOCATED_REPO_ACCESS_IS_OK=yes
borg create --stats "$MOUNTPOINT::"'{now}' "$TARGET" if [ "$ACTION" = "initialize" ]; then
borg list "$MOUNTPOINT" borg init --encryption=repokey "$TARGET"
elif [ "$ACTION" = "backup" ]; then
borg create --stats "$MOUNTPOINT::"'{now}' "$TARGET"
borg list "$MOUNTPOINT"
fi
# Unmount and clean up mountpoint # Unmount and clean up mountpoint
fusermount -u "$MOUNTPOINT" && \ fusermount -u "$MOUNTPOINT" && \