top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Exclude a specific directory from rsync on linux?

+1 vote

I am using centos and trying to do an rsync of the entire /var directory, but exclude just the /var/www directory.

So far I've tried these approaches:

rsync -avzp --exclude-from=/var/www /var/ /mnt/var/    
rsync -avzp --exclude=/var/www /var/ /mnt/var/

But neither has worked. Can I get a suggestion on how to get this to happen?

posted Jun 9, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
cd /var
 rsync -avzp --exclude=www/* . /mnt/var
--exclude-from takes a filename as an argument. That filename is expected to contain a list of patterns to exclude.

If your exclude pattern begins with '/', then it matches a filename  immediately within the transfer root. So in this case, "/var/var/www".

Read the "FILTER RULES" and "INCLUDE/EXCLUDE PATTERN RULES" sections of  the manual.

1 Answer

+2 votes
Best answer

There are two things you need to know about:

  1. Your from directory ends with a "/", which, for rsync actually means /*, ie, /var/*. This makes a difference as to where the "root" of your sync is. In this case, the source is multiple files, not a directory. (equivalent to rsync /var/mail /var/spool /var/opt ... /mnt/var)

  2. You need to specify excludes relative to the root. Note that the root is the topmost file / directory from where the sync begins. Thus, if the source is /home/user/directory then, the root is "directory" not /home/user/directory (rsync doesn't even see /home/user).

Best thing is, do a dry run of the sync, and copy paste what you want to exclude. For example:

(a) rsync -aznp /var/ /mnt/var/ # this means copy all files/directories under /var/ to /mnt/var/
sending incremental file list

Now, your exclude patter has to be www/ (or even better, /www/ to avoid things like mail/www/ also being excluded)

(b) rsync -aznp /var /mnt/ # this means copy the directory /var to /mnt/
sending incremental file list

In this case, the exclude pattern is /var/www/

In summary, you have two opttions to get this to work:

rsync -avzp --exclude=/www /var/ /mnt/var/


rsync -avzp --exclude=/var/www /var /mnt/var

answer Jun 10, 2015 by anonymous
Similar Questions
+2 votes

I am used to traditional update-rc.d et all.

Now I wonder how to add a a script that used to called by init.d (with start/sop ..) to the new "service start xx" regime.

All the tutorials I found talk about how to use update-rc.d..

+3 votes

Since last two days one of my CentOS servers has been generating a small spike of outbound traffic every 30 minutes (X:00 and X:30). It's not enough traffic to really cause any notice except for the fact that it is a very regular pattern and it started abruptly at midnight Sunday.

I tried grepping through my firewall logs, but have been unable to find anything useful there either. I don't see any cron jobs that would generate network traffic. Any suggestions how I can go about tracking this down?

+1 vote

I've been asked to give someone sudo rights across an entire environment without the benefit of something like puppet or chef or cfengine et al.

What I've come up with so far is this:

ssh -t miaprbicsra04v sudo -S /bin/echo "rsherman ALL=(ALL) NOPASSWD: /sbin/service /bin/rm /usr/bin/du /bin/df" >> sudo tee /etc/sudoers

Right now that's just to one host, but I plan on substituting a list of hosts once I get farther along. Problem is, the output hangs on the tee command. Not sure why. Any suggestions?

0 votes

How do I add myself as co-owner of a directory? I set up a new apache server and need to transfer files to /var/www/html. The problem is, of course, I've denied root login but don't have sufficient privs to login and transfer files under my username.