From: Bastian Dehn Date: Wed, 28 May 2025 17:16:47 +0000 (+0200) Subject: change history with split per line and delete log X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=d2fb144ea22c6457405210a09140cafa741b6c71;p=simple-backup.git change history with split per line and delete log --- diff --git a/backup b/backup index 6edd723..1677ae8 100755 --- a/backup +++ b/backup @@ -10,6 +10,54 @@ errlog() return $lastexit } +get_backup_type() +{ + local typ="none" + + [ -f "$backup_path/day" ] && typ="day" + [ -f "$backup_path/week" ] && typ="week" + [ -f "$backup_path/month" ] && typ="month" + + echo "$typ" +} + +write_current_date() +{ + local backup_path="$1" + local current_date="$(date +%F)" + local typ=$(get_backup_type) + + mkdir --parents "history" + + echo "$current_date" > $backup_path/$typ + echo "$current_date" > "history/$typ" +} + +rotate_history() +{ + local history_file="$1" + + [ -f "$history_file" ] \ + && history_lines=$(cat $history_file | wc -l) + echo "ℹ️ INFO: $history_file has $history_lines lines" + [ $history_lines -ge 100 ] \ + && savelog -c 7 -l $history_file \ + && echo "ℹ️ INFO: $history_file rotated" +} + +write_history_entry() +{ + local msg="$1" + local current_date=$(date --iso-8601=seconds) + local typ=$(get_backup_type) + + mkdir --parents "history" + rotate_history "history/history" + + echo "ℹ️ INFO: $current_date $typ $msg" + echo "$current_date $typ $msg" >> "history/history" +} + get_backup_dir() { local backup_path="$1" @@ -148,6 +196,7 @@ remove_backup_dir() for backup in $backups; do echo "🗑️ DELETE: $backup" rm --recursive $backup + write_history_entry "deleted ${backup##*/}" done } @@ -177,38 +226,6 @@ cleanup_backups() print_line } -make_history() -{ - local backup_path="$1" - local backup_dir="$2" - local backup_history_file="history" - local date="$(date +%F)" - local time="$(date +%T)" - local history_path="history" - local typ="none" - local history_size=0 - - [ -f "$backup_path/day" ] && typ="day" - [ -f "$backup_path/week" ] && typ="week" - [ -f "$backup_path/month" ] && typ="month" - - mkdir --parents "$history_path" - - [ -f "$history_path/$backup_history_file" ] \ - && history_size=$(cat $history_path/$backup_history_file \ - | wc -c) - echo "ℹ️ INFO: $history_path/$backup_history_file size $history_size bytes" - [ $history_size -ge 1024 ] \ - && savelog -c 7 -l $history_path/$backup_history_file \ - && echo "ℹ️ INFO: $history_path/$backup_history_file rotate" - - echo "ℹ️ INFO: add history $date $time $typ $backup_dir" - echo "$date" > $backup_path/$typ - echo "$date" > $history_path/$typ - echo "$date $time $typ $backup_dir" \ - >> $history_path/$backup_history_file -} - is_backup_old() { local backup_typ="$1" @@ -325,17 +342,17 @@ main() "$backup_full_path" \ "$last_backup_dir_path" \ || return $? - make_history \ - "$backup_path" \ - "$backup_dir" \ + write_current_date "$backup_path" \ || return $? - check_backup_date \ + write_history_entry "created $backup_dir" \ || return $? cleanup_backups \ "$backup_path" \ "$backup_name" \ $backup_count \ || return $? + check_backup_date \ + || return $? echo "✅ SUCCESS: backup" }