Adding forget option for restic.

This commit is contained in:
Rob Pearce 2019-03-23 16:06:23 +11:00
parent af731a05e7
commit 671a7ba52a
1 changed files with 25 additions and 21 deletions

46
bare.sh
View File

@ -47,22 +47,25 @@ function usage-repo() {
echo " Sharename determined by stripping \$NFS_PREFIX from start of <repopath>." echo " Sharename determined by stripping \$NFS_PREFIX from start of <repopath>."
} }
function usage-rc() { function usage-rc() {
echo " export B2_ACCOUNT_ID=xxx" echo " export B2_ACCOUNT_ID=xxx # Backblaze B2 credentials"
echo " export B2_ACCOUNT_KEY=xxx" echo " export B2_ACCOUNT_KEY=xxx # Backblaze B2 credentials"
echo " export B2_APP_ID=xxx" echo " export B2_APP_ID=xxx # Backblaze B2 bucket details"
echo " export B2_APP_KEY=xxx" echo " export B2_APP_KEY=xxx # Backblaze B2 bucket auth"
echo " export B2_BUCKET_PREFIX=xxx" echo " export B2_BUCKET_PREFIX=xxx # Prefix to append to create unique B2 bucket name"
echo " export RESTIC_PASSWORD=xxx" echo ""
echo " export RSYNC_SERVER=xxx" echo " export RESTIC_PASSWORD=xxx # Password used to encrypt Restic backups"
echo " export RSYNC_USER=backups" echo " export RESTIC_KEEPDAYS=31 # Days to keep restic backups for"
echo " export RSYNC_DIR=/home/backups/backups" echo ""
echo " export RSYNC_OPTIONS=-Pavz" echo " export RSYNC_SERVER=xxx # Server used for repos with 'rsync' tag"
echo " export KEEPDAYS=31 # days to keep restic backups for" echo " export RSYNC_USER=backups # Username for rsync server"
echo " # optional:" echo " export RSYNC_DIR=/home/backups/backups # Remote directory on rsync server"
echo " #export USMB_PREFIX=/DataVolume/shares" echo " export RSYNC_OPTIONS=-Pavz # Options to pass to rsync"
echo " #export NFS_SERVER=nfs.yourdomain.com" echo ""
echo " #export NFS_SERVER_BASE=/remote/nfs/share/base" echo " export USMB_PREFIX=/DataVolume/shares # Strip this from repo path to get USMB share name"
echo " #export NFS_PREFIX=/local/nfs/mountpoint" echo ""
echo " export NFS_SERVER=nfs.yourdomain.com # NFS server where local files for 'nfs' repos are found"
echo " export NFS_SERVER_BASE=/remote/nfs/share/base # Path on local NFS server to prefix to repo names"
echo " export NFS_PREFIX=/local/nfs/mountpoint # Where to mount NFS exports locally before backing them up"
} }
function usage() { function usage() {
@ -195,8 +198,8 @@ if [[ -z $B2_APP_KEY ]]; then
echo "Error - \$B2_APP_KEY not set." echo "Error - \$B2_APP_KEY not set."
exit 1 exit 1
fi fi
if [[ -z $KEEPFOR ]]; then if [[ -z $RESTIC_KEEPDAYS ]]; then
echo "Error - \$KEEPFOR not set." echo "Error - \$RESTIC_KEEPDAYS not set."
exit 1 exit 1
fi fi
@ -484,9 +487,10 @@ for f in $REPOSTOBACKUP; do
${RESTIC} init $AUTHOPTS $CONNECTIONSOPTS >/dev/null 2>&1 ${RESTIC} init $AUTHOPTS $CONNECTIONSOPTS >/dev/null 2>&1
fi fi
elif [[ $CMD == "forget" ]]; then elif [[ $CMD == "forget" ]]; then
# age out stuff after xxx days # age out stuff after RESTIC_KEEPDAYS days
FORGETOPTS="-d ${KEEPDAYS} --prune" FORGETOPTS="-d ${RESTIC_KEEPDAYS}"
${RESTIC} forget $AUTHOPTS $CONNECTIONSOPTS $FORGETOPTS 2>&1 >> ${LOG} ${RESTIC} forget $AUTHOPTS $CONNECTIONSOPTS $FORGETOPTS 2>&1 | awk '($1 == "Applying") { print } ($2 == "snapshots") { show=0 } (show == 1 && $1 != "ID" && NF > 1) { print "Removing: " $0 } ($1 == "remove") { show=1 }' >> ${LOG}
${RESTIC} prune $AUTHOPTS 2>&1 | egrep "^(repository contain|found|will|remove)" >> ${LOG}
else else
log "Error: invalid command $CMD" log "Error: invalid command $CMD"
rv=0 rv=0