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() {
echo "Backup <DIRECTORY> <TARGET> [EXCLUDES...]"
echo "Backup [OPTION] <DIRECTORY> <TARGET> [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