From 31b85395d64fcec74ca28d10524541094f019e0b Mon Sep 17 00:00:00 2001 From: Martin Winkler Date: Mon, 13 Jan 2020 16:42:29 +0100 Subject: [PATCH] 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" --- seqs/backup.sh | 73 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 29 deletions(-) diff --git a/seqs/backup.sh b/seqs/backup.sh index 6788c5a..702b90a 100755 --- a/seqs/backup.sh +++ b/seqs/backup.sh @@ -40,67 +40,82 @@ step_1() { } step_3_info() { - echo "Backup [EXCLUDES...]" + echo "Backup [OPTION] [EXCLUDES...]" echoinfo "Exclude path notation starts within DIRECTORY." 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() { + local configTarget=0 + local buSource= + local buTarget= + local buExcludes= + local buLog= # don't use step number shift + if [ "$1" == "-t" ] ; then + configTarget=1 + shift + fi + if [ -z "$1" ] ; then echoerr " [E] Noting found to backup $1" exit 1 fi - BACKUP_LOG=$(basename $1) - if [ "$BACKUP_LOG" == "/" ] ; then - BACKUP_LOG="root" - BACKUP_SOURCE=$1 + buLog=$(basename $1) + if [ "$buLog" == "/" ] ; then + buLog="root" + buSource="$1" else # remove trailing slashes - BACKUP_SOURCE=$(echo $1 | sed 's:/*$::') + buSource=$(echo "$1" | sed 's:/*$::') fi - BACKUP_LOG="backup_${BACKUP_LOG}" + buLog="backup_${buLog}" shift - - if [ -z "$1" ] ; then - echoerr " [E] No valid target found" - exit 1 + + if [ $configTarget -ne 0 ] && [ $CONFIG -ne 0 ] ; then + # Taking target from config + 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 - BACKUP_TARGET=$(echo $1 | sed 's:/*$::') - if [ ! -d "${BACKUP_TARGET}" ] && [ ! -L "${BACKUP_TARGET}" ] + if [ ! -d "${buTarget}" ] && [ ! -L "${buTarget}" ] then - echoerr " [E] Backup target (${BACKUP_TARGET}) doesn't exist" + echoerr " [E] Backup target (${buTarget}) doesn't exist" exit 1 fi - shift for exclu in "$@"; do - BU_EXCLUDES+=("--exclude='$exclu'") + buExcludes+=("--exclude='$exclu'") done - echo " [I] Source : $BACKUP_SOURCE" - echo " [I] Target : $BACKUP_TARGET" + echo " [I] Source : $buSource" + echo " [I] Target : $buTarget" echo " [I] Excludes: $@" #fix doubling trailing slash on verbose output when backing up root - local buSource="$BACKUP_SOURCE/" - local buTarget="${BACKUP_TARGET}/$(basename ${BACKUP_SOURCE})" - if [ "$BACKUP_SOURCE" == "/" ] ; then - buSource="/" - buTarget="${BACKUP_TARGET}/" + local tmpSource="$buSource/" + local tmpTarget="${buTarget}/$(basename ${buSource})" + if [ "$buSource" == "/" ] ; then + tmpSource="/" + tmpTarget="${buTarget}/" fi - exep "mount -o rw,remount '${BACKUP_TARGET}' >>/dev/null 2>&1" - exep "mv -f ${BACKUP_TARGET}/${BACKUP_LOG}0.log /tmp/${BACKUP_LOG}1.log 2>/dev/null" - exep "rsync -avAX --delete --info=stats2 ${BU_EXCLUDES[*]} ${buSource} ${buTarget} > /tmp/${BACKUP_LOG}0.log" + exep "mount -o rw,remount '${buTarget}' >>/dev/null 2>&1" + exep "mv -f ${buTarget}/${buLog}0.log /tmp/${buLog}1.log 2>/dev/null" + 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 - exep "mount -o ro,remount '${BACKUP_TARGET}' >>/dev/null 2>&1" + exep "mount -o ro,remount '${buTarget}' >>/dev/null 2>&1" } VERSION_SEQREV=10