Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added option: delete old continuum saves #14

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

michael-coleman
Copy link

Per the discussion on this issue this commit adds the functionality to delete old tmux-continuum saves.
This code doesn't change the default behaviour of continuum, but for those users who want to stop the ~/.tmux/resurrect folder filling up with old save files, they can enable this by adding this line to ~/.tmux.conf

set -g @continuum-delete-old-saves-option 'on'

Note: the option uses this code provided by @gdebat, i.e.

ls ~/.tmux/resurrect/* -1dtr | head -n -10 | xargs -d '\n' rm -f

It retains the last 7 saves - but any additional saves beyond those 7 will be deleted.

@michael-coleman michael-coleman deleted the delete_old_saves branch November 28, 2015 04:15
@michael-coleman michael-coleman restored the delete_old_saves branch November 28, 2015 15:42
@bruno-
Copy link
Member

bruno- commented Nov 29, 2015

Hey there!
Thanks for contributing, we probably should provide a solution for deleting files.

I tested this locally and things exploded in a couple places:

  • head -n -10 blows up. Negative count unfortunately doesn't work on OSX
  • ls ~/.tmux/resurrect/* -1dtr also blows up. Command options need to go before the path pattern argument (on OSX at least).

If you agree let's make deleting old files the default (explicit option needed to disable that), but let's increase the number of files saved by default to last 7 days. We'll probably need to do a little math there: we wanna take the value of @continuum-save-interval and figure how many files need to be saved to equal roughly 7 days.

Also, can we change ls ~/.tmux/resurrect/* command to:

  • take @resurrect-dir into account
  • be more restrictive and "target only" files in resurrect dir having this format: tmux_resurrect_*.txt. There are options for tmux-resurrect that save other file types in this dir and we never want to delete them.

Thanks!

@michael-coleman
Copy link
Author

Hey cool,
I agree with

  • making deleting old files the default
  • take @resurrect-dir into account
  • using the pattern tmux_resurrect_*.txt to reduce likelyhood of mistakenly deleting the wrong files.

If we want to only delete files older than 7 days - which I think is a good idea - trying to determine the files age based on how many files are present multiplied by the file creation rate - will cause 2 problems that I can see

  1. From what I can tell tmux-contiuum only creates files when tmux is active
  2. If the save rate is changed e.g. from 15 mins to say 1minute

Fortunately this "older than 7 days test" is easy to achieve with

find $default_resurrect_dir -mtime +7 

Where -mtime +7 is only files whose last modification time is older than 7 days.
Ive tested this command successfully on OSX yosemite (Using Sauce Labs) and I believe its quite POSIX compliant.
So I'm thinking the final command should look something like

find $default_resurrect_dir -type f -mtime +7 -name "tmux_resurrect_*.txt" -exec rm -f {} +

If that sounds good to you, I'll work it into the code and re-submit

@michael-coleman
Copy link
Author

Have now implemented the discussed changes.
These 2 commits make deleting saves older than 7 days the default behaviour for tmux-continuum.
If users want to keep files older than 7 days, they would need to add the following into ./tmux.conf

set -g @continuum-keep-old-saves-option 'on'

I have tested this as working on Ubuntu 14.04 for the following

  • deleting files older than 7 days from the default ~/.tmux/resurrect directory
    Tested by creating dummy files and then setting modified date e.g. touch -t "1511220101" tmux_resurrect_2015-11-22T01:35:27.txt
    .
  • deleting files when using a custom dir via @resurrect-dir
    e.g. set @resurrect-dir to /tmp/resurrect_test
    .
  • keeping old saves, i.e. not running the delete_old_files function when the @continuum-keep-old-saves-option 'on' option is set.

@christarazi
Copy link

Will this be merged? Is there anything else that needs to be addressed? I am willing to contribute.

@michael-coleman
Copy link
Author

@christarazi
Yes it would be nice if this got merged, I'm currently running the tmux-continuum without this branch because its a bit too much hassle to clone from my repo then fetch and rebase onto new commits from the upstream master. Have you fetched this branch and tested the code? If so

  • did it work?
  • what OS are you running?

If we can get the code working across as many OS'es as possible, it might help to get it moving forward.

@christarazi
Copy link

christarazi commented Jun 13, 2016

@michael-coleman

I will test it over the next few days. I will let you as soon as possible. I modified the command to delete files older than 1 day, so that I don't have to wait a week to get back to you on the results.

By the way, I am running Arch Linux.

Edit: @michael-coleman It works perfectly for me. The command I'm using is

$ find ~/.tmux/resurrect -type f -name "tmux_resurrect_*.txt" -mtime +0

which is basically deleting the resurrect files that are older than 24 hours.

@thesauravmitra
Copy link

@michael-coleman @bruno- How is this branch looking?
The FAQ seems to suggest that last is a symlink.
One possible concern with the logic (as I understood by reading the comments here) is if I take a break from my computer (like that ever happens), and then go back after a week to open tmux, and since even my most recent save was more than 7 days ago, the file will be deleted, and I will have nothing to restore to. If last is a hard link, then that issue shouldn't occur, I believe.

@bruno-
Copy link
Member

bruno- commented Jun 4, 2017

Hey guys,
a similar PR was merged just yesterday to tmux-resurrect link. It deletes resurrect files older than 30 days but always keep at least 5 backups.

Can you check that one and close this PR if all the features are there?

@christarazi
Copy link

@bruno- The one major difference I spotted was that this pull request has an option to enable deleting backups, while the other one does not. I think it would be more useful for people to have an option. I don't mind doing a pull request myself, just would like to hear your opinion before starting. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants