How to delete files older than X on backup during sync?
matt at mattmccutchen.net
Sun Nov 9 15:34:32 GMT 2008
On Sun, 2008-11-09 at 03:18 -0500, Matthew Monaco wrote:
> Thomas von Eyben wrote:
> > I wish to use rsync to create a backup BUT only keep the files for a
> > limited period of time, EG two weeks.
> > I have not yet been able to figure out how to do this inside rsync
> > (while the backup is being performed) and my understanding of the
> > "--delete" flag is not for this wish.
> > My plan is - unless I find out that it indeed is possible with rsync -
> > to make a cronjob removing files older than X in the folder containing
> > the backups…
> You can do something like
> "rsync OPTIONS --rsync-path="find /root-dir/ -mtime +14 -delete ; rsync"
> SRC DEST"
If you count the two-week period from the mtime of the file, then
backups of really old files will be deleted as soon as they are saved.
I think it would make more sense to count from the time the backup file
is saved. To do that, use a separate --backup-dir each day (e.g.,
--backup-dir=../backups/$(date +%Y-%m-%d) ) and simply delete each
backup dir as a whole when it becomes two weeks old.
The only disadvantage is that with multiple backup dirs, it becomes less
trivial to find backups of a particular path, but it would be easy to
write a script to help with this.
More information about the rsync