Skip to content

rsync

installation

normally apt-get install rsync will take care of all parameters for you, but in case you have a disabled installation (like the one in turnkey linux (redmine)) you can do this :

edit the file /etc/defaults/rsync and alter the ENABLE line to :

/etc/defaults/rsync
RSYNC_ENABLE=true

to be sure enable the startup scripts with :

enable
update-rc.d rsync defaults

it will tell you if it was needed or not.

When you start rsync

start
/etc/init.d/rsync start

It will probably complain about /etc/rsyncd.conf so :

rsyncd.conf

You will need this file, so start out with the example one.

conf file
cp /usr/share/doc/rsync/examples/rsyncd.conf /etc

Now edit it to your needs, for instance add a new share :

/etc/rsyncd.conf
1
2
3
[myshare]
comment = my new share
path = /

Restart rsync

restart
/etc/init.d/rsyncd restart

You can view the status from any rsync host with :

server status
rsync rsync://servername/

You will get something like :

output
ftp    puclic archive
myshare my new share

usage

rsync can just be used as scp with some extra's for instance you can use it to resume a copy operation.

rsync without destination parameter just lists the source and without protocol uses ssh so :

list source
rsync remote_host:/home

will list the home directories if of course you have the rights.

copy remote to .
rsync -r remote_host:/home/kees .

will attempt to copy the complete home directory of kees to the current directory. but if you stop that half way and do it again it will start all over, like scp would. using -a, it will resume where it left, also see -v for some progress information.

resumes when interrupted
1
2
3
rsync -avr remote_host:/home/kees
ctrl-c
rsync -avr remote_host:/home/kees

Finally, to really sync and also delete the files that where deleted on the other side, you use the --delete flag. Caution is advised here, since delete is a very fast operation and could wipe a lot of files if you make a small typo. (one slash will do the trick). So just run a normal sync, see what happens and then add the delete flag:

-rav
rsync -rav remote:dir .
rsync -rav --delete remote:dir .

Also, if you think timestamps are off, you can do it without checking times, and only use sizes with the --checksum parameter:

checksum
rsync -rav --checksum remote:dir .

However, it seems not do copy much but still take a lot of time deciding not to copy. A comparison with using compression gave :

using a different port

If you are using the protocol the port number can be included in the url, but with ssh it defaults to 22 always. There is however a way to get it onto another port :

different port
rsync -ravz -e "ssh -p 2222" user@example.com:/files/ /local/files/

size only

The default algorithm takes into account time stamp and size to decide whether to copy a file or not, if you don't trust the time stamps you can also do size only . For instance copying the mp3 tagged dir to a second location :

faster to check sizes
cd /data/tagged2
rsync -arv --size-only ./ servert:tagged2

This will only copy the newly added mp3's to the directory on servert.