Considering server data security, I want to add a backup server to achieve better redundancy through data synchronization.
In Linux, there is a very good command rsync to implement differential backup. The following describes its usage:
▲Suitable system: Hongqi DC 4.1 or 5.0, or other Linux and FreeBSD systems
▲Test environment: Hongqi DC 5.0
1. Use RSH or SSH commands
In the absence of an rsync server, we can use the rsync command to directly perform fast differential backup:
Command Format:
# Rsync [Option] Destination path of the Source Path
Where:
[Option]:
A: Use the archive mode, which is equal to-rlptgod, that is, keep the original file permission.
Z: Indicates compressed data during transmission.
V: display to the screen
E: Use a remote shell program (RSH or SSH can be used)
-- Delete: Precisely saves copies. files deleted from the source host are also deleted from the target host.
-- Include = pattern: do not exclude files or directories that conform to pattern.
-- Exclude = pattern: exclude all files or directories that conform to the pattern.
-- Password-file: Specifies the password used for rsync server user authentication.
The Source Path and target path can be in the following format:
Rsync: // [user @] host [: Port]/path <-- rsync server path
[User @] HOST: path <-- another representation of rsync server
[User @] HOST: path <-- remote path
Localpath <-- local path
※Note that at least one source or target path must be a local path. If the local path is ignored, only the remote file list is listed.
Example:
# Rsync-Ave SSH test:/home/FTP/pub // home/FTP/pub/
Synchronize the content in the/home/FTP/pub/directory of the Source Path to the local/home/FTP/pub/directory through rsync.
◎ Indicates the/number at the end of the Source Path, And the suffix/notifies rsync to copy the contents of the directory, but not the directory itself. For example:
# Rsync-Ave SSH test:/home/FTP/pub/home/FTP/
The entire pub directory is synchronized to the local/home/FTP/path.
# Rsync-AZV -- delete rsync: // linuxing@192.168.1.100/blog/var/www/html/
Log on to 192.168.1.100 through linuxing, synchronize the rsync server's blog entry to the local/var/www/html/, and delete files or directories that do not exist in the Local Source Path.
※Always pay attention to the -- delete parameter. When using this parameter, we recommend that you specify the local directory with an absolute path to avoid clearing the current directory.
2. Create an rsync server
When the server does not activate SSH or the backup party does not have the SSH permission, we can create an rsync server to perform anonymous data synchronization.
To use the rsync service, you must create a server and a client:
1. Server
Main configuration file:
# Vi/etc/rsyncd. conf
Log File =/var/log/rsyncd. Log
PID file =/var/run/rsyncd. PID
Lock file =/var/run/rsync. Lock
[Test] # Set the rsync segment name
Path =/var/www/html/test # data storage path to be synchronized
Comment = test folder # comment
Uid = Apache # identity used for File Reading
Gid = Apache # Same as above. It must be a user or group with the permission to read the path.
Ignore errors # ignore errors
Read Only = yes # Read-Only
List = No # list not supported
Auth users = linuxing # account used to connect to the rsync Service
Secrets file =/etc/rsyncd. Secrets # specify the location where the account and password are stored
Account password file:
# Vi/etc/rsyncd. Secrets
# Format: Account: Password (each line is a group, and the account and password are separated by the number)
Linuxing: Backup
After saving, ensure that the user is root and the permission is 600.
# Chown root: Root/etc/rsyncd. Secrets
# Chmod 600/etc/rsyncd. Secrets
Start the service:
# Rsync -- daemon
Ensure automatic start upon startup:
Modify the/etc/xinetd. d/rsync file and change disable = yes to disable = No.
# Sed-I-e "/disable/{S/yes/no/}"/etc/xinetd. d/rsync
# Service xinetd. d restart
2. Client
Use the rsync: // method.
If the rsync server requires password verification, you can add the -- password-file parameter:
# Rsync-AZV -- delete rsync: // The linuxing@192.168.1.100/test/var/www/html -- password-file =/etc/test
# Vi/etc/test
# Specify the access password
Bakcup
# Chmod 600/etc/test
3. Timing
In addition, because the rsync client does not have the timing function, we can add scheduled tasks to the crontab to implement timed synchronization, for example, (do not use the-V parameter to prevent screen flushing)
# Crontab-e
0 22 ** 1-5/usr/bin/rsync-Az -- delete rsync: // linuxing@192.168.1.100/test/var/www/html -- password-file =/etc/test
# Synchronization from Monday to five at ten o'clock every night
Iii. Summary
Advantages of rsync: encrypted network transmission can be performed through SSH, or trust relationships can be established using SSH client keys. It is faster than tar or wget to synchronize large and complex directory structures between two computers. In addition, it can achieve precise synchronization.
Iv. Appendix
If you compile and install rsync (such as FreeBSD), the path is a bit different:
The server configuration file is in:/usr/local/etc/rsyncd. conf
Startup File:/usr/local/etc/rc. d/rsyncd. Sh
Command file:/usr/local/bin/rsync
System Startup hosting:/etc/rc. conf (Added rsyncd_enable = "yes ")
V. References
Http://rsync.samba.org/
Help File: Man rsync or man rsyncd. conf