I'm trying to use rsync to backup only the files that have been created or changed after a certain date. The reason is that on that date, the whole system has been backed up. However, those global backup files are buried into archives, so they are not accessible for testing when rsync runs.
After a bit of research, manpage reading and trial-and-error I came up with this, which almost works:
find "/directory-to-backed-up/" -type f -newer "<DATE-OF-LATEST-GLOBAL-BACKUP>" -print | \
../rsync -v --progress --log-file=./rsync.log -rlt -z -m --chmod=a=rw,Da+x --delete \
--files-from=- \
--exclude-from=exclude.txt \
/ \
"backuphost.lan::updateback/"
Why "almost"? My problem is that the --delete option fails to delete files no longer found at the source. I suspect this is because the names of files gone missing from the source aren't found by find, so they aren't fed to rsync as arguments.
How can I sync only files newer than a certain date, deleting from the destination in backuphost.lan all the files that are no longer found at the source?
find | rsync
, at least for me, isrsync --files-from=<(find /path/to/files/ -type f -newer "datestamp" -print0)
. Can't speak to why--delete
isn't deleting, it certainly should be.rsync
command and not directory contents. However with every change in a directory's content, the dir's timestamp itself will be changed. So you can run your command withfind
but need to include directories (i.e. get rid of the-type f
option.find
(by suppressing the-type f
option) - rsync will backup files that are older than DATE-OF-LATEST-BACKUP.rsync
is at its boundaries then. Well, you could do it in two steps then and run a script usingdiff local_dir remote_dir
(after selecting the dirs with yourfind
command and the-newer
restrictions) and search for files that are only in theremote_dir
, then remove them selectively.find / \( -type d -printf "%p/\n" , -type f -print \) >files_and_dirs
(GNU find only, I think), then I'll use rsync twice: (1) clean up the disappeared-from-source files running rsync on the directories only,rsync --delete --ignore-existing --existing --files-from=<(grep "/$" files_and_dirs) {...}
(--delete, --ignore-existing and --existing when used together don't copy anything; they just delete files.) (2) rsync the existing filesrsync --files-from=<(grep "[^/]$" files_and_dirs)