Copias de Windows con rsync sobre servidor linux
Como siempre, os dejo aqui cosas que encuentro interesantes y que pruebo.
La idea es tener un servidor linux al que mediente rsync se conecte un servidor windows para disponer de una copia de los ficheros. Esta copia solo se realiza sobre los documentos que han cambiado. Algo más que interesante para ahorrar en ancho de banda.
Set up rsync server on Ubuntu
- Run
sudo apt-get install rsync(it’s probably already installed) - Create a file named rsyncd.conf in /etc
-
sudo nano /etc/rsyncd.conf
- Add the following to rsyncd.conf, replacing all instances of
usernamewith your Ubuntu username:[usernamebackup] path = /home/username/backup comment = Backup uid = username gid = username read only = false auth users = username secrets file = /etc/rsyncd.secrets -
sudo chmod 644 /etc/rsyncd.conf
-
- Create a file named rsyncd.secrets in /etc
-
sudo nano /etc/rsyncd.secrets
- Add the following to rsyncd.secrets, replacing
usernamewith your username andpasswordwith a password of your choosing:username:password
-
sudo chmod 600 /etc/rsyncd.secrets
-
- Open rsync port by editing /etc/default/rsync and setting
RSYNC_ENABLE=true
- Restart rsync
sudo /etc/init.d/rsync restart
Set up rsync client on Windows
- Install Cygwin, making sure Editors > nano and Net > rsync are selected
- Add
C:\cygwin\bin;to the Windows PATH statement- Right-click on My Computer and select Properties
- Switch to the Advanced tab and click the Environment Variables button at the bottom
- Find the “Path” or “PATH” variable in the System variables list at the bottom and click Edit
- Add
C:\cygwin\bin;to the beginning of the list
- Create secret file to store password in Cygwin
- Start Cygwin Bash Shell
- Create secret file in the filesystem root and enter only the password in rsyncd.secrets above, with no spaces or line breaks
nano /secret
-
chmod 600 /secret
-
chown Administrator:SYSTEM /secret
- Create bat file to run rsync
- Open Notepad and enter the following command, replacingUser Name with your Windows User Name directory,username with your Ubuntu username, and ipaddresswith the IP address of your Ubuntu server (e.g. 192.168.0.100):
C:\cygwin\bin\rsync.exe -qrtz --password-file=c:\cygwin\secret --delete "/cygdrive/c/Documents and Settings/User Name” username@ipaddress::usernamebackup
As you may have guessed, the
"/cygdrive/c/Documents and Settings/User Name"command line option designates where to start backing up from. As currently configured, this will backup your Windows home directory (Desktop, My Documents, etc). If you want to backup your whole hard drive, change that option to"/cygdrive/c". - Save the file as C:\rsync.bat
- Open Notepad and enter the following command, replacingUser Name with your Windows User Name directory,username with your Ubuntu username, and ipaddresswith the IP address of your Ubuntu server (e.g. 192.168.0.100):
Create scheduled task to run C:\rsync.bat once a day
- Create scheduled task
- Goto Start > Programs > Accessories > System Tools > Scheduled Tasks
- From the File menu, select New > Scheduled Task
- Name this task “rsync backup”
- Right-click on the task and select properties
- Enter
C:\rsync.batin the Run field - Switch to the Schedule tab and select the time you want the backup to run every day and click Ok
- Test the scheduled task
- Create a folder called C:\data and put a few photo files in it
- Edit C:\rsync.bat and change
"/cygdrive/c/Documents and Settings/User Name“to"/cygdrive/c/data" - Add the command
pauseon a new line at the bottom of C:\rsync.bat and save the file - Right-click on the “rsync backup” scheduled task and select “Run”—A command window should popup and with either errors or the list of files being transfered. If there are errors, troubleshoot them.
- Once the scheduled task and C:\rsync.bat appear to be working correctly, change
"/cygdrive/c/data"back to"/cygdrive/c/Documents and Settings/User Name“and remove thepausecommand - Finally, edit the scheduled task properties and change “Run as:” to
NT AUTHORITY\SYSTEM—this will ensure that the process runs in the background, without popping up a command prompt window
Run your first backup
Run C:\rsync.bat from the command line before going to bed. Backing up 35GB over a wireless-g connection took me over 8 hours. Subsequent backups take less than a minute. Behold the beauty of rsync.
Update: for information on how to backup Ubuntu to Ubuntu (or Linux to Linux really) using rsync with passphraseless keys, check out Playing with rsync on Ubuntu.