Skip to main content

How to use cwRsync and rsnapshot to sync from Windows to Linux

The rsync logo
Here is how to sync files from Windows to Linux with rsync. Specifically, using cwRsync server (a Cygwin + rsync package) on the Windows server, and rsnapshot on the Linux backup server. [3 minutes]

Windows Server Setup

First download the cwRsync server package and install it on the Windows server. It will attempt to create a service user for cwRsync, but the user creation did not work for me. Rather specify the name and password of an existing service account (specially-created if necessary) for RsyncServer service to run as. Use the services panel to configure RsyncServer to run automatically on boot. Before starting the service, configure the rsyncd.conf along these lines:

uid = 0
gid = 0
use chroot = false
strict modes = false
hosts allow = backups.example.com
log file = rsyncd.log

[examplemodule]
path = /cygdrive/c/example/path/to/back/up
read only = true
transfer logging = yes

The uid=0 and gid=0 must be added to avoid the @ERROR Invalid UID nobody. The hosts allow line is to only allow the backup server to access the data. Configure rsync modules for each local resource to back up, using Cygwin paths (/cygdrive/c). You can test the rsyncd.conf by running rsync from the cwRsync "ICW" directory in Program Files and attempting to rsync from it on the Linux server:

bin\rsync.exe --config=rsyncd.conf --daemon --no-detach

Linux Server Setup

On the Linux backup server, install rsnapshot. By default there are 6 hourly snapshots (one every 4 hours), 7 daily snapshots, 4 weekly snapshots and 3 monthly snapshots. Add to /etc/rsnapshot.conf a line like this to get data from the windows server. Type tabs between the items, not spaces.

backup    rsync://windowsbox.example.com/examplemodule     windowsbox

Also config the snapshot_root to where you want the files to go. The awesomeness of rsnapshot is that it uses the rsync --link-dest option: as it creates the new snapshot it detects unchanged files from the previous snapshot and hardlinks back to them. Thus, you get complete snapshots using only an incremental amount of space. To view the files as they were 3 days ago, visit the daily.3 directory under "windowsbox" in snapshot_root.

P.S. These steps were tested with rsync 3.0.7 and rsnapshot 1.3.1 on Linux (CentOS 5.4), and cwRsync 4.0.4 (includeing rsync 3.0.7) on Windows (Server 2008).

Do you have a better way to regularly backup Windows files to a Linux server? Comment below!

Comments

  1. Thank you. Your notes were very useful especially the part about uid=0 and gid=0.

    ReplyDelete
  2. Many thanks from me too, I'd been trying to get rsnapshot working on the wifes XP box without any luck until I read:
    "The uid=0 and gid=0 must be added to avoid the @ERROR Invalid UID nobody"

    entered those into the rsyncd.conf and bingo!

    ReplyDelete
  3. You're both welcome, I'm glad people are finding my how-to useful!

    BTW, we had a relatively slow link to the production box and a lot of changing data so we had to slow rsnapshot to a 12 hour interval instead of the default 4 hours to avoid starting - and crashing - a second backup while the first one was still going:

    Edit /etc/rsnapshot.conf to set "interval hourly 2", and edit /etc/cron.d/rsnapshot to set "10 */12 * * *" for the hourly schedule.

    ReplyDelete
  4. Out of the box, I couldn't get the server to start for me either. So I went into "Services" on the Windows machine, copied and re-pasted the password for "SvcCWRSYNC" (I had made note of the credentials when I installed the server), and the server finally started.

    Hope this helps someone.

    ReplyDelete

Post a Comment

Popular posts from this blog

How to learn the Colemak keyboard Layout

Here are my tips on learning the Colemak keyboard layout to reduce finger joint pain. From my experience I also compare it to the regular QWERTY layout. [3 minutes]

The keys to doing long-form Narrative Improv

Here are some key ingredients for full-length improvised plays known as Narrative Improv. Providing tips on story structure, normalcy, the protagonist, consequences and clarity. [4 minutes]

Declutter your home with the Outbox Method

Here are some easy ways to reduce the clutter at home by means of an "Outbox". It's a box for things that you think you might not need, that you then periodically empty. [4 minutes]