rsync --include-from syntax

Latest response

I'm putting together a backup scenario using rsync.
I'm setting it up so I can have cron run a shell script containing an rsync command every night against a list of servers in a separate file and using an include from list in another separate file.
Almost working...
My current issue is that my include-from file currently looks like this:
+ etc/***
+ home/***
+ var/www/***
+ var/spool/mail/***
+ var/lib/mysql/***
+ opt/IBM/***
+ root/***
- *
When the script runs it does not indicate any error, but only syncs etc, home, and root. Anything with a path deeper than one folder is ignored.
I'm sure my syntax must be wrong. Any thoughts?

Responses

You may post the cron command for further help. Just a quick guess, is the recursive option set? I'm sure you would have set it, please post cron job command so that any of the community members would help you....

rsync --archive --recursive --delete --rsync-path="sudo rsync" --include-from ./backup_list -e ssh [user]@[server]:/ /mnt/depot/backup/[server]/

I have not yet created a cron job for it. I'm trying to get it to run from the command line first.

As per the man page of 'rsync'...

If a pattern excludes a particular parent directory, it can render a deeper include pattern ineffectual because rsync did not descend through that excluded section of the hierarchy.  This is particularly important when using a trailing ’*’ rule.  For instance, this won’t work:

              + /some/path/this-file-will-not-be-found
              + /file-is-included
              - *

This fails because the parent directory "some" is excluded by the ’*’ rule, so rsync never visits any of the files in the "some" or "some/path" directories. One solution is to ask for all directories in the hierarchy to be included by using a single rule: "+ */" (put it somewhere before the "- *" rule), and perhaps  use  the --prune-empty-dirs option.  Another solution is to add specific include rules for all the parent dirs that need to be visited.  For instance, this set of rules works fine:

              + /some/
              + /some/path/
              + /some/path/this-file-is-found
              + /file-also-included
              - *

You may have to re-define your include file list. Please check. I've not tested this to see how it works. This may help you.

That is it. Thank You. This works.

$ cat backup_list
+ /var/
+ /var/www/
+ /var/www/***
+ /var/spool/
+ /var/spool/***
+ /var/spool/mail/
+ /var/spool/mail/***
+ /var/lib/
+ /var/lib/mysql/
+ /var/lib/mysql/***
+ /etc/***
+ /home/***
+ /opt/***
+ /root/***
- *

Your explanation above is far better than the manual. I read through the section three times and couldn't make any sense of it.

That is nice, I'm glad that I was able to help you :)

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.