Make pruning configurable
This commit is contained in:
parent
e8411ca6ea
commit
25ea57ea38
1 changed files with 16 additions and 3 deletions
|
|
@ -1,17 +1,24 @@
|
|||
#!/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`"
|
||||
|
||||
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 info
|
||||
|
||||
borg info # test whether we have a valid repository
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Borg info returned a non-zero status. Initializing Borg..."
|
||||
borg init --encryption=repokey
|
||||
fi
|
||||
|
||||
# the above command will fail if the repo hasn't been already initialized, so we can ignore the return status
|
||||
set -e
|
||||
|
||||
if [ -d "/snapshot/source" ]; then
|
||||
|
|
@ -23,8 +30,14 @@ btrfs subvolume snapshot /source /snapshot
|
|||
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}" .
|
||||
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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue