How to delete files older than X on backup during sync?

Thomas von Eyben thomasvoneyben at gmail.com
Sun Nov 9 18:03:57 GMT 2008


On Sun, Nov 9, 2008 at 4:34 PM, Matt McCutchen <matt at mattmccutchen.net> wrote:
> 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.
>
> Matt
>
>

Actually, I think I need to be a little more specific (now I think
about it): I only want to keep the files that are deleted on the
source for the additional period of two weeks.

So I want to keep the back up identical to the source, just not
deleting files in the backup that are deleted in the source (should be
fairly easy with rsync ;-) BUT I  only want to keep these
deleted-on-source files for an additional period of two weeks…

- TvE


More information about the rsync mailing list