add DELETE_OUTDATED to prune old remote bkfiles
This commit is contained in:
26
README.md
26
README.md
@ -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
|
||||
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
|
||||
|
||||
Simply run these scripts once for each pool, setting the _ZPOOL_ environment variable
|
||||
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
|
||||
|
||||
## Warranty
|
||||
|
||||
13
zfsbk.sh
13
zfsbk.sh
@ -102,20 +102,29 @@ fi
|
||||
# upload backup to remote location
|
||||
if [ "x$UPLOAD_PATH" != x ]
|
||||
then
|
||||
upload_excode=1 # assume failure, override with actual outcome
|
||||
#echo "Archiving $bkfile remotely..."
|
||||
if echo "$UPLOAD_PATH" | grep -qE '^rsync://'
|
||||
then
|
||||
rsync -qz $bkfile ${UPLOAD_PATH#rsync://}
|
||||
upload_excode=$?
|
||||
elif echo "$UPLOAD_PATH" | grep -qE '^scp://'
|
||||
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
|
||||
echo "UPLOAD_PATH not understood! '$UPLOAD_PATH'"
|
||||
echo "Expecting rsync://.. or scp://.."
|
||||
exit 1
|
||||
fi
|
||||
# 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
|
||||
# remove backup file if requested
|
||||
rm -f $bkfile
|
||||
|
||||
Reference in New Issue
Block a user