zirias@
Developer
For my private server, I want to have a full backup of the ZFS pool, including all datasets, snapshots, clones (also newly created ones since the last backup). The replication mode (flag
The only issue is: there are a few datasets that are just "scratch data", so a backup doesn't make any sense. The most massive of them is my ccache for the poudriere builder. I don't mind the space it consumes, but it also consumes time, and it's a bit annoying having to wait for a backup of stuff that really really doesn't need a backup.
So, I'm looking for a simple and reliable way to just exclude a few specific datasets from my full backup, while still automatically including any new datasets etc (and also deleting datasets in the backup pool that don't exist any more).
If there's some premade tool based on
– but restoring the pool should be possible with just stock ZFS tooling.
-R
) of zfs send/recv
basically does the right thing. So currently, I'm using this script that served me well for a long time now, which was created by modifying some script I found somewhere...
Bash:
#!/bin/sh -e
KEEPOLD=3
PREFIX=backup
MASTERPOOL=${1:-zroot}
BACKUPPOOL=${2:-backup}
echo Backup from $MASTERPOOL to $BACKUPPOOL.
zpool import -N $BACKUPPOOL
recentBSnap=$(zfs list -rt snap -H -o name $BACKUPPOOL/$MASTERPOOL \
| grep "$BACKUPPOOL/$MASTERPOOL@${PREFIX}-" | tail -1 | cut -d@ -f2)
NEWSNAP=$MASTERPOOL@$PREFIX-$(date '+%Y%m%d-%H%M%S')
if test -z "$recentBSnap"; then
zfs snapshot -r $NEWSNAP
zfs send -Rcv $NEWSNAP | zfs recv -Fuv $BACKUPPOOL/$MASTERPOOL
else
origBSnap=$(zfs list -rt snap -H -o name $MASTERPOOL \
| grep $recentBSnap | head -n1 | cut -d@ -f2)
if test "$recentBSnap" != "$origBSnap"; then
echo Error, snapshot $recentBSnap does not exist in $MASTERPOOL.
zpool export $BACKUPPOOL
exit 1
fi
zfs snapshot -r $NEWSNAP
zfs send -RcvI @$recentBSnap $NEWSNAP \
| zfs recv -Fuv $BACKUPPOOL/$MASTERPOOL
zfs list -rt snap -H -o name $BACKUPPOOL/$MASTERPOOL \
| grep "$BACKUPPOOL/$MASTERPOOL@${PREFIX}-" | tail -r \
| tail +$(($KEEPOLD + 1)) | xargs -n 1 zfs destroy -r
zfs list -rt snap -H -o name $MASTERPOOL \
| grep "$MASTERPOOL@${PREFIX}-" | tail -r \
| tail +$(($KEEPOLD + 1)) | xargs -n 1 zfs destroy -r
fi
zpool export $BACKUPPOOL
The only issue is: there are a few datasets that are just "scratch data", so a backup doesn't make any sense. The most massive of them is my ccache for the poudriere builder. I don't mind the space it consumes, but it also consumes time, and it's a bit annoying having to wait for a backup of stuff that really really doesn't need a backup.
So, I'm looking for a simple and reliable way to just exclude a few specific datasets from my full backup, while still automatically including any new datasets etc (and also deleting datasets in the backup pool that don't exist any more).
If there's some premade tool based on
zfs send/recv
that could be configured to do what I want, please suggest that as well, I don't insist on using a simple script here