From 135aa0b29262de2f2f20b3aaa92baedb2a6cf163 Mon Sep 17 00:00:00 2001 From: Rob Pearce Date: Mon, 27 Nov 2023 08:19:13 +1100 Subject: [PATCH] rclone now uses excludefile if sepecified in repos file rclone now uses --size-only and --copy-links --- bare.sh | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/bare.sh b/bare.sh index 6442515..2519bab 100755 --- a/bare.sh +++ b/bare.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash VALIDCOMMANDS="go ls init repos stats diff forget get check" RCFILE=${HOME}/.backup/config @@ -70,15 +70,15 @@ function log() { } function updatestats() { - local repo cmd stamp code + local repo cmd stamp code repo=$1 cmd=$2 code=$3 stamp=`date +%s` if [[ -f $STATFILE ]]; then - sed -i "/${repo}:${cmd}/d" $STATFILE + sed -i "/${repo}:${cmd}/d" $STATFILE fi - echo "${repo}:${cmd}:${code}:${stamp}" >> $STATFILE + echo "${repo}:${cmd}:${code}:${stamp}" >> $STATFILE } function usage-repo() { @@ -129,7 +129,7 @@ function usage-rc() { echo " export PGUSER=postgres # Postgresql username" echo "" echo " export DEF_RSYNC_SERVER=xxx # Server used for repos with 'rsync' tag" - echo " export DEF_RSYNC_USER=backups # Username for rsync server" + echo " export DEF_RSYNC_USER=backups # Username for rsync server" echo " export DEF_RSYNC_DIR=/home/backups/backups # Remote directory on rsync server" echo " export RSYNC_OPTIONS=-Pavz # Options to pass to rsync" echo "" @@ -256,7 +256,7 @@ function getrepotok() { # output given token from repo def } function getreponame() { - local reponame + local reponame reponame="$1" @@ -268,7 +268,7 @@ function getreponame() { } function getrepodef() { - local reponame match repodef x + local reponame match repodef x reponame="$1" @@ -285,7 +285,7 @@ function getrepodef() { done fi echo "$repodef" -} +} function gettagval() { # return 0 if tag matches local reponame lookfor justtags x t val @@ -319,7 +319,7 @@ function checktag() { # return 0 if tag matches lookfor="$2" justtags=`getrepotags "$reponame"` - + if [[ $justtags =~ ^.*${lookfor}.*$ ]]; then return 0 fi @@ -334,7 +334,7 @@ function do_mount() { mount | grep -q ${DATAPATH} if [[ $? -ne 0 ]]; then # try mounting it. - ${USMB} ${USMBNAME} >/dev/null + ${USMB} ${USMBNAME} >/dev/null if [[ $? -eq 0 ]]; then log "Mount usmb volume '$USMBNAME': success" else @@ -348,7 +348,7 @@ function do_mount() { if [[ $? -ne 0 ]]; then # try mounting it. mkdir -p $DATAPATH - mount_nfs -R 1 ${NFSPATH} ${DATAPATH} >/dev/null + mount_nfs -R 1 ${NFSPATH} ${DATAPATH} >/dev/null if [[ $? -eq 0 ]]; then log "Mount nfs volume '$NFSPATH' to $DATAPATH: success" else @@ -362,7 +362,7 @@ function do_mount() { if [[ $? -ne 0 ]]; then # try mounting it. mkdir -p $DATAPATH - mount ${DATAPATH} >/dev/null + mount ${DATAPATH} >/dev/null if [[ $? -eq 0 ]]; then log "Mount $DATAPATH: success" else @@ -398,7 +398,7 @@ function do_mount() { count=`ls ${DATAPATH} | wc -l` if [ $count -le 2 ]; then - log "Error: ${DATAPATH} exists but appears to be empty" + log "Error: ${DATAPATH} exists but appears to be empty" return 1 fi fi @@ -473,14 +473,14 @@ function is_mounted() { else formatarg="-f" fi - + dev1=$(stat $formatarg %d $dir 2>/dev/null) dev2=$(stat $formatarg %d $dir/.. 2>/dev/null) if [[ $dev1 == $dev2 ]]; then rv=1 else rv=0 - fi + fi return $rv } @@ -784,7 +784,7 @@ for f in $REPO_LIST; do pgrv=$? checktag "$f" mysql myrv=$? - if [[ $pgrv -ne 0 && $myrv -ne 0 ]]; then + if [[ $pgrv -ne 0 && $myrv -ne 0 ]]; then log "error - can't find matching repo for $f - make sure it is listed in ${REPOFILE}" continue fi @@ -800,7 +800,7 @@ for f in $REPO_LIST; do else NEEDMOUNT=0 fi - + if [[ $NEEDMOUNT -eq 1 ]]; then do_mount $DATAPATH if [[ $? -ne 0 ]]; then @@ -874,7 +874,7 @@ for f in $REPO_LIST; do else USELOCALMOUNT=0 fi - + export REPO_PATH=`getrepopath "$f"` if [[ $? -eq 0 ]]; then @@ -1018,9 +1018,17 @@ for f in $REPO_LIST; do else CONNECTIONSOPTS="--transfers=${CONNECTIONS}" fi + + # use sizeonly to check, follow symlinks + OTHEROPTS="$OTHEROPTS --size-only -L" + + export RESTIC_EXCLUDEFILE=`getrepoexcludefile "$f"` + if [[ -n $RESTIC_EXCLUDEFILE ]]; then + OTHEROPTS="$OTHEROPTS --exclude-from ${RESTIC_EXCLUDEFILE}" + fi fi - + if [[ ! $CMD == "check" ]]; then text="Starting '$CMD' on repo '$REPO' [$DATAPATH <-> $MYREPO]" log "$text" @@ -1449,7 +1457,7 @@ for f in $REPO_LIST; do rv=1 fi fi - + if [[ ! $CMD == "check" ]]; then # Record result updatestats $f $CMD $rv