rsync instance Usage

Source: Internet
Author: User
Tags auth chmod rsync
Vi/etc/xinetd.d/rsync
Disable = yes
Change into
Disable = no


Rsyncd.conf is a rsyncd config file.

Vi/etc/rsyncd.conf

#uid = Nobody
#gid = Nobody
Use chroot = yes
Max connections = 4
PID file =/var/run/rsyncd.pid
Lock file =/var/run/rsync.lock
Log file =/var/log/rsyncd.log

[Compshop]
Path =/home/sites/compshop
Auth users = Compshop
UID = Compshop
GID = Compshop
Secrets file =/etc/rsyncd.secrets
Read Only = no

[Datafeed]
Path =/home/sites/datafeed
Auth users = Datafeed
UID = datafeed
GID = Datafeed
Secrets file =/etc/rsyncd.secrets
Read Only = no

[Smtemplates]
Path =/home/sites/smtemplates
Auth users = smtemplates
UID = smtemplates
GID = Smtemplates
Secrets file =/etc/rsyncd.secrets
Read Only = no

[Smarterv2]
Path =/home/sites/smarterv2
Auth users = Smarterv2
UID = Smarterv2
GID = Smarterv2
Secrets file =/etc/rsyncd.secrets
Read Only = no


Rsyncd.secrets is RSYNCD's password file, which is the username and password of the Linux username and password.

Vi/etc/rsyncd.secrets

Compshop:any
Datafeed:any
Smtemplates:any
Smarterv2:any

Above is the server-side configuration, after this service, the port is 873

The following is a client-side configuration file on another computer. The filename can be changed by itself.

Vi/home/sites/sites_rsyncd

#!/bin/bash
RSYNC-TVZRP--progress--password-file=/home/sites/rsyncd.secrets--delete--exclude

/home/sites/compshop/logs compshop@192.168.168.241::compshop/home/sites/compshop/
RSYNC-TVZRP--progress--password-file=/home/sites/rsyncd.secrets--delete--exclude

/home/sites/datafeed/logs datafeed@192.168.168.241::d atafeed/home/sites/datafeed/
RSYNC-TVZRP--progress--password-file=/home/sites/rsyncd.secrets--delete--exclude

/home/sites/smtemplates/logs smtemplates@192.168.168.241::smtemplates/home/sites/smtemplates/
RSYNC-TVZRP--progress--password-file=/home/sites/rsyncd.secrets--delete--exclude

/home/sites/smarterv2/logs smarterv2@192.168.168.241::smarterv2/home/sites/smarterv2/


chmod 744/HOME/SITES/SITES_RSYNCD

Vi/home/sites/rsyncd.secrets

Any

chmod 600/home/sites/rsyncd.secrets

Iii. use of the rsync command
After the rsync server is configured, the Rsync commands can be issued from the client to implement a variety of synchronized

For Rsync has a very
Multi-functional options, here are some common options:
The command format for rsync can be:
1. rsync [OPTION] ... src [src] ... [user@] Host:dest
2. rsync [OPTION] ... [user@] HOST:SRC DEST
3. rsync [OPTION] ... src [src] ... DEST
4. rsync [OPTION] ... [user@] HOST::SRC [DEST]
5. rsync [OPTION] ... src [src] ... [user@] HOST::D EST
6. rsync [OPTION] ... rsync://[user@]host[:P ort]/src [DEST]
Rsync has six different modes of operation:
1. Copy local files and start this when the SRC and des path information does not contain a single colon ":" Separator

mode of work.
2. Use a remote shell program (such as rsh, SSH) to copy the contents of the local machine to the remote machine

。 When DST
This mode is started when the path address contains a single colon ":" Separator.
3. Use a remote shell program (such as rsh, SSH) to copy the contents of the remote machine to the local machine

。 When SRC
This mode is started when the address path contains a single colon ":" Separator.
4. Copy files from remote rsync server to local machine. Starts when the SRC path information contains the "::" Separator

The pattern.
5. Copy files from local machine to remote rsync server. When the DST path information contains the "::" Separator

Move the pattern.
6. List of files for remote machines. This is similar to rsync transmission, but simply omitting the local machine letter in the command

Can be.
Here is an example to illustrate:
# rsync-vazu-progress terry@192.168.100.21:/terry//home
V Detailed Tips
A in archive mode, copy directory, symbolic connection
Z Compression
U only update to prevent local new files from being rewritten, notice both machine clock
-progress refers to the display
The above command is to keep the/home/terry directory on the client 192.168.100.90 and the Terry on the rsync server

Recorded with
Step. This command will require you to enter the password for your Terry account before you perform the synchronization, which is in front of us

In Rsyncd.secrets
defined in the file. If you want to write this command in a script and then execute it regularly, you can make the

With--password-file
Options, specific commands are as follows:
# rsync-vazu-progress--password-file=/etc/rsync.secret
terry@192.168.100.21:/terry//home
To use the--password-file option, you must first create a file that holds the password, specifying

For/etc/rsync.secret.
The content is simple, as follows:
terry:12345
Also modify the file properties as follows:
# chmod 600/etc/rsyncd.secrets
Iv. using rsync to keep file synchronization instances between Linux servers
Now suppose there are two Linux servers A (192.168.100.21) and B (192.168.100.90), Server A
The/home/terry and/home/terry in Server B need to be synchronized, that is, when server A is Chinese

Pieces occurred
After the change, the files in Server B should be changed accordingly.
We use the above method to install Rsync on Server A and configure it as an rsync server, and

Will/home/terry
The directory is configured as an rsync shared directory. Then install rsync on Server B because B is only a client, so

No configuration required.
Then, on Server B, create the following script:
#!/bin/bash
/usr/loca/rsync/bin/rsync-vazu-progress--delete
--password-file=/etc/rsync.secret terry@192.168.100.21:/terry//home
Save this script as atob.sh and add the executable properties:
# chmod 755/root/atob.sh
Then, with the crontab setting, the script runs every 30 minutes. To execute a command:
# CRONTAB-E
Enter the following line:
0,30 * * * */root/atob.sh
Save the exit so that Server B will automatically run the 0 and 30 points per hour

The second atob.sh,atob.sh is responsible for
Keep Server B and server a synchronized. This ensures that all updates to server A are made after 30 minutes, and Server B takes the same
Got the latest information like Server A.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.