auto remove old backup files

remove backup files older than 30 days, but keep at least 5 copies of backup.

Fixes #102.
This commit is contained in:
Xu Cheng 2017-06-02 14:39:11 +08:00 committed by Bruno Sutic
parent 7e0bfcb7e9
commit 9d81e8d026
No known key found for this signature in database
GPG Key ID: CAFA7B1B2914ED81

View File

@ -278,6 +278,13 @@ dump_shell_history() {
done done
} }
remove_old_backups() {
# remove backup files older than 30 days, but keep at least 5 copies of backup.
local -a files
files=($(ls -t $(resurrect_dir)/*.txt | tail -n +6))
[[ ${#files[@]} -eq 0 ]] || find "${files[@]}" -type f -mtime +30 -delete
}
save_all() { save_all() {
local resurrect_file_path="$(resurrect_file_path)" local resurrect_file_path="$(resurrect_file_path)"
local last_resurrect_file="$(last_resurrect_file)" local last_resurrect_file="$(last_resurrect_file)"
@ -300,6 +307,7 @@ save_all() {
if save_shell_history_option_on; then if save_shell_history_option_on; then
dump_shell_history dump_shell_history
fi fi
remove_old_backups
} }
show_output() { show_output() {