1
0

add DELETE_OUTDATED to prune old remote bkfiles

This commit is contained in:
michele
2014-04-19 13:00:53 +02:00
parent 4d72ac0ecc
commit 32adb7b11c
2 changed files with 37 additions and 2 deletions

View File

@ -204,12 +204,38 @@ If you want to cleanup the backup file locally after uploading it upstream, set
`CLEAR_BKFILE` environment variable to a non-empty value. `zfsbk.sh` will maintain the local `CLEAR_BKFILE` environment variable to a non-empty value. `zfsbk.sh` will maintain the local
backup regardless of this variable if the upload failed. backup regardless of this variable if the upload failed.
# delete generated bkfile locally after successful upload
UPLOAD_PATH="..." CLEAR_BKFILE=yep /usr/local/sbin/zfsbk.sh mybk 7
Ask `zfsbk` to remove an old sequence remotely before uploading a new one:
# remove all bkfiles of old sequence *remotely* before uploading new one
UPLOAD_PATH="..." DELETE_OUTDATED="yep" /usr/local/sbin/zfsbk.sh mybk 7
This allows you to cap the size taken by backups at the remote.
# Managing multiple ZFS Pools # Managing multiple ZFS Pools
Simply run these scripts once for each pool, setting the _ZPOOL_ environment variable Simply run these scripts once for each pool, setting the _ZPOOL_ environment variable
accordingly. accordingly.
# Summary of control variables
Here's all environment variables controlling the behavior or `zfssnap` and `zfsbk`:
## zfssnap
* `ZPOOL` [str] name of the ZFS pool to operate on.
* `EXCLUDES` [str] space-separated list of dataset names to exclude from snapshots. Overrides defaults.
* `EXTRA_EXCLUDES` [str] space-separated list of dataset names to exclude from snapshots in addition to defaults.
## zfsbk
* `UPLOAD_PATH` [str] Upload generated bkfile to this remote location; 'scp://' or 'rsync://'
* `CLEAR_BKFILE` [any] If non-empty, remove copy of generated bkfile after successful remote upload.
* `DELETE_OUTDATED` [any] If non-empty, remove old backup sequence remotely before uploading first bkfile of a new sequence.
# Ancillaries # Ancillaries
## Warranty ## Warranty

View File

@ -102,20 +102,29 @@ fi
# upload backup to remote location # upload backup to remote location
if [ "x$UPLOAD_PATH" != x ] if [ "x$UPLOAD_PATH" != x ]
then then
upload_excode=1 # assume failure, override with actual outcome
#echo "Archiving $bkfile remotely..." #echo "Archiving $bkfile remotely..."
if echo "$UPLOAD_PATH" | grep -qE '^rsync://' if echo "$UPLOAD_PATH" | grep -qE '^rsync://'
then then
rsync -qz $bkfile ${UPLOAD_PATH#rsync://} rsync -qz $bkfile ${UPLOAD_PATH#rsync://}
upload_excode=$?
elif echo "$UPLOAD_PATH" | grep -qE '^scp://' elif echo "$UPLOAD_PATH" | grep -qE '^scp://'
then then
scp -BCq $bkfile ${UPLOAD_PATH#scp://} SCP_PATH=${UPLOAD_PATH#scp://}
if [ "$num_snaps" -eq 1 -a "x$DELETE_OUTDATED" != x ]
then
echo "Clearing old zbk-${bkname}* sequence remotely..."
echo "rm zbk-${bkname}*" | sftp -q -b- $SCP_PATH
fi
scp -BCq $bkfile "$SCP_PATH"
upload_excode=$?
else else
echo "UPLOAD_PATH not understood! '$UPLOAD_PATH'" echo "UPLOAD_PATH not understood! '$UPLOAD_PATH'"
echo "Expecting rsync://.. or scp://.." echo "Expecting rsync://.. or scp://.."
exit 1 exit 1
fi fi
# remove local backup if requested & upload was successful # remove local backup if requested & upload was successful
if [ $? -eq 0 -a "x$CLEAR_BKFILE" != x ] if [ $upload_excode -eq 0 -a "x$CLEAR_BKFILE" != x ]
then then
# remove backup file if requested # remove backup file if requested
rm -f $bkfile rm -f $bkfile