It’s good for deploy as well.
It can be used locally (like this: rsync -aHvzO –progress staging/ www/).
Very useful to move big amount of data over the Internet because of its incremental feature.
By default it uses SSH for transfering data.
Probably you would like to perform an automatic SSH login (without entering the password). For doing that, read the related article.
Installation and creation of a dedicated account
yum install rsync
/usr/sbin/adduser backup_user
/usr/bin/passwd backup_user
Uses
You can use rsync as a server/client application or ‘on-demand’ basis.
In the first use, there will be a server machine in which there is rsync running as a server. You can run it as a stand-alone server (using rsync –daemon) or using xinetd. See the attachment at the end of this article or visit this URL: http://transamrit.net/docs/rsync/ to see how to set up the server. In this case, the server will have some shares (something like repositories) and a client can use them.
In the second use, on the destination machine there won’t be a rsync running. You need just to install rsync to use this mode. This second one is the more likely method you will use unless you want to create some public repositories.
The command on the source system is pretty much the same in both the modes, but the way to define the destination URL is slightly different.
Some examples of ‘on-demand’ use – Good for backup
This will back up some local directories on the server vps.
rsync -rlDzC --progress --delete -e 'ssh -p 233 -l backup_user' /mnt/data/penny/ vps:/home/autobck/total_penny/ rsync -rlDzC --progress --delete -e 'ssh -p 233 -l backup_user' /mnt/data/foto/ vps:/home/autobck/photos/
- The option -O prevents an error (probably creating a new directory remotely) from happening.
- As SSH is already used for transport by default, you don’t need the -e option. You do need it if the port of the SSH server (running on the destination machine) is not the standard one or if the user you want to use for the SSH session is not the one you are logged in locally
- vps is an entry in your /etc/hosts file associated with the ip of the remote system
Some example scripts:
Backing up from local machine to remote backup server (with the same user):
#!/bin/bash
export RSYNC_RSH=/usr/bin/ssh
dest=backup1
user=$(whoami)
cd || exit 1
rsync -aHvz --progress --delete . "${user}@${dest}:."
[-z -> to compress, not necessary in LAN]
[-b -> backup of the already exisitng destination files]
[--delete keeps the two copies perfectly in sync, by deleting deleted files]
SSH is useful just if you send data over the Internet.
Listing the files on the backup server:
#!/bin/bash
dest=server1
user=$(whoami)
cd || exit 1
rsync “${user}@${dest}:.” | more
Restoring (the script runs locally):
#!/bin/bash
dest=server1
user=$(whoami)
cd || exit 1
for file in “$@” ; do
rsync -aHPvz “${user}@${dest}:./${file}” “./${file}”
done
For restoring, you simply run the script, passing the names of the files to be restored as arguments on the command line.
We can also restore all the files at once by using a dot as the filename
