Make backup retention period configurable

For instance `tmux set-option -g @resurrect-delete-backup-after 1`
to only keep 1 day of backups.

Closes 252.
This commit is contained in:
Ash Berlin-Taylor 2018-08-17 21:20:16 +01:00 committed by Bruno Sutic
parent 5f5f9d8fd5
commit e815c50f13
No known key found for this signature in database
GPG Key ID: CAFA7B1B2914ED81
3 changed files with 8 additions and 2 deletions

View File

@ -30,6 +30,8 @@
e.g. `vim -S Session1.vim`.
- Enable restoring command arguments for inline strategies with `*` character.
- Kill session "0" if it wasn't restored.
- Add `@resurrect-delete-backup-after` option to specify how many days of
backups to keep - default is 30.
### v2.4.0, 2015-02-23
- add "tmux-test"

View File

@ -269,11 +269,12 @@ dump_shell_history() {
}
remove_old_backups() {
# remove resurrect files older than 30 days, but keep at least 5 copies of backup.
# remove resurrect files older than 30 days (default), but keep at least 5 copies of backup.
local delete_after="$(get_tmux_option "$delete_backup_after_option" "$default_delete_backup_after")"
local -a files
files=($(ls -t $(resurrect_dir)/${RESURRECT_FILE_PREFIX}_*.${RESURRECT_FILE_EXTENSION} | tail -n +6))
[[ ${#files[@]} -eq 0 ]] ||
find "${files[@]}" -type f -mtime +30 -exec rm -v "{}" \;
find "${files[@]}" -type f -mtime "+${delete_after}" -exec rm -v "{}" \;
}
save_all() {

View File

@ -46,3 +46,6 @@ overwrite_option="@resurrect-never-overwrite"
# Hooks are set via ${hook_prefix}${name}, i.e. "@resurrect-hook-post-save-all"
hook_prefix="@resurrect-hook-"
delete_backup_after_option="@resurrect-delete-backup-after"
default_delete_backup_after="30" # days