ansible/playbooks/apps/files/bin/borg-sync

46 lines
1.1 KiB
Text
Raw Permalink Normal View History

2024-10-15 08:54:52 +02:00
#!/bin/bash
# Change all the variables below to suit your needs:
2024-10-16 20:51:57 +02:00
SOURCE_DIRECTORY="/mnt/backup/nextcloud/borg"
2024-10-15 08:54:52 +02:00
RCLONE_CONFIG="borgbase-nextcloud-aio"
2024-10-15 18:32:42 +02:00
TARGET_DIRECTORY="repo"
2024-10-15 08:54:52 +02:00
if [ "$EUID" -ne 0 ]; then
echo "run as root"
output 1
fi
if ! [ -d "$SOURCE_DIRECTORY" ]; then
echo "The root directory does not exist."
exit 1
fi
if [ -z "$(ls -A "$SOURCE_DIRECTORY/")" ]; then
echo "The source directory is empty, which is not allowed."
exit 1
fi
if [ -f "$SOURCE_DIRECTORY/lock.roster" ]; then
echo "Unable to execute the script as the backup archive is currently modified. Please try again later."
exit 1
fi
if [ -f "$SOURCE_DIRECTORY/aio-lockfile" ]; then
echo "Cannot continue because aio-lockfile already exists."
exit 1
fi
touch "$SOURCE_DIRECTORY/aio-lockfile"
if ! rclone sync -v --exclude aio-lockfile "$SOURCE_DIRECTORY/" "$RCLONE_CONFIG:$TARGET_DIRECTORY"; then
2024-10-15 18:32:42 +02:00
echo "Failed to synchronise the backup repository with the target directory."
2024-10-15 08:54:52 +02:00
rm "$SOURCE_DIRECTORY/aio-lockfile"
exit 1
fi
rm "$SOURCE_DIRECTORY/aio-lockfile"
2024-10-15 18:32:42 +02:00
echo "Done"