# rsync over ssh sync directories



## Understudy (Jan 26, 2013)

Hi,

I want to take my computer1:/home/user1 (client) and sync it with computer2:/home/user1 (server). The users have the same UID. The directories are basically the same because I have been doing *cp -Rpv* by mounting it over NFS.

Here is what I would like to do. 

I would like rsync to update the newer files and directories and copy them to computer2. I would like to do it over ssh because I am not going to be able to NFS to the box for a bit. So I am going to set up ssh. I would like to make it a cron job in the end. 

sshd is already on computer2.

So here is what I understand has to be done. 

1. Install the port for rsync on computer1 and computer2.
2. computer2 (server) 


```
ee /usr/local/etc/rsyncd.conf
```


```
uid = nobody
gid = nobody
use chroot = no
max connections = 4
syslog facility = local5
pid file = /var/run/rsyncd.pid
```

Setup rsync dameon to run on boot


```
# echo "rsyncd_enable=YES" >> /etc/rc.conf
```

And start rsync


```
# /usr/local/etc/rc.d/rsyncd start
```

3. computer1 (client)


```
rsync -av home/user1/ user1@computer2:~home/user1  <-- I think
```

This is what I have so far. I am hoping someone can take a look and tell me if I have made mistakes already.

Sincerely,

Brendhan


----------



## Davsjo (Jan 26, 2013)

As I've understood it, if you run rsync against rsyncd, the connection won't be using ssh. To use ssh you must have rsync connect using a shell (through ssh). I would suggest running rsync over ssh using a key file.


----------



## wblock@ (Jan 26, 2013)

Yes, set up keys for passwordless SSH login.

The paths shown are not quite right.  ~ refers to the user's home directory, probably /usr/home/user1.

For an important note, see
`% man rsync | less -p'trailing slash'`

rsync(1) options are important to avoid surprises.  If you copy hard linked files without -H, it copies each link as a new file and the directory gets much larger.

PS: Understudy, I did not edit post #1.  There are opportunities to do so.  Please consider finding them a puzzle.  Hint: when you mention a filename, path, or hostname in text, it should be in [file] tags.


----------



## zeebee (Oct 17, 2013)

*You actually can connect to a rsync deamon via a remote shel*

It is possible to connect to an rsync deamon via a remote shell. Or, more correctly put, to obtain rsyncd features when invoking `rsync --rsh="ssh"`. There are a few restrictions that apply to this situation:


a separate rsyncd.conf file has to be placed in the home directory of the server user you want to connect to.

`use chroot = no` has to be applied explicitly in all modules in this rsyncd.conf. This is due to the fact that a rsync deamon will be spawned with the permissons of the user you login to and `use chroot = yes` requires root privileges.

There is no need to activate rsyncd in /etc/inetd.conf or run an rsync deamon in the background (e.g. via /etc/rc.conf) for this feature to work.

This behaviour is described in `man rsync` under section 





> USING RSYNC-DAEMON FEATURES VIA A REMOTE-SHELL CONNECTION


----------



## mix_room (Oct 17, 2013)

I run the following: `rsync -rvaz -e ssh /home/$USER $USER@$REMOTEHOST:/home/$USER`. To sync directories using rsync over SSH. I have not installed the rsync-daemon on any machine, only the normal binaries. Works very well when running from cron with SSH-keys.


----------



## phoenix (Oct 18, 2013)

This may not be applicable for moving home directories around, but it definitely is when using rsync for backups purposes, especially when backing up FreeBSD systems. You need the following options enabled:

--hard-links: without this, directories like /rescue will balloon out to  over 1 GB as each file in there is actually a hard-link to a single file, but rsync will create separate copies of each binary
--numeric-ids: unless your /etc/passwd and /etc/group are exactly in sync on every machine you run rsync on, you can end up with strange ownership on files

Without the above, we found using rsync to back up and restore a FreeBSD system lead to terrible screams and much gnashing of teeth and rending of sackcloth.


----------



## Understudy (Oct 30, 2013)

How it ended up working:


 Set up ssh with keygen and no password between client and server
 Change the ssh port since it is a public IP
 Create file sync.sh


```
/usr/local/bin/rsync -avz --rsh='ssh -p22' /usr/home/bhorne/  bhorne@192.168.1.1:/usr/home/bhorne/ >> /tmp/var/log/sync.log
```
IP address and ports have been changed to protect the guilty. 
 Set up a cronjob with `crontab -e`

```
# Min(0-59) Hour(0-23) Day(1-31) Month(1-12) Wkdy(0-6)  Command
    00          3          *         *           *      /usr/home/bhorne/sync.sh
```

And so with that I can use mutt to make sure everything worked. I can checked the logs if it didn't.

Sincerely,

Brendhan


----------

