Rsync remote Synchronization

Source: Internet
Author: User
Tags inotify rsync options

Rsync remote Synchronization Service

Inotify-Tools for Real-Time Synchronization

NTP Network Time Service

 

######################################## #################

 

I. Rsync remote Synchronization Service

1. Basic operations of rsync Synchronization

 

Format: rsync source document target document

 

Common rsync options

-A: Archive mode, equivalent to-rlptgod

-V: displays detailed information about the synchronization process.

-Z: Enable compression during transmission

-H: Keep the hard connection file

-A: retain the ACL attribute information of the file.

-- Delete: delete a file with a target but no source

-- Checksum: determines whether to synchronize data based on the checksum.

2. Rsync Synchronization

(1) local synchronization of the rsync server

Create synchronization target directory

[[Email protected] ~] # Mkdir/test

[[Email protected] ~] # Rm-RF/test /*

[[Email protected] ~] # Ls/test

[[Email protected] ~] # Rsync-Az/boot // Test

[[Email protected] ~] # Ls/test

Completely synchronize and delete unnecessary files

[[Email protected] ~] # Touch/test. File

[[Email protected] ~] # Rsync-azvn/boot // test -- delete

Sending incremental file list

./

Deleting test. File

........

// Adding parameter n is the result of pre-execution, but it is not actually executed

[[Email protected] ~] # Rsync-AZV/boot // test -- delete

Sending incremental file list

./

Deleting test. File

........

// Remove parameter n and delete it synchronously. Keep the same

 

Note: If the source folder is not followed by/For example:/boot, the entire folder will be synchronized to the target folder, if/boot/is added, all contents in the folder are synchronized.

 

(2) rsync + SSH remote Synchronization

Downlink: rsync [email protected]: local directory of the source directory

Upstream: rsync local directory [email protected]: target directory

Prepare an rsync server (192.168.4.2) and a remote synchronization terminal (192.168.4.3)

Create a test directory on a remote machine

[[Email protected]/] # mkdir/test

Back up the local/etc directory to the remote host

[[Email protected] ~] # Rsync-Az/boot/[email protected]:/test

.........

[Email protected]'s password: // enter the user name and password of the remote machine

[[Email protected]/] # ls/test/

Back up the/boot/directory of the remote host to the local device.

[[Email protected]/] # rm-RF/test /*

[[Email protected]/] # rsync [email protected]:/boot // Test

[Email protected]'s password:

[[Email protected]/] # ls/test/

 

(3) rsync client <==> rsync server

 

Downlink: rsync [email protected]: Sharing name local directory

Upstream: rsync local directory [email protected]: Share Name

1) create a synchronization account file on the server

[[Email protected] ~] # Vim/etc/rsyncd_users.db

Ruser: pwd123

Othername: 123456 // user name and password required for remote user authentication

2) modify the rsync configuration file and set the synchronization directory.

[[Email protected] ~] # Vim/etc/rsyncd. conf

Gid = nobody

Use chroot = Yes

Log File =/var/log/rsyncd. Log

PID file =/var/run/rsyncd. Pin

[Tools]

Path =/usr/src // synchronization directory

Comment = rsync share test

Read Only = Yes

Dont compress = *. GZ *. bz2 *. tgz *. Zip

Auth users = ruser // ruser authentication is required to add the row. Note that the two lines indicate anonymous synchronization.

Secrets file =/etc/rsyncd_users.db // specify the file to be verified

[[Email protected] ~] # Yum-y install xinetd

[[Email protected] ~] # Chkconfig rsync on // The Rsync service is a temporary service.

[[Email protected] ~] # Service xinetd start

[[Email protected] ~] # Chkconfig xinetd on

Verify on a remote machine

 

View the server synchronization Share Name

[[Email protected]/] # rsync 192.168.4.2 ::

Tools rsyncshare Test

Or

[[Email protected]/] # rsync: // 192.168.4.2

Tools rsyncshare Test

 

View the content list of the shared name

[[Email protected]/] # [email protected]: Tools

Password: // enter the password of the shared user name

Or

[[Email protected]/] # rsyncrsync: // [email protected]/tools

Password:

 

Remote Synchronization

[[Email protected]/] # rm-RF/test /*

[[Email protected]/] # rsync-azrsync: // [email protected]/tools // Test

Password:

[[Email protected]/] # ls/test/

Debug kernels

 

######################################## #################

 

Ii. Rsync real-time synchronization (inotify monitoring and triggering)

1. Install inotify-tools software package

[[Email protected] ~] # Tar zxfinotify-tools-3.13.tar.gz

[[Email protected] ~] # Cd inotify-tools-3.13

[[Email protected] inotify-tools-3.13] #./configure

....

[[Email protected] ~] # Make & make install

2. inotifywait tool trigger Verification

Take the monitoring/OPT directory as an example. When the documents under the/OPT Directory change, the corresponding prompt is immediately given.

[[Email protected] ~] # Inotifywait-mrq-e modify, move, create, delete, attrib/OPT

....

/Opt/create, isdir tdir1

/Opt/create file1.txt

/Opt/modify file1.txt

/Opt/delete file1.txt

 

....

3. Trigger Synchronization Based on inotifywait and while Loops

 

[[Email protected] ~] # Inotifywait-mrq-e modify, move, create, delete, attrib/opt \

| While read x y z; do rsync/opt/opt2; done

... // Make some changes to the source directory

 

[[Email protected] ~] # Ls/opt2/

... // View the Real-Time Synchronization result

 

######################################## #################

 

Iii. NTP Time Synchronization Service

 

1. Adjust the ntpd service configuration and start the service

[[Email protected] ~] # Vim/etc/NTP. conf

Restrict 192.168.4.0 mask 255.255.255.0nomodify notrap

// Allow this network segment to use this server as an NTP server

Server 127.127.1.0 // use the local machine as the NTP server

[[Email protected] ~] # Service ntpd restart

[[Email protected] ~] # Date

Tuesday, August 26, 2014 03:04:37 CST

2. test time synchronization on the client.

[[Email protected]/] # date

Wednesday, December 12, 2007 12:12:03 GMT

[[Email protected]/] # ntpdate 192.168.4.2

[[Email protected]/] # date

Monday, August 25, 2014 19:05:51 GMT

3. Add the NTP server address to the NTP. conf configuration file for automatic synchronization.

[[Email protected]/] # Vim/etc/NTP. conf

Server 192.168.4.2

[[Email protected]/] # service ntpd restart

4. Local Time Synchronization

[[Email protected]/] # hwclock // local hardware clock

Monday, June 17, August 25, 2014 seconds-0.686272 seconds

[[Email protected]/] # date 121212122007

Wednesday, December 12, 2007 12:12:00 GMT

[[Email protected]/] # hwclock -- hctosys // synchronize the hardware clock to the system clock

[[Email protected]/] # date

Monday, August 25, 2014 19:10:06 GMT

[[Email protected]/] # hwclock -- systohc // synchronize the system clock to the hardware clock

[[Email protected]/] # hwclock

 


Rsync remote Synchronization

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.