From 715aa664418a9e4997f03d94b615f495bac5b5ef Mon Sep 17 00:00:00 2001 From: rpi-simonz Date: Wed, 25 Sep 2024 11:04:36 +0200 Subject: [PATCH 01/29] Include OS release info in backup directory names --- raspiBackup.sh | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/raspiBackup.sh b/raspiBackup.sh index f0ea9768..81406d12 100755 --- a/raspiBackup.sh +++ b/raspiBackup.sh @@ -3870,6 +3870,13 @@ function readConfigParameters() { logExit } +function setupOsRelease() { + + # TODO: Need to make this more foolproof?? Probably not. + test -e /etc/os-release && os_release='/etc/os-release' || os_release='/usr/lib/os-release' + . "${os_release}" +} + function setupEnvironment() { logEntry @@ -3890,10 +3897,14 @@ function setupEnvironment() { BACKUPFILES_PARTITION_DATE="$HOSTNAME-backup" + # For including the OS release into the name of the backup directory + setupOsRelease + HOSTNAME_OSR="${HOSTNAME}@${ID}${VERSION_ID}" + if [[ -z "$BACKUP_DIRECTORY_NAME" ]]; then - BACKUPFILE="${HOSTNAME}-${BACKUPTYPE}-backup-$DATE" + BACKUPFILE="${HOSTNAME_OSR}-${BACKUPTYPE}-backup-$DATE" else - BACKUPFILE="${HOSTNAME}-${BACKUPTYPE}-backup-${DATE}_${BACKUP_DIRECTORY_NAME}" + BACKUPFILE="${HOSTNAME_OSR}-${BACKUPTYPE}-backup-${DATE}_${BACKUP_DIRECTORY_NAME}" fi BACKUPTARGET_ROOT="$BACKUPPATH/$HOSTNAME" @@ -5606,7 +5617,7 @@ function backupRsync() { # partition number (for partition based backup) source="/" bootPartitionBackup - lastBackupDir=$(find "$BACKUPTARGET_ROOT" -maxdepth 1 -type d -name "*-$BACKUPTYPE-*" ! -name $BACKUPFILE 2>>/dev/null | sort | tail -n 1) + lastBackupDir=$(find "$BACKUPTARGET_ROOT" -maxdepth 1 -type d -name "${HOSTNAME_OSR}*-$BACKUPTYPE-*" ! -name $BACKUPFILE 2>>/dev/null | sort | tail -n 1) excludeRoot="" excludeMeta="--exclude=/$BACKUPFILES_PARTITION_DATE.img --exclude=/$BACKUPFILES_PARTITION_DATE.tmg --exclude=/$BACKUPFILES_PARTITION_DATE.sfdisk --exclude=/$BACKUPFILES_PARTITION_DATE.blkid --exclude=/$BACKUPFILES_PARTITION_DATE.fdisk --exclude=/$BACKUPFILES_PARTITION_DATE.parted --exclude=/$BACKUPFILES_PARTITION_DATE.mbr --exclude=/$MYNAME.log --exclude=/$MYNAME.msg" fi @@ -6130,7 +6141,7 @@ function applyBackupStrategy() { if ! pushd "$BACKUPPATH" &>>$LOG_FILE; then assertionFailed $LINENO "push to $BACKUPPATH failed" fi - ls -d ${HOSTNAME}-${BACKUPTYPE}-backup-* 2>>$LOG_FILE| grep -vE "_" | head -n -$keepBackups | xargs -I {} rm -rf "{}" &>>"$LOG_FILE"; + ls -d ${HOSTNAME_OSR}-${BACKUPTYPE}-backup-* 2>>$LOG_FILE| grep -vE "_" | head -n -$keepBackups | xargs -I {} rm -rf "{}" &>>"$LOG_FILE"; if ! popd &>>$LOG_FILE; then assertionFailed $LINENO "pop failed" fi @@ -7161,7 +7172,8 @@ function doitBackup() { fi logCommand "ls -1 ${BACKUPPATH}" - local nonRaspiGeneratedDirs=$(ls -1 ${BACKUPPATH} | egrep -Ev "$HOSTNAME\-($POSSIBLE_BACKUP_TYPES_REGEX)\-backup\-([0-9]){8}.([0-9]){6}" | egrep -E "\-backup\-" | wc -l) + # Note: The new optional part (@.*?)* in the regex below saves possible older backups without the OS release in the name from being deleted as nonRaspiGeneratedDirs! + local nonRaspiGeneratedDirs=$(ls -1 ${BACKUPPATH} | egrep -Ev "$HOSTNAME(@.*?)*\-($POSSIBLE_BACKUP_TYPES_REGEX)\-backup\-([0-9]){8}.([0-9]){6}" | egrep -E "\-backup\-" | wc -l) logItem "nonRaspiGeneratedDirs: $nonRaspiGeneratedDirs" if (( $nonRaspiGeneratedDirs > 0 )); then @@ -7280,8 +7292,8 @@ function findNonpartitionBackupBootAndRootpartitionFiles() { if [[ -f "$RESTOREFILE" || $BACKUPTYPE == $BACKUPTYPE_RSYNC ]]; then ROOT_RESTOREFILE="$RESTOREFILE" else - logItem "${RESTOREFILE}/${HOSTNAME}-*-backup*" - ROOT_RESTOREFILE="$(ls ${RESTOREFILE}/${HOSTNAME}-*-backup*)" + logItem "${RESTOREFILE}/${HOSTNAME_OSR}-*-backup*" + ROOT_RESTOREFILE="$(ls ${RESTOREFILE}/${HOSTNAME_OSR}-*-backup*)" logItem "ROOT_RESTOREFILE: $ROOT_RESTOREFILE" if [[ -z "$ROOT_RESTOREFILE" ]]; then writeToConsole $MSG_LEVEL_MINIMAL $MSG_NO_ROOTBACKUPFILE_FOUND $BACKUPTYPE @@ -7994,7 +8006,8 @@ function doitRestore() { BASE_DIR=$(dirname "$RESTOREFILE") logItem "Basedir: $BASE_DIR" - HOSTNAME=$(basename "$RESTOREFILE" | sed -r 's/(.*)-[A-Za-z]+-backup-[0-9]+-[0-9]+.*/\1/') + # Note: Handle old (without) and new (with OS release info) backup directory names + HOSTNAME=$(basename "$RESTOREFILE" | sed -r 's/(.*)(@[A-Za-z0-9]+)*-[A-Za-z]+-backup-[0-9]+-[0-9]+.*/\1/') logItem "Hostname: $HOSTNAME" BACKUPTYPE=$(basename "$RESTOREFILE" | sed -r 's/.*-([A-Za-z]+)-backup-[0-9]+-[0-9]+.*/\1/') logItem "Backuptype: $BACKUPTYPE" From 0012dfd0274ba69acb6d82e6bdf8cbe9667eeeb6 Mon Sep 17 00:00:00 2001 From: rpi-simonz Date: Wed, 25 Sep 2024 11:10:55 +0200 Subject: [PATCH 02/29] Remove superfluous hostname from message --- raspiBackup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/raspiBackup.sh b/raspiBackup.sh index 81406d12..cc40639e 100755 --- a/raspiBackup.sh +++ b/raspiBackup.sh @@ -7202,7 +7202,7 @@ function doitBackup() { # now either execute a SR dryrun or start backup if (( $SMART_RECYCLE_DRYRUN && $SMART_RECYCLE )); then # just apply backup strategy to test smart recycle - writeToConsole $MSG_LEVEL_MINIMAL $MSG_APPLYING_BACKUP_STRATEGY_ONLY "$BACKUPPATH/$(hostname)" + writeToConsole $MSG_LEVEL_MINIMAL $MSG_APPLYING_BACKUP_STRATEGY_ONLY "$BACKUPPATH" applyBackupStrategy rc=0 else From 77009711c3c0cd17ddb59ed6e9d250261fcda711 Mon Sep 17 00:00:00 2001 From: rpi-simonz Date: Wed, 25 Sep 2024 11:17:03 +0200 Subject: [PATCH 03/29] smartRecycle: Keep old backups without OS release info in its name untouched --- raspiBackup.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/raspiBackup.sh b/raspiBackup.sh index cc40639e..5198ad94 100755 --- a/raspiBackup.sh +++ b/raspiBackup.sh @@ -8642,7 +8642,7 @@ function SR_listYearlyBackups() { # directory # today is 20191117 # date +%Y -d "0 year ago" -> 2019 local d=$(date +%Y -d "${i} year ago") - ls -1 $1 | egrep "\-${BACKUPTYPE}\-backup\-$d[0-9]{2}[0-9]{2}" | grep -Ev "_" | sort -ur | tail -n 1 # find earliest yearly backup + ls -1 $1 | egrep "${HOSTNAME_OSR}\-${BACKUPTYPE}\-backup\-$d[0-9]{2}[0-9]{2}" | grep -Ev "_" | sort -ur | tail -n 1 # find earliest yearly backup done fi logExit @@ -8658,7 +8658,7 @@ function SR_listMonthlyBackups() { # directory # today is 20191117 # date -d "$(date +%Y%m15) -0 month" +%Y%m -> 201911 local d=$(date -d "$(date +%Y%m15) -${i} month" +%Y%m) # get month - ls -1 $1 | egrep "\-${BACKUPTYPE}\-backup\-$d[0-9]{2}" | grep -Ev "_" | sort -ur | tail -n 1 # find earlies monthly backup + ls -1 $1 | egrep "${HOSTNAME_OSR}\-${BACKUPTYPE}\-backup\-$d[0-9]{2}" | grep -Ev "_" | sort -ur | tail -n 1 # find earlies monthly backup done fi logExit @@ -8681,7 +8681,7 @@ function SR_listWeeklyBackups() { # directory local mon=$(date +%Y%m%d -d "$last monday -${i} weeks") # calculate monday of week local dl="" for ((d=0;d<=6;d++)); do # now build list of week days of week (mon-sun) - dl="\-${BACKUPTYPE}\-backup\-$(date +%Y%m%d -d "$mon + $d day") $dl" + dl="${HOSTNAME_OSR}\-${BACKUPTYPE}\-backup\-$(date +%Y%m%d -d "$mon + $d day") $dl" done ls -1 $1 | grep -e "$(echo -n $dl | sed "s/ /\\\|/g")" | grep -Ev "_" | sort -ur | tail -n 1 # use earliest backup of this week done @@ -8697,7 +8697,7 @@ function SR_listDailyBackups() { # directory # today is 20191117 # date +%Y%m%d -d "-1 day" -> 20191116 local d=$(date +%Y%m%d -d "-${i} day") # get day - ls -1 $1 | grep "\-${BACKUPTYPE}\-backup\-$d" | grep -Ev "_" | sort -ur | head -n 1 # find most current backup of this day + ls -1 $1 | grep "${HOSTNAME_OSR}\-${BACKUPTYPE}\-backup\-$d" | grep -Ev "_" | sort -ur | head -n 1 # find most current backup of this day done fi logExit @@ -8739,7 +8739,7 @@ function SR_listUniqueBackups() { #directory function SR_listBackupsToDelete() { # directory logEntry $1 - local r="$(ls -1 $1 | grep -v -e "$(echo -n $(SR_listUniqueBackups "$1") -e "_" | sed "s/ /\\\|/g")" | grep "\-${BACKUPTYPE}\-backup\-" )" # make sure to delete only backup type files + local r="$(ls -1 $1 | grep -v -e "$(echo -n $(SR_listUniqueBackups "$1") -e "_" | sed "s/ /\\\|/g")" | grep "${HOSTNAME_OSR}\-${BACKUPTYPE}\-backup\-" )" # make sure to delete only backup type files local rc="$(countLines "$r")" logItem "$r" echo "$r" From 43516c2702c30bc9ca87bd61864afb1dc1114c0e Mon Sep 17 00:00:00 2001 From: rpi-simonz Date: Wed, 25 Sep 2024 12:56:23 +0200 Subject: [PATCH 04/29] Restore: Revert wrong modification and fix HOSTNAME detection --- raspiBackup.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/raspiBackup.sh b/raspiBackup.sh index 5198ad94..df2712bb 100755 --- a/raspiBackup.sh +++ b/raspiBackup.sh @@ -7292,8 +7292,8 @@ function findNonpartitionBackupBootAndRootpartitionFiles() { if [[ -f "$RESTOREFILE" || $BACKUPTYPE == $BACKUPTYPE_RSYNC ]]; then ROOT_RESTOREFILE="$RESTOREFILE" else - logItem "${RESTOREFILE}/${HOSTNAME_OSR}-*-backup*" - ROOT_RESTOREFILE="$(ls ${RESTOREFILE}/${HOSTNAME_OSR}-*-backup*)" + logItem "${RESTOREFILE}/${HOSTNAME}-*-backup*" + ROOT_RESTOREFILE="$(ls ${RESTOREFILE}/${HOSTNAME}-*-backup*)" logItem "ROOT_RESTOREFILE: $ROOT_RESTOREFILE" if [[ -z "$ROOT_RESTOREFILE" ]]; then writeToConsole $MSG_LEVEL_MINIMAL $MSG_NO_ROOTBACKUPFILE_FOUND $BACKUPTYPE @@ -8008,6 +8008,7 @@ function doitRestore() { logItem "Basedir: $BASE_DIR" # Note: Handle old (without) and new (with OS release info) backup directory names HOSTNAME=$(basename "$RESTOREFILE" | sed -r 's/(.*)(@[A-Za-z0-9]+)*-[A-Za-z]+-backup-[0-9]+-[0-9]+.*/\1/') + HOSTNAME=${HOSTNAME%@*} logItem "Hostname: $HOSTNAME" BACKUPTYPE=$(basename "$RESTOREFILE" | sed -r 's/.*-([A-Za-z]+)-backup-[0-9]+-[0-9]+.*/\1/') logItem "Backuptype: $BACKUPTYPE" From a2b7f40411a5a262703889a1331212f1cedb4b8c Mon Sep 17 00:00:00 2001 From: rpi-simonz Date: Wed, 25 Sep 2024 16:34:27 +0200 Subject: [PATCH 05/29] Adapt findNonpartitionBackupBootAndRootpartitionFiles() --- raspiBackup.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/raspiBackup.sh b/raspiBackup.sh index df2712bb..ddb01e0c 100755 --- a/raspiBackup.sh +++ b/raspiBackup.sh @@ -7292,8 +7292,8 @@ function findNonpartitionBackupBootAndRootpartitionFiles() { if [[ -f "$RESTOREFILE" || $BACKUPTYPE == $BACKUPTYPE_RSYNC ]]; then ROOT_RESTOREFILE="$RESTOREFILE" else - logItem "${RESTOREFILE}/${HOSTNAME}-*-backup*" - ROOT_RESTOREFILE="$(ls ${RESTOREFILE}/${HOSTNAME}-*-backup*)" + logItem "${RESTOREFILE}/${HOSTNAME}*-*-backup*" + ROOT_RESTOREFILE="$(ls ${RESTOREFILE}/${HOSTNAME}*-*-backup*)" logItem "ROOT_RESTOREFILE: $ROOT_RESTOREFILE" if [[ -z "$ROOT_RESTOREFILE" ]]; then writeToConsole $MSG_LEVEL_MINIMAL $MSG_NO_ROOTBACKUPFILE_FOUND $BACKUPTYPE From 9e3a8f42bb98202be5cdcc9d644d689dbe76e97e Mon Sep 17 00:00:00 2001 From: rpi-simonz Date: Tue, 1 Oct 2024 12:49:24 +0200 Subject: [PATCH 06/29] Recycle: (Re-)Include old backups without OS release info into strategy --- raspiBackup.sh | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/raspiBackup.sh b/raspiBackup.sh index 26427759..09b5028c 100755 --- a/raspiBackup.sh +++ b/raspiBackup.sh @@ -5593,6 +5593,8 @@ function updateUUID() { function backupRsync() { # partition number (for partition based backup) + # Note: Determining lastbackupDir now depends even more on the naming convention of the backups. See the "sort -t '-' -k 4" commands below! + local verbose partition target source excludeRoot cmd cmdParms excludeMeta logEntry @@ -5609,7 +5611,7 @@ function backupRsync() { # partition number (for partition based backup) target="\"${BACKUPTARGET_DIR}\"" source="$TEMPORARY_MOUNTPOINT_ROOT/$partition" - lastBackupDir=$(find "$BACKUPTARGET_ROOT" -maxdepth 1 -type d -name "*-$BACKUPTYPE-*" ! -name $BACKUPFILE 2>>/dev/null | sort | tail -n 1) + lastBackupDir=$(find "$BACKUPTARGET_ROOT" -maxdepth 1 -type d -name "*-$BACKUPTYPE-*" ! -name $BACKUPFILE 2>>/dev/null | sort -t "-" -k 4 | tail -n 1) excludeRoot="/$partition" else @@ -5617,7 +5619,7 @@ function backupRsync() { # partition number (for partition based backup) source="/" bootPartitionBackup - lastBackupDir=$(find "$BACKUPTARGET_ROOT" -maxdepth 1 -type d -name "${HOSTNAME_OSR}*-$BACKUPTYPE-*" ! -name $BACKUPFILE 2>>/dev/null | sort | tail -n 1) + lastBackupDir=$(find "$BACKUPTARGET_ROOT" -maxdepth 1 -type d -name "*-$BACKUPTYPE-*" ! -name $BACKUPFILE 2>>/dev/null | sort -t "-" -k 4 | tail -n 1) excludeRoot="" excludeMeta="--exclude=/$BACKUPFILES_PARTITION_DATE.img --exclude=/$BACKUPFILES_PARTITION_DATE.tmg --exclude=/$BACKUPFILES_PARTITION_DATE.sfdisk --exclude=/$BACKUPFILES_PARTITION_DATE.blkid --exclude=/$BACKUPFILES_PARTITION_DATE.fdisk --exclude=/$BACKUPFILES_PARTITION_DATE.parted --exclude=/$BACKUPFILES_PARTITION_DATE.mbr --exclude=/$MYNAME.log --exclude=/$MYNAME.msg" fi @@ -6076,6 +6078,8 @@ function restore() { function applyBackupStrategy() { + # Note: Determining the backups to be deleted now depends even more on the naming convention of the backups. See the "sort -t '-' -k 4" commands below! + logEntry "$BACKUP_TARGETDIR" if (( $SMART_RECYCLE )); then @@ -6092,11 +6096,11 @@ function applyBackupStrategy() { logCommand "ls -d $BACKUPPATH/*" - local keptBackups="$(SR_listUniqueBackups $BACKUPTARGET_ROOT)" + local keptBackups="$(SR_listUniqueBackups $BACKUPTARGET_ROOT | sort -t '-' -k 4)" local numKeptBackups="$(countLines "$keptBackups")" logItem "Keptbackups $numKeptBackups: $keptBackups" - local tobeDeletedBackups="$(SR_listBackupsToDelete "$BACKUPTARGET_ROOT")" + local tobeDeletedBackups="$(SR_listBackupsToDelete "$BACKUPTARGET_ROOT" | sort -t '-' -k 4)" local numTobeDeletedBackups="$(countLines "$tobeDeletedBackups")" logItem "TobeDeletedBackups $numTobeDeletedBackups: $tobeDeletedBackups" @@ -6141,7 +6145,7 @@ function applyBackupStrategy() { if ! pushd "$BACKUPPATH" &>>$LOG_FILE; then assertionFailed $LINENO "push to $BACKUPPATH failed" fi - ls -d ${HOSTNAME_OSR}-${BACKUPTYPE}-backup-* 2>>$LOG_FILE| grep -vE "_" | head -n -$keepBackups | xargs -I {} rm -rf "{}" &>>"$LOG_FILE"; + ls -d ${HOSTNAME}*-${BACKUPTYPE}-backup-* 2>>$LOG_FILE| grep -vE "_" | sort -t "-" -k 4 | head -n -$keepBackups | xargs -I {} rm -rf "{}" &>>"$LOG_FILE"; if ! popd &>>$LOG_FILE; then assertionFailed $LINENO "pop failed" fi @@ -8643,7 +8647,7 @@ function SR_listYearlyBackups() { # directory # today is 20191117 # date +%Y -d "0 year ago" -> 2019 local d=$(date +%Y -d "${i} year ago") - ls -1 $1 | egrep "${HOSTNAME_OSR}\-${BACKUPTYPE}\-backup\-$d[0-9]{2}[0-9]{2}" | grep -Ev "_" | sort -ur | tail -n 1 # find earliest yearly backup + ls -1 $1 | egrep "\-${BACKUPTYPE}\-backup\-$d[0-9]{2}[0-9]{2}" | grep -Ev "_" | sort -ur -t "-" -k 4 | tail -n 1 # find earliest yearly backup done fi logExit @@ -8659,7 +8663,7 @@ function SR_listMonthlyBackups() { # directory # today is 20191117 # date -d "$(date +%Y%m15) -0 month" +%Y%m -> 201911 local d=$(date -d "$(date +%Y%m15) -${i} month" +%Y%m) # get month - ls -1 $1 | egrep "${HOSTNAME_OSR}\-${BACKUPTYPE}\-backup\-$d[0-9]{2}" | grep -Ev "_" | sort -ur | tail -n 1 # find earlies monthly backup + ls -1 $1 | egrep "\-${BACKUPTYPE}\-backup\-$d[0-9]{2}" | grep -Ev "_" | sort -ur -t "-" -k 4 | tail -n 1 # find earliest monthly backup done fi logExit @@ -8682,9 +8686,9 @@ function SR_listWeeklyBackups() { # directory local mon=$(date +%Y%m%d -d "$last monday -${i} weeks") # calculate monday of week local dl="" for ((d=0;d<=6;d++)); do # now build list of week days of week (mon-sun) - dl="${HOSTNAME_OSR}\-${BACKUPTYPE}\-backup\-$(date +%Y%m%d -d "$mon + $d day") $dl" + dl="\-${BACKUPTYPE}\-backup\-$(date +%Y%m%d -d "$mon + $d day") $dl" done - ls -1 $1 | grep -e "$(echo -n $dl | sed "s/ /\\\|/g")" | grep -Ev "_" | sort -ur | tail -n 1 # use earliest backup of this week + ls -1 $1 | grep -e "$(echo -n $dl | sed "s/ /\\\|/g")" | grep -Ev "_" | sort -ur -t "-" -k 4 | tail -n 1 # use earliest backup of this week done fi logExit @@ -8698,7 +8702,7 @@ function SR_listDailyBackups() { # directory # today is 20191117 # date +%Y%m%d -d "-1 day" -> 20191116 local d=$(date +%Y%m%d -d "-${i} day") # get day - ls -1 $1 | grep "${HOSTNAME_OSR}\-${BACKUPTYPE}\-backup\-$d" | grep -Ev "_" | sort -ur | head -n 1 # find most current backup of this day + ls -1 $1 | grep "\-${BACKUPTYPE}\-backup\-$d" | grep -Ev "_" | sort -ur -t "-" -k 4 | head -n 1 # find most current backup of this day done fi logExit @@ -8740,7 +8744,7 @@ function SR_listUniqueBackups() { #directory function SR_listBackupsToDelete() { # directory logEntry $1 - local r="$(ls -1 $1 | grep -v -e "$(echo -n $(SR_listUniqueBackups "$1") -e "_" | sed "s/ /\\\|/g")" | grep "${HOSTNAME_OSR}\-${BACKUPTYPE}\-backup\-" )" # make sure to delete only backup type files + local r="$(ls -1 $1 | grep -v -e "$(echo -n $(SR_listUniqueBackups "$1") -e "_" | sed "s/ /\\\|/g")" | grep "\-${BACKUPTYPE}\-backup\-" )" # make sure to delete only backup type files local rc="$(countLines "$r")" logItem "$r" echo "$r" From 3a12b4d4595b32b624a1d918327aec4c6961fab4 Mon Sep 17 00:00:00 2001 From: rpi-simonz Date: Tue, 1 Oct 2024 12:55:26 +0200 Subject: [PATCH 07/29] Fake mode in normal backup type: Add info about backup recycling(deletion) --- raspiBackup.sh | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/raspiBackup.sh b/raspiBackup.sh index 09b5028c..9a03b00f 100755 --- a/raspiBackup.sh +++ b/raspiBackup.sh @@ -6130,6 +6130,8 @@ function applyBackupStrategy() { local bt="${BACKUPTYPE^^}" local v="KEEPBACKUPS_${bt}" local keepOverwrite="${!v}" + local dir_to_delete + local tobeDeletedBackups local keepBackups=$KEEPBACKUPS (( $keepOverwrite != 0 )) && keepBackups=$keepOverwrite @@ -6140,7 +6142,19 @@ function applyBackupStrategy() { writeToConsole $MSG_LEVEL_MINIMAL $MSG_BACKUPS_KEPT "$keepBackups" "$BACKUPTYPE" - if (( ! $FAKE )); then + if (( $FAKE )); then + writeToConsole $MSG_LEVEL_DETAILED $MSG_CLEANUP_BACKUP_VERSION "$BACKUPPATH" + if ! pushd "$BACKUPPATH" &>>$LOG_FILE; then + assertionFailed $LINENO "push to $BACKUPPATH failed" + fi + tobeDeletedBackups=$(ls -d ${HOSTNAME}*-${BACKUPTYPE}-backup-* 2>>$LOG_FILE| grep -vE "_" | sort -t "-" -k 4 | head -n -$keepBackups 2>>$LOG_FILE) + echo "$tobeDeletedBackups" | while read dir_to_delete; do + [[ -n $dir_to_delete ]] && writeToConsole $MSG_LEVEL_MINIMAL $MSG_SMART_RECYCLE_FILE_WOULD_BE_DELETED "$BACKUPTARGET_ROOT/${dir_to_delete}" + done + if ! popd &>>$LOG_FILE; then + assertionFailed $LINENO "pop failed" + fi + else writeToConsole $MSG_LEVEL_DETAILED $MSG_CLEANUP_BACKUP_VERSION "$BACKUPPATH" if ! pushd "$BACKUPPATH" &>>$LOG_FILE; then assertionFailed $LINENO "push to $BACKUPPATH failed" From 858fd9fae71eb7a4089b262317aad356a9f24af2 Mon Sep 17 00:00:00 2001 From: rpi-simonz Date: Thu, 3 Oct 2024 13:53:32 +0200 Subject: [PATCH 08/29] Mostly revert to version 1 and let old backups untouched. A user message will follow soon. Improve getOSRelease to make it more robust. --- raspiBackup.sh | 66 +++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 36 deletions(-) diff --git a/raspiBackup.sh b/raspiBackup.sh index 9a03b00f..062d55a4 100755 --- a/raspiBackup.sh +++ b/raspiBackup.sh @@ -3870,11 +3870,19 @@ function readConfigParameters() { logExit } -function setupOsRelease() { +function getOSRelease() { - # TODO: Need to make this more foolproof?? Probably not. - test -e /etc/os-release && os_release='/etc/os-release' || os_release='/usr/lib/os-release' - . "${os_release}" + test -e /etc/os-release && os_release_file='/etc/os-release' || test -e /usr/lib/os-release && os_release_file='/usr/lib/os-release' || os_release_file='/dev/null' + + # the prefix "osr_" prevents a lonely "local" with its output below when grep is unsuccessful + unset osr_ID osr_VERSION_ID # unset possible values used from global scope then + + local osr_$(grep -E "^ID=" "$os_release_file") + local osr_$(grep -E "^VERSION_ID=" "$os_release_file") + + os_release="${osr_ID}${osr_VERSION_ID}" # e.g. debian12 or even debian"12" + os_release="${os_release//\"/}" # remove any double quotes + echo "${os_release:-unknown}" # handle empty result } function setupEnvironment() { @@ -3898,8 +3906,12 @@ function setupEnvironment() { BACKUPFILES_PARTITION_DATE="$HOSTNAME-backup" # For including the OS release into the name of the backup directory - setupOsRelease - HOSTNAME_OSR="${HOSTNAME}@${ID}${VERSION_ID}" + os_release=$(getOSRelease) + # Note: Sanitize the os_release to be usable as (part of) directory name. + # But don't allow or use "-" or "_" as replacement character! + # Both characters are already used as dividers/markers later on! + # The "~" seems to be okay. Even safer would be "", a.k.a. nothing. + HOSTNAME_OSR="${HOSTNAME}@${os_release//[ \/\\\:\.\-_]/\~}" if [[ -z "$BACKUP_DIRECTORY_NAME" ]]; then BACKUPFILE="${HOSTNAME_OSR}-${BACKUPTYPE}-backup-$DATE" @@ -5593,8 +5605,6 @@ function updateUUID() { function backupRsync() { # partition number (for partition based backup) - # Note: Determining lastbackupDir now depends even more on the naming convention of the backups. See the "sort -t '-' -k 4" commands below! - local verbose partition target source excludeRoot cmd cmdParms excludeMeta logEntry @@ -5611,7 +5621,7 @@ function backupRsync() { # partition number (for partition based backup) target="\"${BACKUPTARGET_DIR}\"" source="$TEMPORARY_MOUNTPOINT_ROOT/$partition" - lastBackupDir=$(find "$BACKUPTARGET_ROOT" -maxdepth 1 -type d -name "*-$BACKUPTYPE-*" ! -name $BACKUPFILE 2>>/dev/null | sort -t "-" -k 4 | tail -n 1) + lastBackupDir=$(find "$BACKUPTARGET_ROOT" -maxdepth 1 -type d -name "*-$BACKUPTYPE-*" ! -name $BACKUPFILE 2>>/dev/null | sort | tail -n 1) excludeRoot="/$partition" else @@ -5619,7 +5629,7 @@ function backupRsync() { # partition number (for partition based backup) source="/" bootPartitionBackup - lastBackupDir=$(find "$BACKUPTARGET_ROOT" -maxdepth 1 -type d -name "*-$BACKUPTYPE-*" ! -name $BACKUPFILE 2>>/dev/null | sort -t "-" -k 4 | tail -n 1) + lastBackupDir=$(find "$BACKUPTARGET_ROOT" -maxdepth 1 -type d -name "${HOSTNAME_OSR}*-$BACKUPTYPE-*" ! -name $BACKUPFILE 2>>/dev/null | sort | tail -n 1) excludeRoot="" excludeMeta="--exclude=/$BACKUPFILES_PARTITION_DATE.img --exclude=/$BACKUPFILES_PARTITION_DATE.tmg --exclude=/$BACKUPFILES_PARTITION_DATE.sfdisk --exclude=/$BACKUPFILES_PARTITION_DATE.blkid --exclude=/$BACKUPFILES_PARTITION_DATE.fdisk --exclude=/$BACKUPFILES_PARTITION_DATE.parted --exclude=/$BACKUPFILES_PARTITION_DATE.mbr --exclude=/$MYNAME.log --exclude=/$MYNAME.msg" fi @@ -6078,8 +6088,6 @@ function restore() { function applyBackupStrategy() { - # Note: Determining the backups to be deleted now depends even more on the naming convention of the backups. See the "sort -t '-' -k 4" commands below! - logEntry "$BACKUP_TARGETDIR" if (( $SMART_RECYCLE )); then @@ -6096,11 +6104,11 @@ function applyBackupStrategy() { logCommand "ls -d $BACKUPPATH/*" - local keptBackups="$(SR_listUniqueBackups $BACKUPTARGET_ROOT | sort -t '-' -k 4)" + local keptBackups="$(SR_listUniqueBackups $BACKUPTARGET_ROOT)" local numKeptBackups="$(countLines "$keptBackups")" logItem "Keptbackups $numKeptBackups: $keptBackups" - local tobeDeletedBackups="$(SR_listBackupsToDelete "$BACKUPTARGET_ROOT" | sort -t '-' -k 4)" + local tobeDeletedBackups="$(SR_listBackupsToDelete "$BACKUPTARGET_ROOT")" local numTobeDeletedBackups="$(countLines "$tobeDeletedBackups")" logItem "TobeDeletedBackups $numTobeDeletedBackups: $tobeDeletedBackups" @@ -6130,8 +6138,6 @@ function applyBackupStrategy() { local bt="${BACKUPTYPE^^}" local v="KEEPBACKUPS_${bt}" local keepOverwrite="${!v}" - local dir_to_delete - local tobeDeletedBackups local keepBackups=$KEEPBACKUPS (( $keepOverwrite != 0 )) && keepBackups=$keepOverwrite @@ -6142,24 +6148,12 @@ function applyBackupStrategy() { writeToConsole $MSG_LEVEL_MINIMAL $MSG_BACKUPS_KEPT "$keepBackups" "$BACKUPTYPE" - if (( $FAKE )); then - writeToConsole $MSG_LEVEL_DETAILED $MSG_CLEANUP_BACKUP_VERSION "$BACKUPPATH" - if ! pushd "$BACKUPPATH" &>>$LOG_FILE; then - assertionFailed $LINENO "push to $BACKUPPATH failed" - fi - tobeDeletedBackups=$(ls -d ${HOSTNAME}*-${BACKUPTYPE}-backup-* 2>>$LOG_FILE| grep -vE "_" | sort -t "-" -k 4 | head -n -$keepBackups 2>>$LOG_FILE) - echo "$tobeDeletedBackups" | while read dir_to_delete; do - [[ -n $dir_to_delete ]] && writeToConsole $MSG_LEVEL_MINIMAL $MSG_SMART_RECYCLE_FILE_WOULD_BE_DELETED "$BACKUPTARGET_ROOT/${dir_to_delete}" - done - if ! popd &>>$LOG_FILE; then - assertionFailed $LINENO "pop failed" - fi - else + if (( ! $FAKE )); then writeToConsole $MSG_LEVEL_DETAILED $MSG_CLEANUP_BACKUP_VERSION "$BACKUPPATH" if ! pushd "$BACKUPPATH" &>>$LOG_FILE; then assertionFailed $LINENO "push to $BACKUPPATH failed" fi - ls -d ${HOSTNAME}*-${BACKUPTYPE}-backup-* 2>>$LOG_FILE| grep -vE "_" | sort -t "-" -k 4 | head -n -$keepBackups | xargs -I {} rm -rf "{}" &>>"$LOG_FILE"; + ls -d ${HOSTNAME_OSR}-${BACKUPTYPE}-backup-* 2>>$LOG_FILE| grep -vE "_" | head -n -$keepBackups | xargs -I {} rm -rf "{}" &>>"$LOG_FILE"; if ! popd &>>$LOG_FILE; then assertionFailed $LINENO "pop failed" fi @@ -8661,7 +8655,7 @@ function SR_listYearlyBackups() { # directory # today is 20191117 # date +%Y -d "0 year ago" -> 2019 local d=$(date +%Y -d "${i} year ago") - ls -1 $1 | egrep "\-${BACKUPTYPE}\-backup\-$d[0-9]{2}[0-9]{2}" | grep -Ev "_" | sort -ur -t "-" -k 4 | tail -n 1 # find earliest yearly backup + ls -1 $1 | egrep "${HOSTNAME_OSR}\-${BACKUPTYPE}\-backup\-$d[0-9]{2}[0-9]{2}" | grep -Ev "_" | sort -ur | tail -n 1 # find earliest yearly backup done fi logExit @@ -8677,7 +8671,7 @@ function SR_listMonthlyBackups() { # directory # today is 20191117 # date -d "$(date +%Y%m15) -0 month" +%Y%m -> 201911 local d=$(date -d "$(date +%Y%m15) -${i} month" +%Y%m) # get month - ls -1 $1 | egrep "\-${BACKUPTYPE}\-backup\-$d[0-9]{2}" | grep -Ev "_" | sort -ur -t "-" -k 4 | tail -n 1 # find earliest monthly backup + ls -1 $1 | egrep "${HOSTNAME_OSR}\-${BACKUPTYPE}\-backup\-$d[0-9]{2}" | grep -Ev "_" | sort -ur | tail -n 1 # find earlies monthly backup done fi logExit @@ -8700,9 +8694,9 @@ function SR_listWeeklyBackups() { # directory local mon=$(date +%Y%m%d -d "$last monday -${i} weeks") # calculate monday of week local dl="" for ((d=0;d<=6;d++)); do # now build list of week days of week (mon-sun) - dl="\-${BACKUPTYPE}\-backup\-$(date +%Y%m%d -d "$mon + $d day") $dl" + dl="${HOSTNAME_OSR}\-${BACKUPTYPE}\-backup\-$(date +%Y%m%d -d "$mon + $d day") $dl" done - ls -1 $1 | grep -e "$(echo -n $dl | sed "s/ /\\\|/g")" | grep -Ev "_" | sort -ur -t "-" -k 4 | tail -n 1 # use earliest backup of this week + ls -1 $1 | grep -e "$(echo -n $dl | sed "s/ /\\\|/g")" | grep -Ev "_" | sort -ur | tail -n 1 # use earliest backup of this week done fi logExit @@ -8716,7 +8710,7 @@ function SR_listDailyBackups() { # directory # today is 20191117 # date +%Y%m%d -d "-1 day" -> 20191116 local d=$(date +%Y%m%d -d "-${i} day") # get day - ls -1 $1 | grep "\-${BACKUPTYPE}\-backup\-$d" | grep -Ev "_" | sort -ur -t "-" -k 4 | head -n 1 # find most current backup of this day + ls -1 $1 | grep "${HOSTNAME_OSR}\-${BACKUPTYPE}\-backup\-$d" | grep -Ev "_" | sort -ur | head -n 1 # find most current backup of this day done fi logExit @@ -8758,7 +8752,7 @@ function SR_listUniqueBackups() { #directory function SR_listBackupsToDelete() { # directory logEntry $1 - local r="$(ls -1 $1 | grep -v -e "$(echo -n $(SR_listUniqueBackups "$1") -e "_" | sed "s/ /\\\|/g")" | grep "\-${BACKUPTYPE}\-backup\-" )" # make sure to delete only backup type files + local r="$(ls -1 $1 | grep -v -e "$(echo -n $(SR_listUniqueBackups "$1") -e "_" | sed "s/ /\\\|/g")" | grep "${HOSTNAME_OSR}\-${BACKUPTYPE}\-backup\-" )" # make sure to delete only backup type files local rc="$(countLines "$r")" logItem "$r" echo "$r" From 6366648c9327831396d4a6509a5d4fcb58204eb5 Mon Sep 17 00:00:00 2001 From: rpi-simonz Date: Thu, 3 Oct 2024 14:56:07 +0200 Subject: [PATCH 09/29] Fake mode in normal backup type: Add info about backup recycling(deletion), fixed --- raspiBackup.sh | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/raspiBackup.sh b/raspiBackup.sh index 062d55a4..61d492ad 100755 --- a/raspiBackup.sh +++ b/raspiBackup.sh @@ -6138,7 +6138,10 @@ function applyBackupStrategy() { local bt="${BACKUPTYPE^^}" local v="KEEPBACKUPS_${bt}" local keepOverwrite="${!v}" - + local dir_to_delete + local dir_to_check + local tobeDeletedBackups + local tobeCheckedBackups local keepBackups=$KEEPBACKUPS (( $keepOverwrite != 0 )) && keepBackups=$keepOverwrite @@ -6148,7 +6151,25 @@ function applyBackupStrategy() { writeToConsole $MSG_LEVEL_MINIMAL $MSG_BACKUPS_KEPT "$keepBackups" "$BACKUPTYPE" - if (( ! $FAKE )); then + if (( $FAKE )); then + fakeKeepBackups=$(( keepBackups - 1 )) # because in FAKE mode no real current backup has been created + writeToConsole $MSG_LEVEL_DETAILED $MSG_CLEANUP_BACKUP_VERSION "$BACKUPPATH" + if ! pushd "$BACKUPPATH" &>>$LOG_FILE; then + assertionFailed $LINENO "push to $BACKUPPATH failed" + fi + local dir_to_check + local tobeCheckedBackups=$(ls -d ${HOSTNAME_OSR}-${BACKUPTYPE}-backup-* 2>>$LOG_FILE| grep -vE "_") + echo "$tobeCheckedBackups" | while read dir_to_check; do + [[ -n $dir_to_check ]] && echo "!!! Matching backup found: $BACKUPTARGET_ROOT/${dir_to_check}" + done + tobeDeletedBackups=$(ls -d ${HOSTNAME_OSR}-${BACKUPTYPE}-backup-* 2>>$LOG_FILE| grep -vE "_" | head -n -$fakeKeepBackups 2>>$LOG_FILE) + echo "$tobeDeletedBackups" | while read dir_to_delete; do + [[ -n $dir_to_delete ]] && writeToConsole $MSG_LEVEL_MINIMAL $MSG_SMART_RECYCLE_FILE_WOULD_BE_DELETED "$BACKUPTARGET_ROOT/${dir_to_delete}" + done + if ! popd &>>$LOG_FILE; then + assertionFailed $LINENO "pop failed" + fi + else writeToConsole $MSG_LEVEL_DETAILED $MSG_CLEANUP_BACKUP_VERSION "$BACKUPPATH" if ! pushd "$BACKUPPATH" &>>$LOG_FILE; then assertionFailed $LINENO "push to $BACKUPPATH failed" From 0ec598b11a87b5bb5a39d5404e75f81fc65c3d08 Mon Sep 17 00:00:00 2001 From: rpi-simonz Date: Thu, 3 Oct 2024 18:28:20 +0200 Subject: [PATCH 10/29] Remove doubled local definition --- raspiBackup.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/raspiBackup.sh b/raspiBackup.sh index 61d492ad..9fc046e9 100755 --- a/raspiBackup.sh +++ b/raspiBackup.sh @@ -6157,8 +6157,7 @@ function applyBackupStrategy() { if ! pushd "$BACKUPPATH" &>>$LOG_FILE; then assertionFailed $LINENO "push to $BACKUPPATH failed" fi - local dir_to_check - local tobeCheckedBackups=$(ls -d ${HOSTNAME_OSR}-${BACKUPTYPE}-backup-* 2>>$LOG_FILE| grep -vE "_") + tobeCheckedBackups=$(ls -d ${HOSTNAME_OSR}-${BACKUPTYPE}-backup-* 2>>$LOG_FILE| grep -vE "_") echo "$tobeCheckedBackups" | while read dir_to_check; do [[ -n $dir_to_check ]] && echo "!!! Matching backup found: $BACKUPTARGET_ROOT/${dir_to_check}" done From c1ad1bc263d2bfd01020022dbf40a60e9f29a7d5 Mon Sep 17 00:00:00 2001 From: rpi-simonz Date: Thu, 3 Oct 2024 18:49:56 +0200 Subject: [PATCH 11/29] First version of reportOldBacks() --- raspiBackup.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/raspiBackup.sh b/raspiBackup.sh index 9fc046e9..c2cbff1d 100755 --- a/raspiBackup.sh +++ b/raspiBackup.sh @@ -4812,6 +4812,7 @@ function cleanup() { # trap || ! $SMART_RECYCLE \ )); then applyBackupStrategy + reportOldBackups fi fi fi @@ -6232,6 +6233,33 @@ function applyBackupStrategy() { logExit } +function reportOldBackups() { + + logEntry "$BACKUP_TARGETDIR" + + local dir_to_list + local tobeListedBackups + + logItem "Deleting oldest directory in $BACKUPPATH" + logCommand "ls -d $BACKUPPATH/*" + + writeToConsole $MSG_LEVEL_MINIMAL $MSG_BACKUPS_KEPT "$keepBackups" "$BACKUPTYPE" + + if ! pushd "$BACKUPPATH" &>>$LOG_FILE; then + assertionFailed $LINENO "push to $BACKUPPATH failed" + fi + tobeListedBackups=$(ls -d ${HOSTNAME}-${BACKUPTYPE}-backup-* 2>>$LOG_FILE| grep -vE "_") + echo "$tobeListedBackups" | while read dir_to_list; do + [[ -n $dir_to_list ]] && echo "!!! Old-type backup found: $BACKUPTARGET_ROOT/${dir_to_list}" + done + if [[ -n "$tobeListedBackups" ]] ; then + echo "!!! Above listed old-type backups might be deleted manually when there are enough new-type ones." + fi + if ! popd &>>$LOG_FILE; then + assertionFailed $LINENO "pop failed" + fi +} + function backup() { logEntry From 6ed21dae78fc6a93d9103269a26f1987475d2a60 Mon Sep 17 00:00:00 2001 From: rpi-simonz Date: Thu, 3 Oct 2024 20:18:59 +0200 Subject: [PATCH 12/29] Change check for file os-release --- raspiBackup.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/raspiBackup.sh b/raspiBackup.sh index c2cbff1d..d7f03acb 100755 --- a/raspiBackup.sh +++ b/raspiBackup.sh @@ -3872,7 +3872,13 @@ function readConfigParameters() { function getOSRelease() { - test -e /etc/os-release && os_release_file='/etc/os-release' || test -e /usr/lib/os-release && os_release_file='/usr/lib/os-release' || os_release_file='/dev/null' + local os_release_file='/dev/null' # fallback + for file in /etc/os-release /usr/lib/os-release; do + if [[ -e $file ]]; then + os_release_file="$file" + break + fi + done # the prefix "osr_" prevents a lonely "local" with its output below when grep is unsuccessful unset osr_ID osr_VERSION_ID # unset possible values used from global scope then @@ -3882,7 +3888,7 @@ function getOSRelease() { os_release="${osr_ID}${osr_VERSION_ID}" # e.g. debian12 or even debian"12" os_release="${os_release//\"/}" # remove any double quotes - echo "${os_release:-unknown}" # handle empty result + echo "${os_release:-unknownOS}" # handle empty result } function setupEnvironment() { From 96d83cfcd3fba44badd335c4d4aaff37a0bb7e16 Mon Sep 17 00:00:00 2001 From: rpi-simonz Date: Thu, 3 Oct 2024 21:36:14 +0200 Subject: [PATCH 13/29] Cleanup and improve reportOldBackups. Still not finished... --- raspiBackup.sh | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/raspiBackup.sh b/raspiBackup.sh index d7f03acb..d4cdd113 100755 --- a/raspiBackup.sh +++ b/raspiBackup.sh @@ -6244,22 +6244,45 @@ function reportOldBackups() { logEntry "$BACKUP_TARGETDIR" local dir_to_list - local tobeListedBackups + local tobeListedNewBackups + local numListedNewBackups + local numListedOldBackups - logItem "Deleting oldest directory in $BACKUPPATH" - logCommand "ls -d $BACKUPPATH/*" + if (( $SMART_RECYCLE )); then + + local keptBackups="$(SR_listUniqueBackups $BACKUPTARGET_ROOT)" + local numKeptBackups="$(countLines "$keptBackups")" + logItem "Keptbackups $numKeptBackups: $keptBackups" - writeToConsole $MSG_LEVEL_MINIMAL $MSG_BACKUPS_KEPT "$keepBackups" "$BACKUPTYPE" + else + + local bt="${BACKUPTYPE^^}" + local v="KEEPBACKUPS_${bt}" + local keepOverwrite="${!v}" + local keepBackups=$KEEPBACKUPS + (( $keepOverwrite != 0 )) && keepBackups=$keepOverwrite + fi if ! pushd "$BACKUPPATH" &>>$LOG_FILE; then assertionFailed $LINENO "push to $BACKUPPATH failed" fi - tobeListedBackups=$(ls -d ${HOSTNAME}-${BACKUPTYPE}-backup-* 2>>$LOG_FILE| grep -vE "_") - echo "$tobeListedBackups" | while read dir_to_list; do + + tobeListedNewBackups=$(ls -d ${HOSTNAME_OSR}-${BACKUPTYPE}-backup-* 2>>$LOG_FILE| grep -vE "_") + numListedNewBackups="$(countLines "$tobeListedNewBackups")" + + tobeListedOldBackups=$(ls -d ${HOSTNAME}-${BACKUPTYPE}-backup-* 2>>$LOG_FILE| grep -vE "_") + + echo "$tobeListedOldBackups" | while read dir_to_list; do [[ -n $dir_to_list ]] && echo "!!! Old-type backup found: $BACKUPTARGET_ROOT/${dir_to_list}" done - if [[ -n "$tobeListedBackups" ]] ; then + if [[ -n "$tobeListedOldBackups" ]] ; then echo "!!! Above listed old-type backups might be deleted manually when there are enough new-type ones." + echo -e "!!! That means: if numListedNewBackups ($numListedNewBackups) >= \c" + if (( $SMART_RECYCLE )); then + echo "numKeptBackups ($numKeptBackups)" + else + echo "keepBackups ($keepBackups)" + fi fi if ! popd &>>$LOG_FILE; then assertionFailed $LINENO "pop failed" From 2a42e8f4503703675ef444b17324d0b995477617 Mon Sep 17 00:00:00 2001 From: rpi-simonz Date: Fri, 4 Oct 2024 10:22:55 +0200 Subject: [PATCH 14/29] Cleanup and change getOSRelease a bit --- raspiBackup.sh | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/raspiBackup.sh b/raspiBackup.sh index d4cdd113..cf9a1c08 100755 --- a/raspiBackup.sh +++ b/raspiBackup.sh @@ -3872,23 +3872,22 @@ function readConfigParameters() { function getOSRelease() { - local os_release_file='/dev/null' # fallback - for file in /etc/os-release /usr/lib/os-release; do - if [[ -e $file ]]; then - os_release_file="$file" - break - fi + local os_release_file + local os_release + + for os_release_file in /etc/os-release /usr/lib/os-release /dev/null ; do + [[ -e "$os_release_file" ]] && break done - # the prefix "osr_" prevents a lonely "local" with its output below when grep is unsuccessful - unset osr_ID osr_VERSION_ID # unset possible values used from global scope then + # the prefix "osr_" prevents a lonely "local" with its output below when grep is unsuccessful + unset osr_ID osr_VERSION_ID # unset possible values used from global scope then - local osr_$(grep -E "^ID=" "$os_release_file") - local osr_$(grep -E "^VERSION_ID=" "$os_release_file") + local osr_$(grep -E "^ID=" "$os_release_file") + local osr_$(grep -E "^VERSION_ID=" "$os_release_file") - os_release="${osr_ID}${osr_VERSION_ID}" # e.g. debian12 or even debian"12" - os_release="${os_release//\"/}" # remove any double quotes - echo "${os_release:-unknownOS}" # handle empty result + os_release="${osr_ID}${osr_VERSION_ID}" # e.g. debian12 or even debian"12" + os_release="${os_release//\"/}" # remove any double quotes + echo "${os_release:-unknownOS}" # handle empty result } function setupEnvironment() { From 9dd0b26825e308bb497fdffb03f473a68e19e5e3 Mon Sep 17 00:00:00 2001 From: rpi-simonz Date: Fri, 4 Oct 2024 21:37:27 +0200 Subject: [PATCH 15/29] Fix call location for reportOldBackups --- raspiBackup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/raspiBackup.sh b/raspiBackup.sh index cf9a1c08..817dd9c0 100755 --- a/raspiBackup.sh +++ b/raspiBackup.sh @@ -4817,12 +4817,12 @@ function cleanup() { # trap || ! $SMART_RECYCLE \ )); then applyBackupStrategy - reportOldBackups fi fi fi cleanupTempFiles + reportOldBackups finalCommand "$rc" From cc064f20af893b1df4b5e2555d0fd4cd04ef578f Mon Sep 17 00:00:00 2001 From: rpi-simonz Date: Sat, 5 Oct 2024 10:22:01 +0200 Subject: [PATCH 16/29] Improve message text in reportOldBackups --- raspiBackup.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/raspiBackup.sh b/raspiBackup.sh index 817dd9c0..9d3f7289 100755 --- a/raspiBackup.sh +++ b/raspiBackup.sh @@ -6276,12 +6276,11 @@ function reportOldBackups() { done if [[ -n "$tobeListedOldBackups" ]] ; then echo "!!! Above listed old-type backups might be deleted manually when there are enough new-type ones." - echo -e "!!! That means: if numListedNewBackups ($numListedNewBackups) >= \c" + echo -e "!!! \"Enough\" means: if numListedNewBackups ($numListedNewBackups) \c" if (( $SMART_RECYCLE )); then - echo "numKeptBackups ($numKeptBackups)" - else - echo "keepBackups ($keepBackups)" + echo -e " or numKeptBackups ($numKeptBackups) \c" fi + echo " has reached keepBackups (${keepBackups:-$DEFAULT_KEEPBACKUPS})" fi if ! popd &>>$LOG_FILE; then assertionFailed $LINENO "pop failed" From 678a2753ebd4083c2c9c1b093578e95277d16276 Mon Sep 17 00:00:00 2001 From: rpi-simonz Date: Sat, 5 Oct 2024 17:52:31 +0200 Subject: [PATCH 17/29] Only show message if there are old-type backups existing --- raspiBackup.sh | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/raspiBackup.sh b/raspiBackup.sh index 9d3f7289..ce2f77dc 100755 --- a/raspiBackup.sh +++ b/raspiBackup.sh @@ -6271,17 +6271,19 @@ function reportOldBackups() { tobeListedOldBackups=$(ls -d ${HOSTNAME}-${BACKUPTYPE}-backup-* 2>>$LOG_FILE| grep -vE "_") - echo "$tobeListedOldBackups" | while read dir_to_list; do - [[ -n $dir_to_list ]] && echo "!!! Old-type backup found: $BACKUPTARGET_ROOT/${dir_to_list}" - done - if [[ -n "$tobeListedOldBackups" ]] ; then - echo "!!! Above listed old-type backups might be deleted manually when there are enough new-type ones." + if [[ -n $tobeListedOldBackups ]] ; then + echo "!!! **********************************************************************" + echo "!!! Old-type backups found:" + echo "$tobeListedOldBackups" | while read dir_to_list; do + [[ -n $dir_to_list ]] && echo "!!! - $BACKUPTARGET_ROOT/${dir_to_list}" + done + echo "!!! These old-type backups might be deleted manually when there are enough new-type ones." echo -e "!!! \"Enough\" means: if numListedNewBackups ($numListedNewBackups) \c" - if (( $SMART_RECYCLE )); then - echo -e " or numKeptBackups ($numKeptBackups) \c" - fi + (( $SMART_RECYCLE )) && echo -e " or numKeptBackups ($numKeptBackups) \c" echo " has reached keepBackups (${keepBackups:-$DEFAULT_KEEPBACKUPS})" + echo "!!! **********************************************************************" fi + if ! popd &>>$LOG_FILE; then assertionFailed $LINENO "pop failed" fi From 8f782cd78235702ba4ca1e63be39efc5d3145302 Mon Sep 17 00:00:00 2001 From: rpi-simonz Date: Sat, 5 Oct 2024 18:20:28 +0200 Subject: [PATCH 18/29] New messages 400 and 401 --- raspiBackup.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/raspiBackup.sh b/raspiBackup.sh index ce2f77dc..4717e8d3 100755 --- a/raspiBackup.sh +++ b/raspiBackup.sh @@ -1831,6 +1831,14 @@ MSG_DE[$MSG_NO_FILEATTRIBUTE_RIGHTS]="RBK0266E: Es fehlt die Berechtigung um Lin MSG_FI[$MSG_NO_FILEATTRIBUTE_RIGHTS]="RBK0266E: Käyttöoikeudet tiedostoattribuuttien luomiseen puuttuvat kohteesta %s (Tiedostojärjestelmä: %s)." MSG_FR[$MSG_NO_FILEATTRIBUTE_RIGHTS]="RBK0266E: Droits d'accès manquants pour créer des attributs de fichier sur %s (système de fichiers : %s)." +MSG_EXISTING_BACKUP=400 +MSG_EN[$MSG_EXISTING_BACKUP]="RBK0400I: Existing backup: %s" +MSG_DE[$MSG_EXISTING_BACKUP]="RBK0400I: Existierendes Backup: %s" +MSG_NORMAL_RECYCLE_FILE_WOULD_BE_DELETED=401 +MSG_EN[$MSG_NORMAL_RECYCLE_FILE_WOULD_BE_DELETED]="RBK0401W: Backup strategy would delete %s." +MSG_DE[$MSG_NORMAL_RECYCLE_FILE_WOULD_BE_DELETED]="RBK0401W: Backup Strategie würde %s Backup löschen." +MSG_FI[$MSG_NORMAL_RECYCLE_FILE_WOULD_BE_DELETED]="RBK0401W: Varmuuskopiointistrategia poistaisi kohteen %s." + # # Non NLS messages # @@ -6165,11 +6173,11 @@ function applyBackupStrategy() { fi tobeCheckedBackups=$(ls -d ${HOSTNAME_OSR}-${BACKUPTYPE}-backup-* 2>>$LOG_FILE| grep -vE "_") echo "$tobeCheckedBackups" | while read dir_to_check; do - [[ -n $dir_to_check ]] && echo "!!! Matching backup found: $BACKUPTARGET_ROOT/${dir_to_check}" + [[ -n $dir_to_check ]] && writeToConsole $MSG_LEVEL_MINIMAL $MSG_EXISTING_BACKUP $BACKUPTARGET_ROOT/${dir_to_check} done tobeDeletedBackups=$(ls -d ${HOSTNAME_OSR}-${BACKUPTYPE}-backup-* 2>>$LOG_FILE| grep -vE "_" | head -n -$fakeKeepBackups 2>>$LOG_FILE) echo "$tobeDeletedBackups" | while read dir_to_delete; do - [[ -n $dir_to_delete ]] && writeToConsole $MSG_LEVEL_MINIMAL $MSG_SMART_RECYCLE_FILE_WOULD_BE_DELETED "$BACKUPTARGET_ROOT/${dir_to_delete}" + [[ -n $dir_to_delete ]] && writeToConsole $MSG_LEVEL_MINIMAL $MSG_NORMAL_RECYCLE_FILE_WOULD_BE_DELETED "$BACKUPTARGET_ROOT/${dir_to_delete}" done if ! popd &>>$LOG_FILE; then assertionFailed $LINENO "pop failed" From 371db91b42839f336060931a42925a5664859286 Mon Sep 17 00:00:00 2001 From: rpi-simonz Date: Sat, 5 Oct 2024 19:25:55 +0200 Subject: [PATCH 19/29] reportOldBackups now with writeToConsole messages, 402-406 --- raspiBackup.sh | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/raspiBackup.sh b/raspiBackup.sh index 4717e8d3..2bf17be4 100755 --- a/raspiBackup.sh +++ b/raspiBackup.sh @@ -1838,6 +1838,21 @@ MSG_NORMAL_RECYCLE_FILE_WOULD_BE_DELETED=401 MSG_EN[$MSG_NORMAL_RECYCLE_FILE_WOULD_BE_DELETED]="RBK0401W: Backup strategy would delete %s." MSG_DE[$MSG_NORMAL_RECYCLE_FILE_WOULD_BE_DELETED]="RBK0401W: Backup Strategie würde %s Backup löschen." MSG_FI[$MSG_NORMAL_RECYCLE_FILE_WOULD_BE_DELETED]="RBK0401W: Varmuuskopiointistrategia poistaisi kohteen %s." +MSG_OLD_TYPE_BACKUPS_FOUND=402 +MSG_EN[$MSG_OLD_TYPE_BACKUPS_FOUND]="RBK0402W: Old-type backups foundi (without OS info in its Name):" +MSG_DE[$MSG_OLD_TYPE_BACKUPS_FOUND]="RBK0402W: Backups vom alten Typ gefunden (ohne OS-Info im Namen):" +MSG_OLD_TYPE_BACKUPS_HANDLING_INFO=403 +MSG_EN[$MSG_OLD_TYPE_BACKUPS_HANDLING_INFO]="RBK0403W: They might be deleted manually. Best when there are enough new-type ones." +MSG_DE[$MSG_OLD_TYPE_BACKUPS_HANDLING_INFO]="RBK0403W: Diese könnten manuell gelöcht werden. Sinnvollerweise, wenn genügend neue Backups existieren." +MSG_OLD_TYPE_BACKUPS_HANDLING_INFO_NORMAL=404 +MSG_EN[$MSG_OLD_TYPE_BACKUPS_HANDLING_INFO_NORMAL]="RBK0404W: \"Enough\" means: if numListedNewBackups (%s) has reached keepBackups (%s)." +MSG_DE[$MSG_OLD_TYPE_BACKUPS_HANDLING_INFO_NORMAL]="RBK0404W: \"Genügend\" meint: Wenn numListedNewBackups (%s) den Wert von keepBackups (%s) erreicht hat." +MSG_OLD_TYPE_BACKUPS_HANDLING_INFO_SMART=405 +MSG_EN[$MSG_OLD_TYPE_BACKUPS_HANDLING_INFO_SMART]="RBK0405W: \"Enough\" means: if numListedNewBackups (%s) or numKeptBackups (%s) has reached keepBackups (%s)." +MSG_DE[$MSG_OLD_TYPE_BACKUPS_HANDLING_INFO_SMART]="RBK0405W: \"Genügend\" meint: Wenn numListedNewBackups (%s) oder numKeptBackups (%s) den Wert von keepBackups (%s) erreicht hat." +MSG_GENERIC_WARNING=406 +MSG_EN[$MSG_GENERIC_WARNING]="RBK0406W: %s" +MSG_DE[$MSG_GENERIC_WARNING]="RBK0406W: %s" # # Non NLS messages @@ -6280,16 +6295,18 @@ function reportOldBackups() { tobeListedOldBackups=$(ls -d ${HOSTNAME}-${BACKUPTYPE}-backup-* 2>>$LOG_FILE| grep -vE "_") if [[ -n $tobeListedOldBackups ]] ; then - echo "!!! **********************************************************************" - echo "!!! Old-type backups found:" + writeToConsole $MSG_LEVEL_MINIMAL $MSG_GENERIC_WARNING "? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? " + writeToConsole $MSG_LEVEL_MINIMAL $MSG_OLD_TYPE_BACKUPS_FOUND echo "$tobeListedOldBackups" | while read dir_to_list; do - [[ -n $dir_to_list ]] && echo "!!! - $BACKUPTARGET_ROOT/${dir_to_list}" + [[ -n $dir_to_list ]] && writeToConsole $MSG_LEVEL_MINIMAL $MSG_GENERIC_WARNING " - $BACKUPTARGET_ROOT/${dir_to_list}" done - echo "!!! These old-type backups might be deleted manually when there are enough new-type ones." - echo -e "!!! \"Enough\" means: if numListedNewBackups ($numListedNewBackups) \c" - (( $SMART_RECYCLE )) && echo -e " or numKeptBackups ($numKeptBackups) \c" - echo " has reached keepBackups (${keepBackups:-$DEFAULT_KEEPBACKUPS})" - echo "!!! **********************************************************************" + writeToConsole $MSG_LEVEL_MINIMAL $MSG_OLD_TYPE_BACKUPS_HANDLING_INFO + if (( $SMART_RECYCLE )) ; then + writeToConsole $MSG_LEVEL_MINIMAL $MSG_OLD_TYPE_BACKUPS_HANDLING_INFO_SMART $numListedNewBackups $numKeptBackups ${keepBackups:-$DEFAULT_KEEPBACKUPS} + else + writeToConsole $MSG_LEVEL_MINIMAL $MSG_OLD_TYPE_BACKUPS_HANDLING_INFO_NORMAL $numListedNewBackups ${keepBackups:-$DEFAULT_KEEPBACKUPS} + fi + writeToConsole $MSG_LEVEL_MINIMAL $MSG_GENERIC_WARNING "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" fi if ! popd &>>$LOG_FILE; then From c498ef191f48fc3198820780698535f79ad7df11 Mon Sep 17 00:00:00 2001 From: rpi-simonz Date: Sun, 6 Oct 2024 08:00:13 +0200 Subject: [PATCH 20/29] Fix typo --- raspiBackup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/raspiBackup.sh b/raspiBackup.sh index 2bf17be4..9399aee5 100755 --- a/raspiBackup.sh +++ b/raspiBackup.sh @@ -8773,7 +8773,7 @@ function SR_listMonthlyBackups() { # directory # today is 20191117 # date -d "$(date +%Y%m15) -0 month" +%Y%m -> 201911 local d=$(date -d "$(date +%Y%m15) -${i} month" +%Y%m) # get month - ls -1 $1 | egrep "${HOSTNAME_OSR}\-${BACKUPTYPE}\-backup\-$d[0-9]{2}" | grep -Ev "_" | sort -ur | tail -n 1 # find earlies monthly backup + ls -1 $1 | egrep "${HOSTNAME_OSR}\-${BACKUPTYPE}\-backup\-$d[0-9]{2}" | grep -Ev "_" | sort -ur | tail -n 1 # find earliest monthly backup done fi logExit From 9e0f6d9221a40259c5bcab2fd570429cfafefe42 Mon Sep 17 00:00:00 2001 From: rpi-simonz Date: Sun, 6 Oct 2024 08:25:17 +0200 Subject: [PATCH 21/29] Fix typos in and enhance messages used in reportOldBackups --- raspiBackup.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/raspiBackup.sh b/raspiBackup.sh index 9399aee5..e036cd29 100755 --- a/raspiBackup.sh +++ b/raspiBackup.sh @@ -1839,11 +1839,11 @@ MSG_EN[$MSG_NORMAL_RECYCLE_FILE_WOULD_BE_DELETED]="RBK0401W: Backup strategy wou MSG_DE[$MSG_NORMAL_RECYCLE_FILE_WOULD_BE_DELETED]="RBK0401W: Backup Strategie würde %s Backup löschen." MSG_FI[$MSG_NORMAL_RECYCLE_FILE_WOULD_BE_DELETED]="RBK0401W: Varmuuskopiointistrategia poistaisi kohteen %s." MSG_OLD_TYPE_BACKUPS_FOUND=402 -MSG_EN[$MSG_OLD_TYPE_BACKUPS_FOUND]="RBK0402W: Old-type backups foundi (without OS info in its Name):" +MSG_EN[$MSG_OLD_TYPE_BACKUPS_FOUND]="RBK0402W: Old-type backups found (without OS info in its Name):" MSG_DE[$MSG_OLD_TYPE_BACKUPS_FOUND]="RBK0402W: Backups vom alten Typ gefunden (ohne OS-Info im Namen):" MSG_OLD_TYPE_BACKUPS_HANDLING_INFO=403 MSG_EN[$MSG_OLD_TYPE_BACKUPS_HANDLING_INFO]="RBK0403W: They might be deleted manually. Best when there are enough new-type ones." -MSG_DE[$MSG_OLD_TYPE_BACKUPS_HANDLING_INFO]="RBK0403W: Diese könnten manuell gelöcht werden. Sinnvollerweise, wenn genügend neue Backups existieren." +MSG_DE[$MSG_OLD_TYPE_BACKUPS_HANDLING_INFO]="RBK0403W: Diese können manuell gelöscht werden. Sinnvollerweise, wenn genügend neue Backups existieren." MSG_OLD_TYPE_BACKUPS_HANDLING_INFO_NORMAL=404 MSG_EN[$MSG_OLD_TYPE_BACKUPS_HANDLING_INFO_NORMAL]="RBK0404W: \"Enough\" means: if numListedNewBackups (%s) has reached keepBackups (%s)." MSG_DE[$MSG_OLD_TYPE_BACKUPS_HANDLING_INFO_NORMAL]="RBK0404W: \"Genügend\" meint: Wenn numListedNewBackups (%s) den Wert von keepBackups (%s) erreicht hat." @@ -1853,6 +1853,9 @@ MSG_DE[$MSG_OLD_TYPE_BACKUPS_HANDLING_INFO_SMART]="RBK0405W: \"Genügend\" meint MSG_GENERIC_WARNING=406 MSG_EN[$MSG_GENERIC_WARNING]="RBK0406W: %s" MSG_DE[$MSG_GENERIC_WARNING]="RBK0406W: %s" +MSG_BACKUP_NAMING_CHANGE=407 +MSG_EN[$MSG_BACKUP_NAMING_CHANGE]="RBK0407W: With raspiBackup version %s the naming of the backup directories changed!" +MSG_DE[$MSG_BACKUP_NAMING_CHANGE]="RBK0407W: Ab raspiBackup Version %s hat sich die Bezeichnung der Backup-Verzeichnisse geändert!" # # Non NLS messages @@ -6295,7 +6298,8 @@ function reportOldBackups() { tobeListedOldBackups=$(ls -d ${HOSTNAME}-${BACKUPTYPE}-backup-* 2>>$LOG_FILE| grep -vE "_") if [[ -n $tobeListedOldBackups ]] ; then - writeToConsole $MSG_LEVEL_MINIMAL $MSG_GENERIC_WARNING "? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? " + writeToConsole $MSG_LEVEL_MINIMAL $MSG_GENERIC_WARNING "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + writeToConsole $MSG_LEVEL_MINIMAL $MSG_BACKUP_NAMING_CHANGE "0.6.10.0" writeToConsole $MSG_LEVEL_MINIMAL $MSG_OLD_TYPE_BACKUPS_FOUND echo "$tobeListedOldBackups" | while read dir_to_list; do [[ -n $dir_to_list ]] && writeToConsole $MSG_LEVEL_MINIMAL $MSG_GENERIC_WARNING " - $BACKUPTARGET_ROOT/${dir_to_list}" From 778ffc61f987110e0ec0eee32d72a541e2dfd83f Mon Sep 17 00:00:00 2001 From: rpi-simonz Date: Sun, 6 Oct 2024 08:29:55 +0200 Subject: [PATCH 22/29] Fix some indentation inconsistencies --- raspiBackup.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/raspiBackup.sh b/raspiBackup.sh index e036cd29..a30d1596 100755 --- a/raspiBackup.sh +++ b/raspiBackup.sh @@ -6859,7 +6859,7 @@ function inspect4Backup() { fi logItem "bootMountpoint: $bootMountpoint, bootPartition: $bootPartition" - + logItem "Starting root discovery" # find root partition @@ -7257,8 +7257,8 @@ function doitBackup() { fi if (( $SYSTEMSTATUS )) && ! which lsof &>/dev/null; then - writeToConsole $MSG_LEVEL_MINIMAL $MSG_MISSING_INSTALLED_FILE "lsof" "lsof" - exitError $RC_MISSING_COMMANDS + writeToConsole $MSG_LEVEL_MINIMAL $MSG_MISSING_INSTALLED_FILE "lsof" "lsof" + exitError $RC_MISSING_COMMANDS fi writeToConsole $MSG_LEVEL_MINIMAL $MSG_USING_BACKUPPATH "$BACKUPPATH" "$(getFsType "$BACKUPPATH")" @@ -7283,10 +7283,10 @@ function doitBackup() { BACKUPPATH_PARAMETER="$BACKUPPATH" BACKUPPATH="$BACKUPPATH/$HOSTNAME" if [[ ! -d "$BACKUPPATH" ]]; then - if ! mkdir -p "${BACKUPPATH}"; then + if ! mkdir -p "${BACKUPPATH}"; then writeToConsole $MSG_LEVEL_MINIMAL $MSG_UNABLE_TO_CREATE_DIRECTORY "$BACKUPPATH" exitError $RC_CREATE_ERROR - fi + fi fi logCommand "ls -1 ${BACKUPPATH}" @@ -8267,8 +8267,8 @@ function updateRestoreReminder() { # initialize reminder state if [[ ! -e "$reminder_file" ]]; then - echo "$(date +%Y%m) 0" > "$reminder_file" - return + echo "$(date +%Y%m) 0" > "$reminder_file" + return fi # retrieve reminder state @@ -8276,7 +8276,7 @@ function updateRestoreReminder() { now=$(date +%Y%m) local rf rf="$(<$reminder_file)" - if [[ -z "${rf}" ]]; then # issue #316: reminder file exists but is empty + if [[ -z "${rf}" ]]; then # issue #316: reminder file exists but is empty echo "$(date +%Y%m) 0" > "$reminder_file" return fi @@ -8952,7 +8952,7 @@ function usageEN() { [ -z "$DEFAULT_STOPSERVICES" ] && DEFAULT_STOPSERVICES="no" echo "-a \"{commands to execute after Backup}\" (default: $DEFAULT_STARTSERVICES)" echo "-B Save bootpartition in tar file (Default: $DEFAULT_TAR_BOOT_PARTITION_ENABLED)" - echo "-F Backup is simulated" + echo "-F Backup is simulated" echo "-k {backupsToKeep} (default: $DEFAULT_KEEPBACKUPS)" [ -z "$DEFAULT_STARTSERVICES" ] && DEFAULT_STARTSERVICES="no" echo "-o \"{commands to execute before Backup}\" (default: $DEFAULT_STOPSERVICES)" @@ -9003,7 +9003,7 @@ function usageDE() { [ -z "$DEFAULT_STOPSERVICES" ] && DEFAULT_STOPSERVICES="keine" echo "-a \"{Befehle die nach dem Backup ausgeführt werden}\" (Standard: $DEFAULT_STARTSERVICES)" echo "-B Sicherung der Bootpartition als tar file (Standard: $DEFAULT_TAR_BOOT_PARTITION_ENABLED)" - echo "-F Backup wird nur simuliert" + echo "-F Backup wird nur simuliert" echo "-k {Anzahl Backups} (Standard: $DEFAULT_KEEPBACKUPS)" [ -z "$DEFAULT_STARTSERVICES" ] && DEFAULT_STARTSERVICES="keine" echo "-o \"{Befehle die vor dem Backup ausgeführt werden}\" (Standard: $DEFAULT_STOPSERVICES)" @@ -9052,7 +9052,7 @@ function usageFI() { [ -z "$DEFAULT_STOPSERVICES" ] && DEFAULT_STOPSERVICES="ei" echo "-a \"{varmuuskopion jläkeen suoritettavat komennot}\" (oletus: $DEFAULT_STARTSERVICES)" echo "-B Tee käynnistysosiosta kopio tar tiedostoon (oletus: $DEFAULT_TAR_BOOT_PARTITION_ENABLED)" - echo "-F Varmuuskopioinnin simulointi" + echo "-F Varmuuskopioinnin simulointi" echo "-k {säilytettävien varmuuskopioiden lkm} (oletus: $DEFAULT_KEEPBACKUPS)" [ -z "$DEFAULT_STARTSERVICES" ] && DEFAULT_STARTSERVICES="ei" echo "-o \"{ennen varmuuskopiointia suoritettavat komennot}\" (oletus: $DEFAULT_STOPSERVICES)" From 76d8d1cd2f652d3f3be710ea2e9e6264ffc5ee03 Mon Sep 17 00:00:00 2001 From: rpi-simonz Date: Sun, 6 Oct 2024 09:06:06 +0200 Subject: [PATCH 23/29] Rename and reorder some of the new messages --- raspiBackup.sh | 61 ++++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/raspiBackup.sh b/raspiBackup.sh index a30d1596..823e0ff0 100755 --- a/raspiBackup.sh +++ b/raspiBackup.sh @@ -1831,31 +1831,34 @@ MSG_DE[$MSG_NO_FILEATTRIBUTE_RIGHTS]="RBK0266E: Es fehlt die Berechtigung um Lin MSG_FI[$MSG_NO_FILEATTRIBUTE_RIGHTS]="RBK0266E: Käyttöoikeudet tiedostoattribuuttien luomiseen puuttuvat kohteesta %s (Tiedostojärjestelmä: %s)." MSG_FR[$MSG_NO_FILEATTRIBUTE_RIGHTS]="RBK0266E: Droits d'accès manquants pour créer des attributs de fichier sur %s (système de fichiers : %s)." -MSG_EXISTING_BACKUP=400 -MSG_EN[$MSG_EXISTING_BACKUP]="RBK0400I: Existing backup: %s" -MSG_DE[$MSG_EXISTING_BACKUP]="RBK0400I: Existierendes Backup: %s" -MSG_NORMAL_RECYCLE_FILE_WOULD_BE_DELETED=401 -MSG_EN[$MSG_NORMAL_RECYCLE_FILE_WOULD_BE_DELETED]="RBK0401W: Backup strategy would delete %s." -MSG_DE[$MSG_NORMAL_RECYCLE_FILE_WOULD_BE_DELETED]="RBK0401W: Backup Strategie würde %s Backup löschen." -MSG_FI[$MSG_NORMAL_RECYCLE_FILE_WOULD_BE_DELETED]="RBK0401W: Varmuuskopiointistrategia poistaisi kohteen %s." -MSG_OLD_TYPE_BACKUPS_FOUND=402 -MSG_EN[$MSG_OLD_TYPE_BACKUPS_FOUND]="RBK0402W: Old-type backups found (without OS info in its Name):" -MSG_DE[$MSG_OLD_TYPE_BACKUPS_FOUND]="RBK0402W: Backups vom alten Typ gefunden (ohne OS-Info im Namen):" -MSG_OLD_TYPE_BACKUPS_HANDLING_INFO=403 -MSG_EN[$MSG_OLD_TYPE_BACKUPS_HANDLING_INFO]="RBK0403W: They might be deleted manually. Best when there are enough new-type ones." -MSG_DE[$MSG_OLD_TYPE_BACKUPS_HANDLING_INFO]="RBK0403W: Diese können manuell gelöscht werden. Sinnvollerweise, wenn genügend neue Backups existieren." -MSG_OLD_TYPE_BACKUPS_HANDLING_INFO_NORMAL=404 -MSG_EN[$MSG_OLD_TYPE_BACKUPS_HANDLING_INFO_NORMAL]="RBK0404W: \"Enough\" means: if numListedNewBackups (%s) has reached keepBackups (%s)." -MSG_DE[$MSG_OLD_TYPE_BACKUPS_HANDLING_INFO_NORMAL]="RBK0404W: \"Genügend\" meint: Wenn numListedNewBackups (%s) den Wert von keepBackups (%s) erreicht hat." -MSG_OLD_TYPE_BACKUPS_HANDLING_INFO_SMART=405 -MSG_EN[$MSG_OLD_TYPE_BACKUPS_HANDLING_INFO_SMART]="RBK0405W: \"Enough\" means: if numListedNewBackups (%s) or numKeptBackups (%s) has reached keepBackups (%s)." -MSG_DE[$MSG_OLD_TYPE_BACKUPS_HANDLING_INFO_SMART]="RBK0405W: \"Genügend\" meint: Wenn numListedNewBackups (%s) oder numKeptBackups (%s) den Wert von keepBackups (%s) erreicht hat." -MSG_GENERIC_WARNING=406 -MSG_EN[$MSG_GENERIC_WARNING]="RBK0406W: %s" -MSG_DE[$MSG_GENERIC_WARNING]="RBK0406W: %s" -MSG_BACKUP_NAMING_CHANGE=407 -MSG_EN[$MSG_BACKUP_NAMING_CHANGE]="RBK0407W: With raspiBackup version %s the naming of the backup directories changed!" -MSG_DE[$MSG_BACKUP_NAMING_CHANGE]="RBK0407W: Ab raspiBackup Version %s hat sich die Bezeichnung der Backup-Verzeichnisse geändert!" +MSG_GENERIC_WARNING=400 +MSG_EN[$MSG_GENERIC_WARNING]="RBK0400W: %s" +MSG_DE[$MSG_GENERIC_WARNING]="RBK0400W: %s" + +MSG_EXISTING_BACKUP=401 +MSG_EN[$MSG_EXISTING_BACKUP]="RBK0401I: Existing backup: %s" +MSG_DE[$MSG_EXISTING_BACKUP]="RBK0401I: Existierendes Backup: %s" +MSG_NORMAL_RECYCLE_FILE_WOULD_BE_DELETED=402 +MSG_EN[$MSG_NORMAL_RECYCLE_FILE_WOULD_BE_DELETED]="RBK0402W: Backup strategy would delete %s." +MSG_DE[$MSG_NORMAL_RECYCLE_FILE_WOULD_BE_DELETED]="RBK0402W: Backup Strategie würde %s Backup löschen." +MSG_FI[$MSG_NORMAL_RECYCLE_FILE_WOULD_BE_DELETED]="RBK0402W: Varmuuskopiointistrategia poistaisi kohteen %s." + +MSG_BACKUP_NAMING_CHANGE=403 +MSG_EN[$MSG_BACKUP_NAMING_CHANGE]="RBK0403W: With raspiBackup version %s the naming of the backup directories changed!" +MSG_DE[$MSG_BACKUP_NAMING_CHANGE]="RBK0403W: Ab raspiBackup Version %s hat sich die Bezeichnung der Backup-Verzeichnisse geändert!" +MSG_OLD_NAME_BACKUPS_FOUND=404 +MSG_EN[$MSG_OLD_NAME_BACKUPS_FOUND]="RBK0404W: Old-name backups found (without OS info in its name):" +MSG_DE[$MSG_OLD_NAME_BACKUPS_FOUND]="RBK0404W: Backups mit alter Bezeichnung gefunden (ohne OS-Info im Namen):" +MSG_OLD_NAME_BACKUPS_HANDLING_INFO=405 +MSG_EN[$MSG_OLD_NAME_BACKUPS_HANDLING_INFO]="RBK0405W: They might be deleted manually. Best when there are enough new-type ones." +MSG_DE[$MSG_OLD_NAME_BACKUPS_HANDLING_INFO]="RBK0405W: Diese können manuell gelöscht werden. Sinnvollerweise, wenn genügend neue Backups existieren." +MSG_OLD_NAME_BACKUPS_HANDLING_INFO_NORMAL=406 +MSG_EN[$MSG_OLD_NAME_BACKUPS_HANDLING_INFO_NORMAL]="RBK0406W: \"Enough\" means: if numListedNewBackups (%s) has reached keepBackups (%s)." +MSG_DE[$MSG_OLD_NAME_BACKUPS_HANDLING_INFO_NORMAL]="RBK0406W: \"Genügend\" meint: Wenn numListedNewBackups (%s) den Wert von keepBackups (%s) erreicht hat." +MSG_OLD_NAME_BACKUPS_HANDLING_INFO_SMART=407 +MSG_EN[$MSG_OLD_NAME_BACKUPS_HANDLING_INFO_SMART]="RBK0407W: \"Enough\" means: if numListedNewBackups (%s) or numKeptBackups (%s) has reached keepBackups (%s)." +MSG_DE[$MSG_OLD_NAME_BACKUPS_HANDLING_INFO_SMART]="RBK0407W: \"Genügend\" meint: Wenn numListedNewBackups (%s) oder numKeptBackups (%s) den Wert von keepBackups (%s) erreicht hat." + # # Non NLS messages @@ -6300,15 +6303,15 @@ function reportOldBackups() { if [[ -n $tobeListedOldBackups ]] ; then writeToConsole $MSG_LEVEL_MINIMAL $MSG_GENERIC_WARNING "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" writeToConsole $MSG_LEVEL_MINIMAL $MSG_BACKUP_NAMING_CHANGE "0.6.10.0" - writeToConsole $MSG_LEVEL_MINIMAL $MSG_OLD_TYPE_BACKUPS_FOUND + writeToConsole $MSG_LEVEL_MINIMAL $MSG_OLD_NAME_BACKUPS_FOUND echo "$tobeListedOldBackups" | while read dir_to_list; do [[ -n $dir_to_list ]] && writeToConsole $MSG_LEVEL_MINIMAL $MSG_GENERIC_WARNING " - $BACKUPTARGET_ROOT/${dir_to_list}" done - writeToConsole $MSG_LEVEL_MINIMAL $MSG_OLD_TYPE_BACKUPS_HANDLING_INFO + writeToConsole $MSG_LEVEL_MINIMAL $MSG_OLD_NAME_BACKUPS_HANDLING_INFO if (( $SMART_RECYCLE )) ; then - writeToConsole $MSG_LEVEL_MINIMAL $MSG_OLD_TYPE_BACKUPS_HANDLING_INFO_SMART $numListedNewBackups $numKeptBackups ${keepBackups:-$DEFAULT_KEEPBACKUPS} + writeToConsole $MSG_LEVEL_MINIMAL $MSG_OLD_NAME_BACKUPS_HANDLING_INFO_SMART $numListedNewBackups $numKeptBackups ${keepBackups:-$DEFAULT_KEEPBACKUPS} else - writeToConsole $MSG_LEVEL_MINIMAL $MSG_OLD_TYPE_BACKUPS_HANDLING_INFO_NORMAL $numListedNewBackups ${keepBackups:-$DEFAULT_KEEPBACKUPS} + writeToConsole $MSG_LEVEL_MINIMAL $MSG_OLD_NAME_BACKUPS_HANDLING_INFO_NORMAL $numListedNewBackups ${keepBackups:-$DEFAULT_KEEPBACKUPS} fi writeToConsole $MSG_LEVEL_MINIMAL $MSG_GENERIC_WARNING "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" fi From be4a2bfcaf4ee4aa418bfdaea9af6789b88acd78 Mon Sep 17 00:00:00 2001 From: rpi-simonz Date: Mon, 7 Oct 2024 21:01:56 +0200 Subject: [PATCH 24/29] Delete overlooked asterisk --- raspiBackup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/raspiBackup.sh b/raspiBackup.sh index 823e0ff0..3d392587 100755 --- a/raspiBackup.sh +++ b/raspiBackup.sh @@ -5664,7 +5664,7 @@ function backupRsync() { # partition number (for partition based backup) source="/" bootPartitionBackup - lastBackupDir=$(find "$BACKUPTARGET_ROOT" -maxdepth 1 -type d -name "${HOSTNAME_OSR}*-$BACKUPTYPE-*" ! -name $BACKUPFILE 2>>/dev/null | sort | tail -n 1) + lastBackupDir=$(find "$BACKUPTARGET_ROOT" -maxdepth 1 -type d -name "${HOSTNAME_OSR}-$BACKUPTYPE-*" ! -name $BACKUPFILE 2>>/dev/null | sort | tail -n 1) excludeRoot="" excludeMeta="--exclude=/$BACKUPFILES_PARTITION_DATE.img --exclude=/$BACKUPFILES_PARTITION_DATE.tmg --exclude=/$BACKUPFILES_PARTITION_DATE.sfdisk --exclude=/$BACKUPFILES_PARTITION_DATE.blkid --exclude=/$BACKUPFILES_PARTITION_DATE.fdisk --exclude=/$BACKUPFILES_PARTITION_DATE.parted --exclude=/$BACKUPFILES_PARTITION_DATE.mbr --exclude=/$MYNAME.log --exclude=/$MYNAME.msg" fi From cb8da15919eaa8fa7a1d7618094f3de82d0de3ac Mon Sep 17 00:00:00 2001 From: rpi-simonz Date: Tue, 8 Oct 2024 07:18:24 +0200 Subject: [PATCH 25/29] First adaption of raspiBackup7412Test.sh - Untested yet --- test/raspiBackup7412Test.sh | 57 ++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 14 deletions(-) diff --git a/test/raspiBackup7412Test.sh b/test/raspiBackup7412Test.sh index 303d2ab9..5fdefd40 100755 --- a/test/raspiBackup7412Test.sh +++ b/test/raspiBackup7412Test.sh @@ -66,6 +66,35 @@ YEARLY=$PER_BUCKET MASS=1 TYPE=1 +HOSTNAME=$(hostname) +# For including the OS release into the name of the backup directory +os_release=$(getOSRelease) +# Note: Sanitize the os_release to be usable as (part of) directory name. +# But don't allow or use "-" or "_" as replacement character! +# Both characters are already used as dividers/markers later on! +# The "~" seems to be okay. Even safer would be "", a.k.a. nothing. +HOSTNAME_OSR="${HOSTNAME}@${os_release//[ \/\\\:\.\-_]/\~}" + +function getOSRelease() { + + local os_release_file + local os_release + + for os_release_file in /etc/os-release /usr/lib/os-release /dev/null ; do + [[ -e "$os_release_file" ]] && break + done + + # the prefix "osr_" prevents a lonely "local" with its output below when grep is unsuccessful + unset osr_ID osr_VERSION_ID # unset possible values used from global scope then + + local osr_$(grep -E "^ID=" "$os_release_file") + local osr_$(grep -E "^VERSION_ID=" "$os_release_file") + + os_release="${osr_ID}${osr_VERSION_ID}" # e.g. debian12 or even debian"12" + os_release="${os_release//\"/}" # remove any double quotes + echo "${os_release:-unknownOS}" # handle empty result +} + function createSpecificBackups() { # stringlist_of_dates of form yyyymmdd{-hhmmss] type dont_delete_flag if (( $# <= 2 )); then @@ -84,15 +113,15 @@ function createSpecificBackups() { # stringlist_of_dates of form yyyymmdd{-hhmms local h for d in $1; do (( ${#d} <= 8 )) && t="$tc" || t="" - local h="$(hostname)/$(hostname)-${type}-backup-"$d$t + local h="${HOSTNAME}/${HOSTNAME_OSR}-${type}-backup-"$d$t mkdir -p $DIR/$h - h="$(hostname)/$(hostname)-${type}-backup-"${d}-100000_before_before + h="${HOSTNAME}/${HOSTNAME_OSR}-${type}-backup-"${d}-100000_before_before mkdir -p $DIR/$h - h="$(hostname)/$(hostname)-${type}-backup-"${d}-200000_after_after + h="${HOSTNAME}/${HOSTNAME_OSR}-${type}-backup-"${d}-200000_after_after mkdir -p $DIR/$h done - (( $DEBUG )) && ls -1 "$DIR/$(hostname)" + (( $DEBUG )) && ls -1 "$DIR/${HOSTNAME}" } @@ -132,7 +161,7 @@ function createMassBackups() { # startdate count #per_day type dont_delete_flag printf -v F_HR "%02d" $F_HR printf -v F_MI "%02d" $F_MI printf -v F_SI "%02d" $F_SI - local h="$(hostname)/$(hostname)-${type}-backup-"$(date -d "$today -$i days" +%Y%m%d-) + local h="${HOSTNAME}/${HOSTNAME_OSR}-${type}-backup-"$(date -d "$today -$i days" +%Y%m%d-) local n="$h$F_HR$F_MI$F_SI" if (( c-- % $TICKS == 0 )); then (( $DEBUG )) && echo "Next $TICKS ... $n ..." @@ -145,7 +174,7 @@ function createMassBackups() { # startdate count #per_day type dont_delete_flag done done - (( $DEBUG )) && ls -1 "$DIR/$(hostname)" + (( $DEBUG )) && ls -1 "$DIR/${HOSTNAME}" } @@ -153,11 +182,11 @@ function testMassBackups() { # count type echo "Testing ..." - local f=$(ls $DIR/$(hostname-${2})/ | wc -l) + local f=$(ls $DIR/${HOSTNAME_OSR}-${2}/ | wc -l) if (( f != $1 )); then echo "???: Expected $1 but found $f backups" - ls -r1 "$DIR/$(hostname)-${2}" + ls -r1 "$DIR/${HOSTNAME_OSR}-${2}" exit 1 fi } @@ -179,28 +208,28 @@ function testSpecificBackups() { # lineNo stringlist_of_dates type numberOfstati echo "Testing for type $type and static $((2*$static)) ..." - local f=$(ls $DIR/$(hostname)/ | grep $type | grep -v "_" | wc -l) + local f=$(ls $DIR/${HOSTNAME}/ | grep $type | grep -v "_" | wc -l) local n=$(wc -w <<< "$dtes") if (( f != $n )); then echo "??? Test in line $l: Expected #$n $dtes but found $f backups of type $type" - (( $DEBUG )) && ls -1 "$DIR/$(hostname)" + (( $DEBUG )) && ls -1 "$DIR/${HOSTNAME}" exit 1 fi - local f=$(ls $DIR/$(hostname)/ | grep $type | grep "_" | wc -l) + local f=$(ls $DIR/${HOSTNAME}/ | grep $type | grep "_" | wc -l) if (( f != $(($static*2)) )); then echo "??? Test in line $l: Expected #$(($static*2)) statics but found $f statics of type $type" - (( $DEBUG )) && ls -1 "$DIR/$(hostname)" + (( $DEBUG )) && ls -1 "$DIR/${HOSTNAME}" exit 1 fi local d for d in $dtes; do - if [[ -z $(find $DIR/$(hostname) -type d -name "*${type}-backup-${d}*") ]] ; then + if [[ -z $(find $DIR/${HOSTNAME} -type d -name "*${type}-backup-${d}*") ]] ; then echo "??? Test in line $l: Expected date $d of type $type in $dtes not found" - ls -1 "$DIR/$(hostname)" + ls -1 "$DIR/${HOSTNAME}" exit 1 fi done From 7e9cae96c5ed1f594ed0e36aa045df388aaa4f22 Mon Sep 17 00:00:00 2001 From: rpi-simonz Date: Tue, 8 Oct 2024 08:45:15 +0200 Subject: [PATCH 26/29] Add TODO hints to raspiBackup7412Test.sh --- test/raspiBackup7412Test.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/raspiBackup7412Test.sh b/test/raspiBackup7412Test.sh index 5fdefd40..41ef23a8 100755 --- a/test/raspiBackup7412Test.sh +++ b/test/raspiBackup7412Test.sh @@ -180,6 +180,9 @@ function createMassBackups() { # startdate count #per_day type dont_delete_flag function testMassBackups() { # count type + #TODO: a) is this function used anywhere? + # b) if yes: is HOSTNAME_OSR correct then? Just after "$DIR/"? + echo "Testing ..." local f=$(ls $DIR/${HOSTNAME_OSR}-${2}/ | wc -l) @@ -208,6 +211,9 @@ function testSpecificBackups() { # lineNo stringlist_of_dates type numberOfstati echo "Testing for type $type and static $((2*$static)) ..." + #TODO: do we need to filter HOSTNAME_OSR? + # or/and do we need to check for old-named backups too? + local f=$(ls $DIR/${HOSTNAME}/ | grep $type | grep -v "_" | wc -l) local n=$(wc -w <<< "$dtes") From 794bfa20fc194a05d330a1766d4f36c390e8c9e5 Mon Sep 17 00:00:00 2001 From: rpi-simonz Date: Tue, 8 Oct 2024 09:03:16 +0200 Subject: [PATCH 27/29] Fix code position of function --- test/raspiBackup7412Test.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/test/raspiBackup7412Test.sh b/test/raspiBackup7412Test.sh index 41ef23a8..941475e7 100755 --- a/test/raspiBackup7412Test.sh +++ b/test/raspiBackup7412Test.sh @@ -67,13 +67,6 @@ MASS=1 TYPE=1 HOSTNAME=$(hostname) -# For including the OS release into the name of the backup directory -os_release=$(getOSRelease) -# Note: Sanitize the os_release to be usable as (part of) directory name. -# But don't allow or use "-" or "_" as replacement character! -# Both characters are already used as dividers/markers later on! -# The "~" seems to be okay. Even safer would be "", a.k.a. nothing. -HOSTNAME_OSR="${HOSTNAME}@${os_release//[ \/\\\:\.\-_]/\~}" function getOSRelease() { @@ -241,6 +234,15 @@ function testSpecificBackups() { # lineNo stringlist_of_dates type numberOfstati done } +# For including the OS release into the name of the backup directory +os_release=$(getOSRelease) +# Note: Sanitize the os_release to be usable as (part of) directory name. +# But don't allow or use "-" or "_" as replacement character! +# Both characters are already used as dividers/markers later on! +# The "~" seems to be okay. Even safer would be "", a.k.a. nothing. +HOSTNAME_OSR="${HOSTNAME}@${os_release//[ \/\\\:\.\-_]/\~}" + + # tests to execute for all timeframes # 1) check limit on option is used for timeframe # 2) check if backup of this week/month/year is included From 9fb075830bfc0e941b51167db85bed9d83ffc34e Mon Sep 17 00:00:00 2001 From: rpi-simonz Date: Tue, 8 Oct 2024 21:45:43 +0200 Subject: [PATCH 28/29] framps changes (sent by personal message): Get getOSRelease by sourcing raspiBackup.sh. Add test to check for NOT deleting old-named backups. And some smaller changes. --- test/raspiBackup7412Test.sh | 75 ++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 43 deletions(-) diff --git a/test/raspiBackup7412Test.sh b/test/raspiBackup7412Test.sh index 941475e7..cd3586b9 100755 --- a/test/raspiBackup7412Test.sh +++ b/test/raspiBackup7412Test.sh @@ -32,15 +32,6 @@ MYSELF=${0##*/} MYNAME=${MYSELF%.*} VERSION="0.2" -set +u;GIT_DATE="$Date$"; set -u -GIT_DATE_ONLY=${GIT_DATE/: /} -GIT_DATE_ONLY=$(cut -f 2 -d ' ' <<< $GIT_DATE) -GIT_TIME_ONLY=$(cut -f 3 -d ' ' <<< $GIT_DATE) -set +u;GIT_COMMIT="$Sha1$";set -u -GIT_COMMIT_ONLY=$(cut -f 2 -d ' ' <<< $GIT_COMMIT | sed 's/\$//') - -GIT_CODEVERSION="$MYSELF $VERSION, $GIT_DATE_ONLY/$GIT_TIME_ONLY - $GIT_COMMIT_ONLY" - if (( $UID != 0 )); then echo "Call me as root" exit 1 @@ -65,28 +56,11 @@ MONTHLY=$PER_BUCKET YEARLY=$PER_BUCKET MASS=1 TYPE=1 +ADD_HOST=0 # flag to create old named backups HOSTNAME=$(hostname) -function getOSRelease() { - - local os_release_file - local os_release - - for os_release_file in /etc/os-release /usr/lib/os-release /dev/null ; do - [[ -e "$os_release_file" ]] && break - done - - # the prefix "osr_" prevents a lonely "local" with its output below when grep is unsuccessful - unset osr_ID osr_VERSION_ID # unset possible values used from global scope then - - local osr_$(grep -E "^ID=" "$os_release_file") - local osr_$(grep -E "^VERSION_ID=" "$os_release_file") - - os_release="${osr_ID}${osr_VERSION_ID}" # e.g. debian12 or even debian"12" - os_release="${os_release//\"/}" # remove any double quotes - echo "${os_release:-unknownOS}" # handle empty result -} +source ../raspiBackup.sh function createSpecificBackups() { # stringlist_of_dates of form yyyymmdd{-hhmmss] type dont_delete_flag @@ -108,6 +82,10 @@ function createSpecificBackups() { # stringlist_of_dates of form yyyymmdd{-hhmms (( ${#d} <= 8 )) && t="$tc" || t="" local h="${HOSTNAME}/${HOSTNAME_OSR}-${type}-backup-"$d$t mkdir -p $DIR/$h + if (( $ADD_HOST )); then # flag to create old directorynames also + local h="${HOSTNAME}/${HOSTNAME}-${type}-backup-"$d$t + mkdir -p $DIR/$h + fi h="${HOSTNAME}/${HOSTNAME_OSR}-${type}-backup-"${d}-100000_before_before mkdir -p $DIR/$h h="${HOSTNAME}/${HOSTNAME_OSR}-${type}-backup-"${d}-200000_after_after @@ -171,20 +149,21 @@ function createMassBackups() { # startdate count #per_day type dont_delete_flag } -function testMassBackups() { # count type - - #TODO: a) is this function used anywhere? - # b) if yes: is HOSTNAME_OSR correct then? Just after "$DIR/"? +function testOldDirNames() { # lineNo type number_of_backups + local l="$1" + local type="$2" + local n="$3" - echo "Testing ..." + echo "Testing for type $type old names $3" - local f=$(ls $DIR/${HOSTNAME_OSR}-${2}/ | wc -l) + local f=$(ls $DIR/${HOSTNAME}/${HOSTNAME}-* | grep $type | grep -v "_" | wc -l) - if (( f != $1 )); then - echo "???: Expected $1 but found $f backups" - ls -r1 "$DIR/${HOSTNAME_OSR}-${2}" + if (( f != n )); then + echo "??? Test in line $l: Expected #$n old backups but found $f backups" + (( $DEBUG )) && ls -1 "$DIR/${HOSTNAME}" exit 1 fi + } function testSpecificBackups() { # lineNo stringlist_of_dates type numberOfstaticBackups @@ -204,10 +183,7 @@ function testSpecificBackups() { # lineNo stringlist_of_dates type numberOfstati echo "Testing for type $type and static $((2*$static)) ..." - #TODO: do we need to filter HOSTNAME_OSR? - # or/and do we need to check for old-named backups too? - - local f=$(ls $DIR/${HOSTNAME}/ | grep $type | grep -v "_" | wc -l) + local f=$(ls $DIR/${HOSTNAME}/${HOSTNAME_OSR}* | grep $type | grep -v "_" | wc -l) local n=$(wc -w <<< "$dtes") if (( f != $n )); then @@ -216,7 +192,7 @@ function testSpecificBackups() { # lineNo stringlist_of_dates type numberOfstati exit 1 fi - local f=$(ls $DIR/${HOSTNAME}/ | grep $type | grep "_" | wc -l) + local f=$(ls $DIR/${HOSTNAME}/${HOSTNAME_OSR}* | grep $type | grep "_" | wc -l) if (( f != $(($static*2)) )); then echo "??? Test in line $l: Expected #$(($static*2)) statics but found $f statics of type $type" @@ -226,7 +202,7 @@ function testSpecificBackups() { # lineNo stringlist_of_dates type numberOfstati local d for d in $dtes; do - if [[ -z $(find $DIR/${HOSTNAME} -type d -name "*${type}-backup-${d}*") ]] ; then + if [[ -z $(find $DIR/${HOSTNAME}/${HOSTNAME_OSR}* -type d -name "*${type}-backup-${d}*") ]] ; then echo "??? Test in line $l: Expected date $d of type $type in $dtes not found" ls -1 "$DIR/${HOSTNAME}" exit 1 @@ -258,12 +234,16 @@ raspiOpts="--smartRecycle --smartRecycleDryrun- -t rsync -F -x -c -Z -m 1 -l 1 - if (( $DAILY )); then + + ADD_HOST=1 l=$LINENO echo "$l === DAILY (1) + (5)" d="20191116 20191117 20191118 20191119" createSpecificBackups "$d" faketime "2019-11-19" ../raspiBackup.sh --smartRecycleOptions "3 0 0 0" $raspiOpts >> $LOG_FILE testSpecificBackups $l "20191117 20191118 20191119" $(wc -w <<< "$d") + testOldDirNames $l rsync 4 + ADD_HOST=0 l=$LINENO echo "$l === DAILY (2)" @@ -286,12 +266,15 @@ fi if (( $WEEKLY )); then + ADD_HOST=1 l=$LINENO echo "$l === WEEKLY (1)" d="20191118 20191112 20190601" createSpecificBackups "$d" faketime "2019-11-19" ../raspiBackup.sh --smartRecycleOptions "0 2 0 0" $raspiOpts >> $LOG_FILE testSpecificBackups $l "20191118 20191112" $(wc -w <<< "$d") + testOldDirNames $l rsync 3 + ADD_HOST=0 l=$LINENO echo "$l === WEEKLY (1)" @@ -377,12 +360,15 @@ fi if (( $MONTHLY )); then + ADD_HOST=1 l=$LINENO echo "$l === MONTHLY (1)" d="20191108 20191003 20190903 20190810" createSpecificBackups "$d" faketime "2019-11-19" ../raspiBackup.sh --smartRecycleOptions "0 0 1 0" $raspiOpts >> $LOG_FILE testSpecificBackups $l "20191108" $(wc -w <<< "$d") + testOldDirNames $l rsync 4 + ADD_HOST=0 l=$LINENO echo "$l === MONTHLY (2)" @@ -419,12 +405,15 @@ fi if (( $YEARLY )); then + ADD_HOST=1 l=$LINENO echo "$l === YEARLY (1)" d="20190111 20181203 20171108 20161003" createSpecificBackups "$d" faketime "2019-01-19" ../raspiBackup.sh --smartRecycleOptions "0 0 1 0" $raspiOpts >> $LOG_FILE testSpecificBackups $l "20190111" $(wc -w <<< "$d") + testOldDirNames $l rsync 4 + ADD_HOST=0 l=$LINENO echo "$l === YEARLY (2)" From 95c16fd817289f08d7172daa88361bcb267de907 Mon Sep 17 00:00:00 2001 From: rpi-simonz Date: Wed, 9 Oct 2024 18:54:00 +0200 Subject: [PATCH 29/29] Only show info about old-named backups for a number of times (5) --- raspiBackup.sh | 72 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 60 insertions(+), 12 deletions(-) diff --git a/raspiBackup.sh b/raspiBackup.sh index 3d392587..5b6327d9 100755 --- a/raspiBackup.sh +++ b/raspiBackup.sh @@ -140,6 +140,7 @@ PROPERTY_FILE="$MYNAME.properties" LATEST_TEMP_PROPERTY_FILE="/tmp/$PROPERTY_FILE" VAR_LIB_DIRECTORY="/var/lib/$MYNAME" RESTORE_REMINDER_FILE="restore.reminder" +REPORT_COUNTER_FILE="report.counter" VARS_FILE="/tmp/$MYNAME.vars" TEMPORARY_MOUNTPOINT_ROOT="/tmp" LOGFILE_EXT=".log" @@ -1858,6 +1859,12 @@ MSG_DE[$MSG_OLD_NAME_BACKUPS_HANDLING_INFO_NORMAL]="RBK0406W: \"Genügend\" mein MSG_OLD_NAME_BACKUPS_HANDLING_INFO_SMART=407 MSG_EN[$MSG_OLD_NAME_BACKUPS_HANDLING_INFO_SMART]="RBK0407W: \"Enough\" means: if numListedNewBackups (%s) or numKeptBackups (%s) has reached keepBackups (%s)." MSG_DE[$MSG_OLD_NAME_BACKUPS_HANDLING_INFO_SMART]="RBK0407W: \"Genügend\" meint: Wenn numListedNewBackups (%s) oder numKeptBackups (%s) den Wert von keepBackups (%s) erreicht hat." +MSG_OLD_NAME_BACKUPS_COUNTER_INFO=408 +MSG_EN[$MSG_OLD_NAME_BACKUPS_COUNTER_INFO]="RBK0408W: Note: This message will be shown again %s times." +MSG_DE[$MSG_OLD_NAME_BACKUPS_COUNTER_INFO]="RBK0408W: Hinweis: Diese Meldung wird weitere %s Mal angezeigt werden." +MSG_OLD_NAME_BACKUPS_COUNTER_INFO_BYE=409 +MSG_EN[$MSG_OLD_NAME_BACKUPS_COUNTER_INFO_BYE]="RBK0409W: Note: This message will no longer be shown from now on." +MSG_DE[$MSG_OLD_NAME_BACKUPS_COUNTER_INFO_BYE]="RBK0409W: Hinweis: Diese Meldung wird zukünftig nicht mehr angezeigt werden." # @@ -2933,6 +2940,8 @@ function initializeDefaultConfigVariables() { DEFAULT_DYNAMIC_MOUNT="" # Define bootdevice (e.g. /dev/mmcblk0, /dev/nvme0n1 or /dev/sda) and turn off boot device autodiscovery DEFAULT_BOOT_DEVICE="" + # How often inform about possible old-named backups + DEFAULT_REPORT_COUNTER="5" ############# End default config section ############# } @@ -6301,19 +6310,58 @@ function reportOldBackups() { tobeListedOldBackups=$(ls -d ${HOSTNAME}-${BACKUPTYPE}-backup-* 2>>$LOG_FILE| grep -vE "_") if [[ -n $tobeListedOldBackups ]] ; then - writeToConsole $MSG_LEVEL_MINIMAL $MSG_GENERIC_WARNING "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" - writeToConsole $MSG_LEVEL_MINIMAL $MSG_BACKUP_NAMING_CHANGE "0.6.10.0" - writeToConsole $MSG_LEVEL_MINIMAL $MSG_OLD_NAME_BACKUPS_FOUND - echo "$tobeListedOldBackups" | while read dir_to_list; do - [[ -n $dir_to_list ]] && writeToConsole $MSG_LEVEL_MINIMAL $MSG_GENERIC_WARNING " - $BACKUPTARGET_ROOT/${dir_to_list}" - done - writeToConsole $MSG_LEVEL_MINIMAL $MSG_OLD_NAME_BACKUPS_HANDLING_INFO - if (( $SMART_RECYCLE )) ; then - writeToConsole $MSG_LEVEL_MINIMAL $MSG_OLD_NAME_BACKUPS_HANDLING_INFO_SMART $numListedNewBackups $numKeptBackups ${keepBackups:-$DEFAULT_KEEPBACKUPS} - else - writeToConsole $MSG_LEVEL_MINIMAL $MSG_OLD_NAME_BACKUPS_HANDLING_INFO_NORMAL $numListedNewBackups ${keepBackups:-$DEFAULT_KEEPBACKUPS} + + local report_counter_file="$VAR_LIB_DIRECTORY/$REPORT_COUNTER_FILE" + + # create directory to save counter + if [[ ! -d "$VAR_LIB_DIRECTORY" ]]; then + mkdir -p "$VAR_LIB_DIRECTORY" + fi + + # initialize counter + if [[ ! -e "$report_counter_file" ]]; then + echo "$DEFAULT_REPORT_COUNTER" > "$report_counter_file" + fi + + # retrieve counter + local rf + rf="$(<$report_counter_file)" + if [[ -z "${rf}" ]]; then # counter file exists but is empty + echo "$DEFAULT_REPORT_COUNTER" > "$report_counter_file" + return + fi + rf=( $(<$report_counter_file) ) + + # only print report if counter says so + if (( $rf > 0 )); then + + # update counter, but only if not in FAKE mode + local rfn=$(( ${rf} - 1 )) + if (( ! $FAKE )); then + echo "${rfn}" > "$report_counter_file" + fi + + writeToConsole $MSG_LEVEL_MINIMAL $MSG_GENERIC_WARNING "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + writeToConsole $MSG_LEVEL_MINIMAL $MSG_BACKUP_NAMING_CHANGE "0.6.10.0" + writeToConsole $MSG_LEVEL_MINIMAL $MSG_OLD_NAME_BACKUPS_FOUND + echo "$tobeListedOldBackups" | while read dir_to_list; do + [[ -n $dir_to_list ]] && writeToConsole $MSG_LEVEL_MINIMAL $MSG_GENERIC_WARNING " - $BACKUPTARGET_ROOT/${dir_to_list}" + done + writeToConsole $MSG_LEVEL_MINIMAL $MSG_OLD_NAME_BACKUPS_HANDLING_INFO + if (( $SMART_RECYCLE )) ; then + writeToConsole $MSG_LEVEL_MINIMAL $MSG_OLD_NAME_BACKUPS_HANDLING_INFO_SMART $numListedNewBackups $numKeptBackups ${keepBackups:-$DEFAULT_KEEPBACKUPS} + else + writeToConsole $MSG_LEVEL_MINIMAL $MSG_OLD_NAME_BACKUPS_HANDLING_INFO_NORMAL $numListedNewBackups ${keepBackups:-$DEFAULT_KEEPBACKUPS} + fi + if (( $rfn > 0 )) ; then + writeToConsole $MSG_LEVEL_MINIMAL $MSG_OLD_NAME_BACKUPS_COUNTER_INFO "${rfn}" + else + writeToConsole $MSG_LEVEL_MINIMAL $MSG_OLD_NAME_BACKUPS_COUNTER_INFO_BYE + fi + + writeToConsole $MSG_LEVEL_MINIMAL $MSG_GENERIC_WARNING "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + fi - writeToConsole $MSG_LEVEL_MINIMAL $MSG_GENERIC_WARNING "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" fi if ! popd &>>$LOG_FILE; then