Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

File backup synchronization rsync

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

I. Overview of rsync

Rsync is a data mirroring backup tool-remote sync under unix-like systems. A tool that supports fast incremental backup, supports local replication, remote synchronization, etc., rsync command to synchronize system files before logging into the remote host authentication, authentication process used in two kinds of protocols: ssh protocol and rsync protocol.

Rsync characteristics

1. Ability to update entire directories and trees and file systems

two。 Selectively maintain symbolic links, hard links, file attributes, permissions, devices, time, etc.

3. There are no special permission requirements for installation

4. For multiple files, internal pipelining reduces the delay of file waiting

5. Can use rsh, ssh or direct port as transport portal port

6. Supports anonymous rsync synchronization of files and is an ideal mirroring tool

2. Synchronous source

Rsync (server):

The remote server of the backup operation, also known as the backup source

There are mainly two kinds: ssh source and rsync source.

2.1Sync source of ssh

Experimental environment preparation: one server, one client

Create separate test directories (/ server/ssh, / client/ssh) on the server and client

2.1.1. Downlink synchronization (download)

Rsync-avz server address: / server directory / local directory

Rsync-avz 192.168.115.198:/server/ssh/ / client/ssh/

-a: archiving mode, recursive merge to retain object attributes

-v: displays the synchronization process

-z: compress the file when transferring it

2.1.2. Uplink synchronization (upload)

Rsync-avz / local directory / * server address: / server directory

First, create a user on the server side for uplink synchronization, and give the user permission to execute the directory where the uplink synchronization files are located.

It should be used in combination with setfacl to ensure security

Upload files on the client

2.2, rsync synchronization source

Experimental environment preparation: one server, one client

Create separate test directories (/ server/rsync, / client/rsync) on the server and client

1) create a master configuration file (/ etc/rsyncd.conf) on the server side

2) create a password file

3) start the service rsync-daemon

2.2.1. Downlink synchronization

Rsync-avz user name @ server address:: shared module name / local directory

Rsync-avz rsync:// user name @ server address / shared module name / local directory

The solution is to change the permissions of the password file

After that, restart the rsync service

Close the kill-s QUIT process number first

When you start again, the startup is not successful. At this time, you need to delete the file of the process number.

The connection will be successful on the client side.

2.2.2, uplink synchronization

Rsync-avz / local directory / * user name @ server address:: share module name

Rsync-avz / local directory / * rsync:// user name @ server address / shared module name

First, modify the permissions of the module

If you test again, it will be successful.

-- delete deletes files with destination addresses but not source addresses

Exempt from password verification

3.1Source of ssh (key pair)

Generate a key pair on the client

3.2, .rsync synchronization source (variable)

Export RSYNC_PASSWORD= virtual user password

Automatic real-time synchronous backup

The deficiency of periodic synchronization

The time for performing backup is fixed, the delay is obvious, and the real-time performance is poor.

When the synchronization source remains unchanged for a long time, intensive periodic tasks are unnecessary.

Advantages of real-time synchronization

Start the backup as soon as the synchronization source changes

As long as there is no change in the synchronization source, no backup is performed.

4.1.Configuring inotify

Optimization under configuration file (/ etc/sysctl.conf) 6.* (optional)

Mak_queue_events = 16384

Monitor queue size (16384)

Mak_user_instances = 1024

Maximum number of monitoring instances (1024)

Max_user_watches = 1028576

Maximum number of monitoring files per instance (1028576)

Environment configuration: install gcc*, installation package ready

1) decompress and install

2) inotifywait: for continuous monitoring and real-time output of results

Inotifywatch: used for short-term monitoring. The result will be returned after the task is completed.

Create a user for uplink synchronization and give the user permission to execute the directory where the uplink synchronization files are located

4.2. One-way real-time synchronization of master and slave servers

Rsync+ inotify (real-time synchronization, one-way synchronization tool. Used in conjunction with the following script)

Note: users are required to log in without password authentication, and so needs to generate key pairs for asd users (user asd should exist on the server side)

Test verification (real-time synchronization, one-way synchronization tool)

4.3.Bidirectional real-time synchronization of unison + inotify

4.3.1. Realize two-way key-free file transfer

1) two directories for synchronization

Create a directory client: / client/ssh/ server: / server/ssh/

2) if you use root to log in, generate a key pair to avoid password authentication

Ssh-keygen-t rsa

Ssh-copy-id root@192.168.115.199 (server ip)

Ssh-keygen-t rsa

Ssh-copy-id root@192.168.115.198 (client ip)

Server-side secret key generation is the same as above

4.3.2. Install three softwares

1) install inotify first (gcc* is required)

2) reinstall ocaml

. / configurer make world opt make install

3) install unison

Copy the generated script

Then the same operation is done on the server side.

4.3.3. Configuration script

Client

Server side

Cancel the prompt message and use nohup to execute the script

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report