How can I get rsync to ignore missing files?

I'm executing a command like the following to several different systems:

$ rsync -a -v [email protected]:'/path/to/first/*.log path/to/second.txt' /dest/folder/0007/.

Sometimes *.log does not exist, and that's OK, but rsync generates the following error:

receiving file list ... rsync: link_stat "/path/to/first/*.log" failed: No such file or directory (2)
done

Is there any way to suppress that? The only way I can think of is to use include and exclude filters, which just seem a PITA to me. Thanks!


Solution 1:

I think the answer to the question is best described in this answer:

https://stackoverflow.com/a/27637277/1236128

--ignore-missing-args

Unfortunately, only later versions have this functionality. I am running RHEL 7 with rsync 3.0.9, which does not seem to have this option.

Solution 2:

To clarify, you would just like to not 'see' the error? For that case you could just redirect the Standard Error Output, but you may end up missing a more serious error that you might want to know of.

Redirect Error Output Example

rsync -a -v [email protected]:'/path/to/first/*.log path/to/second.txt' /dest/folder/0007/ 2>/dev/null

If instead you are looking to only miss the error on a file that doesn't exist, you can't change the rsync *.log filter and you want to avoid using includes, you could wrap it in a script to proceed based on the condition.

Script Example

#!/bin/sh
# Script to Handle Rsync based on Log File Existence
if [ "$(ls -A /path/to/first/*.log > /dev/null > 2&1)" ]; then
     # Log Exists Use This Rsync
    rsync -a -v [email protected]:'/path/to/first/*.log path/to/second.txt' /dest/folder/0007/
else
    # Log Does Not Exist Use This Rsync
    rsync -a -v [email protected]:'path/to/second.txt' /dest/folder/0007/
fi

Hope I was some help.