1. Differential Copy of Files: Only changed pieces of files are transferred and not complete files.
2. Compression: Before transfer the files are compressed to save transfer time
3. Secure Transfer: ssh is used. Even rsh can be used.
It is an excellent choice as a backup and mirroring tool.
Here is a very High level view of Rsync... It shows that once an rsync server has been setup any number of clients who has rsync installed can synchronize to/from this server.
Installing RSync Server:
1. Download RSync Server Binaries from here.
or
Debian or Ubuntu:
# apt-get install rsync
or
$ sudo apt-get install rsync
Red Hat Enterprise Linux (RHEL)
# up2date rsync
CentOS/Fedora Core Linux
# yum install rsync
2. Setup the RSync Configuration File. We will see shortly how the configuration file looks like and what changes we need to make.
3. Run RSync in Daemon mode.
Here is the command to run rsync in Daemon Mode:
rsync -v -v --no-detach --daemon
Dissecting the Configuration File:
So here is how the configuration file looks like.. It is located in /etc/rsyncd.conf... In not you should create one.
#/etc/rsyncd.conf
motd file = /etc/rsyncd.motd
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
[my_path]
path = /rsync_files_here
comment = My Rsync Server
uid = nobody
gid = nobody
read only = no
list = yes
auth users = username
secrets file = /etc/rsyncd.scrt
hosts allow = *.xyz.com
hosts deny = *
list = false
motd file: Is actually a Message of the day. Anything contained in this file will be displayed when clients connect to this machine.
log file: Specifies Log file where diagnostic and runtime messages are sent.
pid file: Contains the Process ID number of the running rsync daemon.
lock file: Ensures things run smoothly.
All of the above 4 are global to the rsync daemon.
Let's have a look at other options available:
- path - Actual filesystem path where the files are rsync'ed from and/or to.
- comment - Any useful comment you wanna put.
- auth users - you really should put this in to restrict access to only a pre-defined user that you specify in the following secrets file - does not have to be a valid system user.
- secrets file - the file containing plaintext key/value pairs of usernames and passwords.
- hosts allow - IPs or hostnames that you wish to specifically allow or deny!
- hosts deny - IPs or hostnames that you wish to specifically allow or deny!
An Example of executing RSync Client to Transfer files:
rsync --verbose --progress --stats --compress --recursive --times --perms --links --delete /mysourcedir/* myservername:/mydestinationdir
--verbose : Tells that you want to see the progress display of what is being executed
--stats : Shows you the complete status after execution is finished
--recursive : Iterates through the directory and copies all files from/to within the directories
--perms : Preserve permissions
--times: Preserver timestamps on the file
--links : Copy symbolic links with links
/mysourcedir/* : To copy all files from this source directory.
myservername:/mydestinationdir : Destination directory on the server where files will be transferred.
rsync common options
- --delete : delete files that don't exist on sender (system)
- -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
So that was the Basic Rsync Stuff... We will dig deeper into using RSync in upcoming articles.
No comments:
Post a Comment