The FreeBSD Diary |
(TM) | Providing practical examples since 1998If you buy from Amazon USA, please support us by using this link. |
rsync - synchronizing two file trees
15 December 2000
|
This article originally appeared quite some time ago. But for some
unknown reason, it was lost from the indexes. I've just come back to upgrade it with
some new error observations. We now return you to your regularly scheduled read...
This article describes how you can use |
Overview
|
I'll only be looking at copying from a remote rsync server (4) to a local machine and when using a remote shell program (2). |
This was an easy port to install (aren't they all, for the most part?).
Remember, I have the entire ports tree, so I did this:
If you don't have the ports tree installed, you have a bit more work to do.... As far as I know,
you need rsync installed on both client and server, although you do not need to be running rsyncd
unless you are connecting via method 4.
|
Setting up the server
|
In this example, we're going to be using a remote rsync server (4).
On the production web server, I created the /usr/local/etc/rsyncd.conf
file. The contents is based on man rsyncd.conf .
uid = rsync gid = rsync use chroot = no max connections = 4 syslog facility = local5 pid file = /var/run/rsyncd.pid [www] path = /usr/local/websites/ comment = all of the websites You'll note that I'm running
and
Then I started the rsync daemon and verified it was running by doing this:
And I found this in
Then I verified that I could connect to the daemon by doing this:
I determined the port 873 by looking at See the security section for more information. You can also specify a login and user id. But if you do that, I suggest you make
This example is straight from the man page. Add this to the configuration file:
The
And don't forget to hide that file from the world as well:
|
Setting up the client
|
You may have to install rsync on the client as well.. There wasn't much to set up on the client. I merely issued the
following command. The rsync server in question is ducky .
In the above example, I'm connecting to ducky, getting the www collection, and putting it all in /home/dan/test. And I checked the output of my first
See the man pages for more exclusion options. I also wanted deleted server files to be deleted on the client. So I did this:
Of course, you can combine all of these arguments to suit your needs. I found the
|
My transfers are occur on a trusted network and I'm not worried about
the contents of the transfer being observed. However, you can use ssh as the transfer medium by using the following command:
Note that this differs from the previous example in that you have only one : (colon) not two as in
the previous example. See man rsync for details. In this example, we will be grabbing the contents
of ~/www from host ducky using our existing user login. The contents of the remote directory will be
synchronized with the local directory Now if you try an
Here I supplied the wrong password and I didn't specify the user ID. I suspect it
used my login. A check of the man page confirmed this. This was my next
attempt. You can see that I added the user name before the host,
In this case, nothing was transferred as I'd already done several successful The next section deals with how to use a password in batch mode. |
Do it on a regular basis
|
There's no sense in having an rsync set up if you aren't going to
use it on a regular basis. In order to use rsync from a cron job, you should supply
the password in a non-world readable file. I put my password in /home/dan/test/rsync.password .
Remember to chmod 640 that password file!I put the command into a
script file (
Remember to Then I put this into
The above will mail you a copy of the output. If you want to use ssh as your transport medium, I suggest using using the authorized_keys feature. |
My comments
|
I think |
I was recently adding some new files to my rsync tree. I
found these errors:
It took me a while to understand the problem. It's a read issue. If you get the user id for rsync wrong, you'll see this error:
I had the rsync user misspelt as rysnc .
|