Added 'forget' mode to age out old restic backups.
When running in cron mode, filter out restic noise.
This commit is contained in:
parent
8c61f8001d
commit
af731a05e7
40
bare.sh
40
bare.sh
|
@ -1,5 +1,5 @@
|
|||
#!/bin/bash
|
||||
VALIDCOMMANDS="go ls init repos stats diff"
|
||||
VALIDCOMMANDS="go ls init repos stats diff forget"
|
||||
|
||||
RCFILE=${HOME}/.backup/config
|
||||
AUTHFILE=${HOME}/.backup/auth
|
||||
|
@ -57,6 +57,7 @@ function usage-rc() {
|
|||
echo " export RSYNC_USER=backups"
|
||||
echo " export RSYNC_DIR=/home/backups/backups"
|
||||
echo " export RSYNC_OPTIONS=-Pavz"
|
||||
echo " export KEEPDAYS=31 # days to keep restic backups for"
|
||||
echo " # optional:"
|
||||
echo " #export USMB_PREFIX=/DataVolume/shares"
|
||||
echo " #export NFS_SERVER=nfs.yourdomain.com"
|
||||
|
@ -194,6 +195,10 @@ if [[ -z $B2_APP_KEY ]]; then
|
|||
echo "Error - \$B2_APP_KEY not set."
|
||||
exit 1
|
||||
fi
|
||||
if [[ -z $KEEPFOR ]]; then
|
||||
echo "Error - \$KEEPFOR not set."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Convert speed from Mbps to KBps
|
||||
if ! [[ -z $SPEED ]]; then
|
||||
|
@ -328,6 +333,7 @@ for f in $REPOSTOBACKUP; do
|
|||
mount | grep -q ${DATAPATH}
|
||||
if [[ $? -ne 0 ]]; then
|
||||
# try mounting it.
|
||||
mkdir -p $DATAPATH
|
||||
mount -t nfs ${NFSPATH} ${DATAPATH} >/dev/null
|
||||
if [[ $? -eq 0 ]]; then
|
||||
log "Mount nfs volume '$NFSPATH' to $DATAPATH: success"
|
||||
|
@ -364,6 +370,24 @@ fi
|
|||
for f in $REPOSTOBACKUP; do
|
||||
REPO=${f}
|
||||
DATAPATH=$(getdatapath $REPO)
|
||||
checktag "$f" usmb
|
||||
if [[ $? -eq 0 ]]; then
|
||||
USMBNAME=`echo "${DATAPATH}" | sed -e "s,${USMB_PREFIX}/\(.*\).*,\1,"`
|
||||
USEUSMB=1
|
||||
else
|
||||
USMBNAME=""
|
||||
USEUSMB=0
|
||||
fi
|
||||
|
||||
checktag "$f" nfs
|
||||
if [[ $? -eq 0 ]]; then
|
||||
NFSNAME=`echo "${DATAPATH}" | sed -e "s,${NFS_PREFIX}/\(.*\).*,\1,"`
|
||||
NFSPATH="${NFS_SERVER}:${NFS_SERVER_BASE}/${NFSNAME}"
|
||||
USENFS=1
|
||||
else
|
||||
NFSNAME=""
|
||||
USENFS=0
|
||||
fi
|
||||
export RESTIC_REPOSITORY="b2:${B2_BUCKET_PREFIX}-${REPO}"
|
||||
export RCLONE_REPOSITORY="remote:${B2_BUCKET_PREFIX}-${REPO}"
|
||||
export RSYNC_FULLDIR="${RSYNC_DIR}/${REPO}"
|
||||
|
@ -436,7 +460,11 @@ for f in $REPOSTOBACKUP; do
|
|||
|
||||
if [[ $mode == "restic" ]]; then
|
||||
if [[ $CMD == "go" ]]; then
|
||||
${RESTIC} backup $AUTHOPTS $CONNECTIONSOPTS $SPEEDOPTS $DATAPATH 2>&1 >> ${LOG}
|
||||
if [[ $CRONMODE -eq 1 ]]; then
|
||||
${RESTIC} backup $AUTHOPTS $CONNECTIONSOPTS $SPEEDOPTS $DATAPATH 2>&1 | egrep "^(Added|processed|snapshot)" >> ${LOG}
|
||||
else
|
||||
${RESTIC} backup $AUTHOPTS $CONNECTIONSOPTS $SPEEDOPTS $DATAPATH 2>&1 >> ${LOG}
|
||||
fi
|
||||
rv=$?
|
||||
elif [[ $CMD == "ls" ]]; then
|
||||
${RESTIC} snapshots $AUTHOPTS $CONNECTIONSOPTS 2>&1 >> ${LOG}
|
||||
|
@ -455,6 +483,10 @@ for f in $REPOSTOBACKUP; do
|
|||
else
|
||||
${RESTIC} init $AUTHOPTS $CONNECTIONSOPTS >/dev/null 2>&1
|
||||
fi
|
||||
elif [[ $CMD == "forget" ]]; then
|
||||
# age out stuff after xxx days
|
||||
FORGETOPTS="-d ${KEEPDAYS} --prune"
|
||||
${RESTIC} forget $AUTHOPTS $CONNECTIONSOPTS $FORGETOPTS 2>&1 >> ${LOG}
|
||||
else
|
||||
log "Error: invalid command $CMD"
|
||||
rv=0
|
||||
|
@ -489,6 +521,8 @@ for f in $REPOSTOBACKUP; do
|
|||
log "Creation of ${RSYNC_FULLDIR} failed."
|
||||
fi
|
||||
fi
|
||||
elif [[ $CMD == "forget" ]]; then
|
||||
log "Error: forget not supported for rsync mode."
|
||||
else
|
||||
log "Error: invalid command $CMD"
|
||||
rv=0
|
||||
|
@ -537,6 +571,8 @@ for f in $REPOSTOBACKUP; do
|
|||
log "Rclone bucket creation of $RCLONE_REPOSITORY failed."
|
||||
fi
|
||||
fi
|
||||
elif [[ $CMD == "forget" ]]; then
|
||||
log "Error: forget not supported for rclone mode."
|
||||
else
|
||||
log "Error: invalid command $CMD"
|
||||
rv=0
|
||||
|
|
Loading…
Reference in New Issue