Skip to main content

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Asked
Viewed 10k times
5

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?

6
  • 1
    Slightly more readable than find | rsync, at least for me, is rsync --files-from=<(find /path/to/files/ -type f -newer "datestamp" -print0). Can't speak to why --delete isn't deleting, it certainly should be.
    DopeGhoti
    –  DopeGhoti
    2016-02-22 19:20:24 +00:00
    Commented Feb 22, 2016 at 19:20
  • 2
    The files are not deleted because you are comparing existing (on the source) files only with your 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 with find but need to include directories (i.e. get rid of the -type f option.
    FelixJN
    –  FelixJN
    2016-02-22 19:21:42 +00:00
    Commented Feb 22, 2016 at 19:21
  • @Fiximan - I had thought of this myself, but if I do as you suggest - namely, include directories in find (by suppressing the -type f option) - rsync will backup files that are older than DATE-OF-LATEST-BACKUP.
    juanriccio
    –  juanriccio
    2016-02-22 19:31:25 +00:00
    Commented Feb 22, 2016 at 19:31
  • I see. AFAIK rsync is at its boundaries then. Well, you could do it in two steps then and run a script using diff local_dir remote_dir (after selecting the dirs with your find command and the -newer restrictions) and search for files that are only in the remote_dir, then remove them selectively.
    FelixJN
    –  FelixJN
    2016-02-24 19:45:08 +00:00
    Commented Feb 24, 2016 at 19:45
  • 2
    Yes, I guess I'll have to do it in two steps. First build a list, appending a / to directory names, 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 files rsync --files-from=<(grep "[^/]$" files_and_dirs)
    juanriccio
    –  juanriccio
    2016-02-25 01:54:02 +00:00
    Commented Feb 25, 2016 at 1:54

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.