]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
fix count up backup more than backups
authorBastian Dehn <hhaalo@arcor.de>
Sat, 24 May 2025 18:21:31 +0000 (20:21 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 24 May 2025 18:21:31 +0000 (20:21 +0200)
backup

diff --git a/backup b/backup
index 32d448658aea79d77e93948fd703e87e81f4cdaa..e3ff4b064e6ad31018bab0638676a45b981b7ca1 100755 (executable)
--- a/backup
+++ b/backup
@@ -14,12 +14,12 @@ get_backup_dir()
 {
        local backup_path="$1"
        local backup_name="$2"
+       local last_backup_number="$3"
        local date=$(date +%F)
 
        local backup_dir=
        local number=
-       for count in {1..99}; do
-               number=$(printf "%02d" $count)
+       for number in $(seq --format "%02g" $last_backup_number 99); do
                backup_dir="$date"_"$number"_"$backup_name"
                [ -d "$backup_path/$backup_dir" ] || break;
        done
@@ -44,6 +44,7 @@ get_last_backup_dir_path()
 
 print_line()
 {
+       local i=
        for i in {1..80}; do
                printf "#"
        done
@@ -82,6 +83,7 @@ backup_remote_pathes()
        local LIGHTPURPLE="\e[1;35m"
        local RESET="\e[0m"
 
+       local path=
        for path in $pathes; do
                print_line
                printf "ℹ️  INFO: machine ${LIGHTPURPLE}%s${RESET}; " "$machine"
@@ -118,6 +120,7 @@ backup_remotes()
                || errlog "config.yaml no machines" \
                || return $?
 
+       local machine=
        for machine in $machines; do
                echo "ℹ️  INFO: create direcotry $backup_path/$machine"
                mkdir -p $backup_path/$machine \
@@ -141,6 +144,7 @@ remove_backup_dir()
                | sort \
                | head --lines $delete_count)
 
+       local backup=
        for backup in $backups; do
                echo "🗑️  DELETE: $backup"
                rm --recursive $backup
@@ -230,6 +234,7 @@ check_backup_date()
 
        print_line
        printf "\n"
+       local typ=
        for typ in day week month; do
                if [ -f "$typ" ]; then
                        color=$LIGHTGREEN
@@ -286,18 +291,25 @@ main()
                || return $?
        echo "ℹ️  INFO: backup count $backup_count"
 
-       local backup_dir=$(get_backup_dir \
+       local last_backup_dir_path=$(get_last_backup_dir_path \
                "$backup_path" \
                "$backup_name")
+       echo "ℹ️  INFO: last backup dir path $last_backup_dir_path"
+
+       local today_date=$(date +%F)
+       local last_backup_number=1
+       [[ "$last_backup_dir_path" =~ "$today_date" ]] \
+               && last_backup_number=${last_backup_dir_path##*/} \
+               && last_backup_number=${last_backup_number:11:2}
+       local backup_dir=$(get_backup_dir \
+               "$backup_path" \
+               "$backup_name" \
+               "$last_backup_number")
+
        echo "ℹ️  INFO: backup folder $backup_dir"
        local backup_full_path=$backup_path/$backup_dir
        echo "ℹ️  INFO: create folder $backup_full_path"
 
-       local last_backup_dir_path=$(get_last_backup_dir_path \
-               "$backup_path" \
-               "$backup_name")
-       echo "ℹ️  INFO: last backup dir path $last_backup_dir_path"
-
        backup_remotes \
                "$backup_full_path" \
                "$last_backup_dir_path" \