make dobackup work correctly

This commit is contained in:
root 2022-12-12 16:11:22 +00:00
parent 8560e368b1
commit f425f1d72f
2 changed files with 23 additions and 16 deletions

6
tilserv/delbackup Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env -S bash -e
for i in $(zfs list -H -o name -t snapshot | grep 'bighdd\/backup\/.*@2.*'); do
if (( date - ${i##bighdd*@} >= 7 )); then
echo "$i is to be deleted since the snapshot is 7 days or older"
fi
done

View File

@ -1,17 +1,18 @@
#!/bin/bash
#!/usr/bin/env -S bash -e
#if [ -z $1 ]; then echo "Usage: $0 [target pool]"; exit 1; fi
targetpool="bighdd/backup"
incbackup="nvme/gitea@inc"
newsnap="gitea@$(date +%Y%m%d)"
latestsnap=$(zfs list -r -t snapshot -H -o name bighdd/backup/gitea | grep gitea@ | tail -n1)
if [ "bighdd/backup/$newsnap" != "$latestsnap" ]; then
set -x
zfs snapshot -r nvme/$newsnap
zfs send -RI $incbackup nvme/$newsnap | zfs recv -Fu ${targetpool}/gitea
zfs destroy nvme/$newsnap
set +x
else
echo "Backup ($targetpool) already contains snapshot $backupsnap"
fi
backupscript() {
targetpool="bighdd/backup"
incbackup="nvme/${1}@inc"
newsnap="${1}@$(date +%Y%m%d)"
latestsnap=$(zfs list -r -t snapshot -H -o name bighdd/backup/${1} | grep ${1}@ | tail -n1)
if [ "bighdd/backup/$newsnap" != "$latestsnap" ]; then
set -x
zfs snapshot -r nvme/$newsnap
zfs send -RI $incbackup nvme/$newsnap | pv | zfs recv -Fu ${targetpool}/${1}
zfs destroy nvme/$newsnap
set +x
else
echo "Backup ($targetpool) already contains snapshot of $1"
fi
}
for i in ${@}; do backupscript ${i}; done