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"
for backup in $backups; do
echo "🗑️ DELETE: $backup"
rm --recursive $backup
+ write_history_entry "deleted ${backup##*/}"
done
}
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"
"$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"
}