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