Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm running 2 ubuntu 9.10 servers. I have to synchronize the changes between these two machines. The following are the directories I've to synchronize:

/usr, /etc, /var, /bin, /sbin, /lib

I'm using rsync like the below for replication:

rsync -avP 192.168.2.100:/usr/ /usr

rsync -avP 192.168.2.100:/etc/ /etc ------here I'll have to exclude many files like /etc/udev/*, /etc/hosts, /etc/hostname,...

I tried using rsync -avP --exclude '/etc/fstab' 192.168.2.100:/etc/ /etc but it overwritten entire /etc directory

Can any one edit and give me rsync to one line command which synchronizes specified directories and not which are excluded?. Need help!

share|improve this question
    
To get full list rsync options by typing man rsync | col -b >filename.txt or .pdf –  joe1983 Oct 30 '11 at 13:25

4 Answers 4

The exclude pattern is relative to the source files, not the destination files. You're actually excluding 192.168.2.100:/etc/etc/fstab, which does not exist.

You should use:

rsync -avP --exclude '/fstab' 192.168.2.100:/etc/ /etc
share|improve this answer
    
And to complete Adam's answer, you would probably find useful to define your exclusions in a separate file The syntax is : --exclude-from 'yourfile' yourfile contains list of files and folders to exclude (one pattern per line) –  teo96 Nov 15 '10 at 13:00
    
@Adam:Oops!. It works. –  user3215 Nov 15 '10 at 13:15
    
@Bubblegum: so I can use --exclude-from 'filename' for multiple files & directories. Is it possible to sync multiple directories(/etc, /usr, /home) in one rsync command with excludes?. –  user3215 Nov 15 '10 at 13:19
    
@user3215: What you're asking here is close to this question at unix.SE. Hopefully my rsync include/exclude summary can help you. –  Gilles Nov 15 '10 at 22:42
1  
@Adam: The exclude pattern is relative to both the source and the destination paths. Note that --exclude 'fstab' excludes all files and directories called fstab anywhere; to only exclude /etc/fstab and not /etc/foo/fstab, use --exclude '/fstab'. –  Gilles Nov 15 '10 at 22:44

You should use something like this:

$ sudo rsync "$backup_options" --log-file="$backup_log_file" --include-from="$backup_incl_from_file" --exclude-from="$backup_excl_from_file" "$backup_src_folder" "$backup_dest_folder"

where the text file $backup_incl_from_file should include:

usr/***
etc/***
var/***
bin/***
sbin/***
lib/***
...

and the text file $backup_excl_from_file should include:

etc/udev/
etc/hosts
etc/hostname
...

In this example

backup_src_folder="192.168.2.100:/"
backup_dest_folder="192.168.2.101:/"

It's important you read the rsync man page before you use this example to meet your needs, paying special attention to the INCLUDE/EXCLUDE PATTERN RULES section.

share|improve this answer
    
It overwritten every thing. Don't know where I did mistake. –  user3215 Nov 16 '10 at 11:37
up vote 0 down vote accepted

The following is the rsync command to sync multiple directories in one-line and is worked for me. Please let me know if it is the right way to use.

This should be run on SOURCE system:

rsync -avP --exclude 'udev' --exclude 'hosts' --exclude 'hostname' --exclude 'any-account-under-home' /etc /home /usr /var /lib /bin /sbin 192.168.2.100:/

We can exclude many files/directories from specified directories.

If we have a file with the same name let say 'test' under /etc/ and /home and you want to exclude this file only from /etc, then placing a exclude entry excluding 'test' from all .

share|improve this answer

Try this in the Advanced Options window to exclude a directory and its sub directories

--exclude "/user/pathtodirectory*/" where 'user' is your user name and 'pathtodirectoy' is the the directory you want excluded, along with all its sub directories. Make sure you include the double quotes and forward slashes.

Example: --exclude "/johndoe/downloads*/"

Tested on both Ubuntu 14.04 and Ubuntu Gnome 14.04.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.