New budir option to take backup target from config

Rsync doesn't cross filesystem boundaries any more

Important partitions need to be backup separately using "budir"
This commit is contained in:
2020-01-13 16:42:29 +01:00
parent 84855cded6
commit 31b85395d6

View File

@@ -40,67 +40,82 @@ step_1() {
} }
step_3_info() { step_3_info() {
echo "Backup <DIRECTORY> <TARGET> [EXCLUDES...]" echo "Backup [OPTION] <DIRECTORY> <TARGET> [EXCLUDES...]"
echoinfo "Exclude path notation starts within DIRECTORY." echoinfo "Exclude path notation starts within DIRECTORY."
echoinfo "e.g. to exclude DIRECTORY/a:" echoinfo "e.g. to exclude DIRECTORY/a:"
echoinfo " $0 budir DIRECTORY TARGET a" echoinfo " $0 budir DIRECTORY TARGET /a"
} }
step_3_alias() { ALIAS="budir"; } step_3_alias() { ALIAS="budir"; }
step_3() { step_3() {
local configTarget=0
local buSource=
local buTarget=
local buExcludes=
local buLog=
# don't use step number # don't use step number
shift shift
if [ "$1" == "-t" ] ; then
configTarget=1
shift
fi
if [ -z "$1" ] ; then if [ -z "$1" ] ; then
echoerr " [E] Noting found to backup $1" echoerr " [E] Noting found to backup $1"
exit 1 exit 1
fi fi
BACKUP_LOG=$(basename $1) buLog=$(basename $1)
if [ "$BACKUP_LOG" == "/" ] ; then if [ "$buLog" == "/" ] ; then
BACKUP_LOG="root" buLog="root"
BACKUP_SOURCE=$1 buSource="$1"
else else
# remove trailing slashes # remove trailing slashes
BACKUP_SOURCE=$(echo $1 | sed 's:/*$::') buSource=$(echo "$1" | sed 's:/*$::')
fi fi
BACKUP_LOG="backup_${BACKUP_LOG}" buLog="backup_${buLog}"
shift shift
if [ -z "$1" ] ; then if [ $configTarget -ne 0 ] && [ $CONFIG -ne 0 ] ; then
echoerr " [E] No valid target found" # Taking target from config
exit 1 buTarget=$(echo "$BACKUP_TARGET" | sed 's:/*$::')
else
if [ -z "$1" ] ; then
echoerr " [E] No valid target found"
exit 1
fi
buTarget=$(echo "$1" | sed 's:/*$::')
shift
fi fi
BACKUP_TARGET=$(echo $1 | sed 's:/*$::') if [ ! -d "${buTarget}" ] && [ ! -L "${buTarget}" ]
if [ ! -d "${BACKUP_TARGET}" ] && [ ! -L "${BACKUP_TARGET}" ]
then then
echoerr " [E] Backup target (${BACKUP_TARGET}) doesn't exist" echoerr " [E] Backup target (${buTarget}) doesn't exist"
exit 1 exit 1
fi fi
shift
for exclu in "$@"; do for exclu in "$@"; do
BU_EXCLUDES+=("--exclude='$exclu'") buExcludes+=("--exclude='$exclu'")
done done
echo " [I] Source : $BACKUP_SOURCE" echo " [I] Source : $buSource"
echo " [I] Target : $BACKUP_TARGET" echo " [I] Target : $buTarget"
echo " [I] Excludes: $@" echo " [I] Excludes: $@"
#fix doubling trailing slash on verbose output when backing up root #fix doubling trailing slash on verbose output when backing up root
local buSource="$BACKUP_SOURCE/" local tmpSource="$buSource/"
local buTarget="${BACKUP_TARGET}/$(basename ${BACKUP_SOURCE})" local tmpTarget="${buTarget}/$(basename ${buSource})"
if [ "$BACKUP_SOURCE" == "/" ] ; then if [ "$buSource" == "/" ] ; then
buSource="/" tmpSource="/"
buTarget="${BACKUP_TARGET}/" tmpTarget="${buTarget}/"
fi fi
exep "mount -o rw,remount '${BACKUP_TARGET}' >>/dev/null 2>&1" exep "mount -o rw,remount '${buTarget}' >>/dev/null 2>&1"
exep "mv -f ${BACKUP_TARGET}/${BACKUP_LOG}0.log /tmp/${BACKUP_LOG}1.log 2>/dev/null" exep "mv -f ${buTarget}/${buLog}0.log /tmp/${buLog}1.log 2>/dev/null"
exep "rsync -avAX --delete --info=stats2 ${BU_EXCLUDES[*]} ${buSource} ${buTarget} > /tmp/${BACKUP_LOG}0.log" exep "rsync -avxHAX --delete --info=stats2 ${buExcludes[*]} ${tmpSource} ${tmpTarget} > /tmp/${buLog}0.log"
exe mv -f /tmp/${BACKUP_LOG}*.log ${BACKUP_TARGET} exe mv -f /tmp/${buLog}*.log ${buTarget}
exe sync exe sync
exep "mount -o ro,remount '${BACKUP_TARGET}' >>/dev/null 2>&1" exep "mount -o ro,remount '${buTarget}' >>/dev/null 2>&1"
} }
VERSION_SEQREV=10 VERSION_SEQREV=10