Brief introduction
For the choice of Linux as an application platform for small and medium-sized enterprises or Web sites, often face how to achieve remote Data backup or Web site mirror image of the problem, although there are commercial backup and mirror products to choose from, but these products are often too expensive prices. So how to use free software to efficiently implement remote backup and Web site mirror image is a topic worthy of discussion.
The easiest way to make remote data backups or Web site mirrors over a network is to use wget, but it is inefficient to have all the data transferred over the network at a time without considering which files are updated. Especially when the amount of data that needs to be backed up is large, it often takes hours to transfer data over the network.
So here is an efficient network remote backup and Mirror tool-rsync, which can meet most of the requirements are not particularly stringent backup requirements.
Rsync is a data mirroring Backup tool under Unix-like systems, and--remote sync can be seen from the name of the software. Its characteristics are as follows:
Can be mirrored to save the entire directory tree and file system.
It is easy to maintain the original file permissions, time, soft and hard links and so on.
can be installed without special permissions.
Optimized flow, high efficiency of file transfer.
You can use RCP, ssh, and so on to transfer files, of course, through a direct socket connection.
Support for anonymous transmission, to facilitate the use of Web site mirror image.
Software downloads
RYSNC's home address is:
http://rsync.samba.org/
The latest version is 2.4.6. You can choose to download from the original website: http://rsync.samba.org/ftp/rsync/. You can also choose to download from this site: rsync 2.4.6.
Compiling the installation
The compilation and installation of rsync is simple and requires only the following simple steps:
[Root@www rsync-2.4.6]#./configure
[Root@www rsync-2.4.6]# make
[Root@www rsync-2.4.6]# make install
However, it should be noted that rsync must be installed on servers A and B, where rsync is running in server mode on Server A and B on the client side of Rsync. This runs the rsync daemon on Web Server A and periodically runs the client on B to back up the content that needs to be backed up on Web server A.
Rsync Server
1, the start of the rsync server
On Web Server A, you need to start the rsync server in a daemon way, just run:
[Root@www rsync-2.4.6]#/usr/local/bin/rsync--daemon
Can be started. The Rsync default service port is 873, and the server receives a client's anonymous or authenticated backup request on that port.
There are several different ways to start a service at startup, such as:
A, join inetd.conf
Edit/etc/services, add rsync 873/tcp, specify the service port for Rsync is 873. Edit Add/etc/inetd.conf, add rsync stream TCP nowait root/bin/rsync rsync--daemon
Note: For xinetd, the setting method is similar.
B, Join rc.local
Edit/etc/rc.d/rc.local, add at the end:
/usr/local/bin/rsync--daemon
2, the configuration of rsync
For the rsync server, the most important and complex is its configuration. The rsync server's configuration file is/etc/rsyncd.conf, which controls authentication, access, logging, and so on.
The file is made up of one or more module structures. A module definition begins with the module name in square brackets until the next module definition begins or the file ends, and the module contains a parameter definition formatted with NAME = value. Each module actually corresponds to a directory tree that needs to be backed up, for example, in our instance environment, there are three trees that need to be backed up:/www/,/home/web_user1/and/home/web_user2/, then you need to define three modules in the configuration file. Corresponds to three trees respectively.
The configuration file is the behavior unit, which means that each new row represents a new annotation, module definition, or parameter assignment. A line that starts with a # represents a comment, and a row that ends with "\" means that the following row is the continuation of the row. An equal sign in a parameter assignment may be a case-insensitive string, a Boolean value expressed in Trure/false.
Global parameters
All parameters before [Modlue] in a file are global parameters, and of course you can define module parameters in the global Parameters section, when the value of this parameter is the default value for all modules.
MOTD file
The MOTD file parameter is used to specify a message file that, when the client connects to the server, displays the contents of the file to the customer, and there is no MOTD file by default.
Log file
"Log File" specifies the log files for rsync and does not send the log to syslog.
PID File
Specifies the PID file for rsync.
Syslog facility
Specifies the message level for rsync when sending log messages to syslog, common message levels: Uth, Authpriv, cron, Daemon, FTP, Kern, LPR, mail, news, security, Sys-log, user, UUCP , Local0, Local1, Local2, Local3,local4, LOCAL5, Local6 and LOCAL7. The default value is daemon.
Module parameters
After a global parameter, you need to define one or more modules, and the following parameters can be defined in the module:
Comment
Assign a description to the module, which is displayed to the customer, along with the module name, when the client connects to the module list. The default does not describe the definition.
Path
Specifies the directory tree path for the module to be backed up, which must be specified.
Use Chroot
If "Use Chroot" is specified as true, rsync first chroot to the directory specified by the path parameter before transferring the file. The reason for this is to implement additional security protection, but the disadvantage is that you need to roots permissions, and you cannot back up the directory files that point to external symbolic connections. The chroot value is true by default.
Max connections
Specify the maximum number of concurrent connections to the module to protect the server, and a connection request exceeding the limit will be told to try again later. The default value is 0, which means there is no limit.
Lock file
Specifies the lock file that supports the Max connections parameter, and the default value is/var/run/rsyncd.lock.
Read Only
This option sets whether the customer is allowed to upload files. If true, any upload requests will fail, and if it is false and the server directory read-write permission is allowed, the upload is allowed. The default value is true.
List
This option sets whether the module should be listed when the client requests a list of modules that can be used. If you set this option to False, you can create a hidden module. The default value is true.
Uid
This option specifies the UID that the daemon should have when the module transmits files, with the GID option used to determine which file permissions to access, and the default value is "nobody".
Gid
This option specifies the GID that the daemon should have when the module transmits files. The default value is "nobody".
Exlude
Use to specify multiple pattern lists separated by spaces and add them to the exclude list. This is equivalent to using--exclude in the client command to specify the pattern, although the Exlude mode specified in the configuration file is not passed to the client and is applied only to the server. A module can specify only one exlude option, but it is possible to use "-" and "+" in front of the pattern to specify whether it is exclude or include.
However, it is important to note that this option has a certain security problem, the customer is likely to bypass the Exlude list, if you want to ensure that a particular file can not be accessed, it is best to combine the uid/gid option.
Exlude from
Specifies a filename that contains the definition of the Exclude mode from which the server reads the Exlude list definition.
Include
A list of patterns that specify multiple exlude that are separated by spaces and should be used. This equates to specifying patterns using--include in client commands, combining include and exlude to define complex exlude/include rules. A module can only specify an include option, but it is possible to use "-" and "+" in front of the pattern to specify whether it is exclude or include.
Include from
Specifies a file name that contains the definition of the include mode, from which the server reads the Include list definition.
Current 1/3 page
123 Next read the full text