Make pruning configurable

This commit is contained in:
Andras Schmelczer 2024-06-02 11:43:17 +01:00
parent e8411ca6ea
commit 25ea57ea38

View file

@ -1,17 +1,24 @@
#!/bin/bash #!/bin/bash
KEEP_DAILY=${KEEP_DAILY:-6}
KEEP_WEEKLY=${KEEP_WEEKLY:-3}
KEEP_MONTHLY=${KEEP_MONTHLY:-48}
KEEP_YEARLY=${KEEP_YEARLY:-0}
echo "Starting backup script at `date`" echo "Starting backup script at `date`"
export BORG_RSH='ssh -oBatchMode=yes' # https://borgbackup.readthedocs.io/en/stable/usage/notes.html#ssh-batch-mode export BORG_RSH='ssh -oBatchMode=yes' # https://borgbackup.readthedocs.io/en/stable/usage/notes.html#ssh-batch-mode
# break any stale locks in case the script was interrupted
borg break-lock borg break-lock
borg info
borg info # test whether we have a valid repository
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Borg info returned a non-zero status. Initializing Borg..." echo "Borg info returned a non-zero status. Initializing Borg..."
borg init --encryption=repokey borg init --encryption=repokey
fi fi
# the above command will fail if the repo hasn't been already initialized, so we can ignore the return status
set -e set -e
if [ -d "/snapshot/source" ]; then if [ -d "/snapshot/source" ]; then
@ -23,8 +30,14 @@ btrfs subvolume snapshot /source /snapshot
cd /snapshot/source cd /snapshot/source
borg create --stats --list --filter=AMCE --files-cache=ctime,size --compression=zstd,12 --exclude-from /exclude.conf ::"{hostname}-{now:%Y-%m-%dT%H:%M:%S}" . borg create --stats --list --filter=AMCE --files-cache=ctime,size --compression=zstd,12 --exclude-from /exclude.conf ::"{hostname}-{now:%Y-%m-%dT%H:%M:%S}" .
cd - cd -
borg prune --list --stats --keep-daily=7 --keep-weekly=4 --keep-monthly=12 --keep-yearly=5
borg compact --threshold=5 --cleanup-commits borg prune --list --stats \
--keep-daily=$KEEP_DAILY \
--keep-weekly=$KEEP_WEEKLY \
--keep-monthly=$KEEP_MONTHLY \
--keep-yearly=$KEEP_YEARLY
borg compact --threshold=5 --cleanup-commits --verbose --progress
btrfs subvolume delete /snapshot/source btrfs subvolume delete /snapshot/source