quick rsync how to…
Working in Linux servers sometimes makes it inevitable to use rsync to move and synchronize files from one server to another. This is where rsync excels as it does not only moving of files but also incremental synchronization between two servers. It's also great tool to backup files to a remote server when used in conjunction with cron to automate it. Most new installation may not have it installed on their boxes, in debian it is as easy as typing
apt-get install rsync
to install the latest version.
Once installed you'll need two servers to properly test it. First of all, as you are accessing other server you will need an account on all servers. Also, since rsync doesn't have secure transfer by default, make sure to install open-ssh on both servers to transfer files securely.
Some common options are:
- --delete : delete files that don't exist on sender (system) (Use with caution!!!)
- -v : Verbose (try -vv for more detailed information)
- -e "ssh options" : specify the ssh as remote shell
- -a : archive mode
- -r : recurse into directories
- -z : compress file data
- progress: will show the percentage of the file copied
Example commands:
Copy files from local server to remote server
$ rsync -v -e ssh /[local folder]/[local file] [remote.user]@[remote.server]:~
Copy files from remote server to local server
$ rsync -v -e ssh [remote.user]@[remote.server]:~/[remote.file] /[local.folder]
Synchronize directories from local server to remote server
$ rsync -r -a -v -e "ssh -l [remote.user]" [remote.server]:/[remote.directory]/ /[local]/[directory]
Synchronize directories from remote server to local server
$ rsync -r -a -v -e "ssh -l [remote.user]" [remote.server]:/[remote.directory] /[local]/[directory]
There other features such as excluding files while syncing and mirroring folders. Also, this process can be easier if password less authentication is set up between two servers. However, most of the basic use is covered above.