--files-from= and --delete corrent options

Matt McCutchen matt at mattmccutchen.net
Wed Sep 24 01:47:40 GMT 2008


On Mon, 2008-09-22 at 15:43 +1000, j at mesrobertson.com wrote:
> I am running the following command to backup a specific file from
> /tmp/BACKUPFILE which contains the name "Friday2008-09-19.bkf".
> 
> rsync -ah --delete --numeric-ids --stats --delete-excluded
> --files-from=/tmp/BACKUPFILE /var/data/shares/vmbackups/
> /mnt/usb_backup/SFSYDVS01/daily.0/VM/
> 
> The name in /tmp/BACKUPFILE changes each day for example when next run it
> will be "Monday2008-09-19.bkf" I use a script before running rsync to
> obtain the most recently modified file from /var/data/shares/vmbackups/ and
> cat it into /tmp/BACKUPFILE.
> 
> I want the /mnt/usb_backup/SFSYDVS01/daily.0/VM/ directory to only ever
> contain the most recent backup file e.g.
> 
> root at sfnas01:~# ls -t1 /var/data/shares/vmbackups | head -n 1 >
> /tmp/BACKUPFILE
> root at sfnas01:~# rsync [CORRECT OPTIONS] --files-from=/tmp/BACKUPFILE
> /var/data/shares/vmbackups/ /mnt/usb_backup/SFSYDVS01/daily.0/VM/
> root at sfnas01:~# ls /mnt/usb_backup/SFSYDVS01/daily.0/VM/
> Friday2008-09-19.bkf
> 
> Skip to next day.....
> 
> root at sfnas01:~# ls -t1 /var/data/shares/vmbackups | head -n 1 >
> /tmp/BACKUPFILE
> root at sfnas01:~# rsync [CORRECT OPTIONS] --files-from=/tmp/BACKUPFILE
> /var/data/shares/vmbackups/ /mnt/usb_backup/SFSYDVS01/daily.0/VM/
> root at sfnas01:~# ls /mnt/usb_backup/SFSYDVS01/daily.0/VM/
> Monday2008-09-19.bkf
> 
> But currently the command grabs everything in /var/data/shares/vmbackups/
> and so I end up with:
> 
> root at sfnas01:~# ls /mnt/usb_backup/SFSYDVS01/daily.0/VM/
> Monday2008-09-19.bkf Friday2008-09-19.bkf
> 
> I expected the --delete option would have removed Friday2008-09-19.bkf in
> this example (with the --delete option) but it doesn't.  I've read the man
> page and googled a bit but I think i'm getting a bit lost.

The current meaning of --files-from is to restrict rsync to processing
the paths in the list, and rsync deletes extraneous destination files as
part of the processing of the parent directory (assuming -d or -r is
on), so you can't delete unlisted files this way.  See:

https://bugzilla.samba.org/show_bug.cgi?id=3465

Try this instead:

rsync [OPTIONS] --include-from=/tmp/BACKUPFILE --exclude='*'
/var/data/shares/vmbackups/ /mnt/usb_backup/SFSYDVS01/daily.0/VM/

This way, rsync will scan the destination directory for deletions (since
you have -a without --files-from, which implies -r) and will delete the
old files because they are excluded with --delete-excluded.

Matt



More information about the rsync mailing list