From the "Network Management" section, "Network Management" column is often facing how to implement remote backups or how to establish a data remote backup or how to establish a website image. Although commercial backup and mirroring products are available, the price of these products is often too expensive. So how to use free software to efficiently implement remote backups and website mirroring, it is a topic worth discussing. The easiest way to remotely perform remote data backups or website mirroring is to use Wget. However, each time you need to transfer all the data over again on the network, without considering which files are updated, so the efficiency is very low. Especially when the amount of backup data is required, it is often necessary to spend a few hours to perform data transmission on the network. Therefore, if there is an efficient network remote backup and mirror tool Rsync, you can meet the most requirements not particularly stringent backup needs. For system administrators, the usual work center should focus on the maintenance system to function properly, and it is often possible to serve a data backup. In the case of our understanding, 80% of the system administrators are not too concerned about the security of their own servers, but it is quite interested in the technology of backup image. However, due to the hardware and software prices of commercial products are quite high, free software is often selected, such as the network remote backup and mirror tool RSync mentioned earlier, which meets the vast number of requirements not particularly high backup requirements. Rsync is Linux, data mirror backup tool under UNIX systems, which can see Remote Sync from the name of the software. It has this characteristic: can be mirrored to save the entire directory tree and file system; it can be easily permission, time, soft and hard links, etc. Use RCP, SSH, etc. to transfer files, of course, can also be connected to a direct Socket connection; support anonymous transmission. Installing and configuring RSYNC instances, such as 2 servers, server names are: WWW and Backup. Hardware environment: 2 HP servers, 1G CPU, 512M RAM, 18G SCSI hard disk; system environment: Redhat Linux 6.2; service environment: rsync-2.4.6. Among them, the Web service content named WWW is stored in the following places: / WWW / and / Mirror / file0 / and / mirror / file1 / directory. Now we need to establish backups of these directory contents on backup machine BACKUP by building RSYNC synchronization services. Software Download Rysnc's home page address is: http://rsync.samba.org/, you can download Rysnc installation software from here (Note: Download source code compilation is best). Compiling and installing Rysnc's compilation and installation is very simple, just a few simple steps (installed in 2 servers): $ TAR XVF RSYNC-2.4.6.tgz $ CD rsync-2.4.6 $ ./configure $ make $ make INSTALL, but you need to note that RSync must be installed on the server WWW and Backup, where the WWW server runs RSYNC in server mode, while BACKUP runs RSYNC in the client mode. This runs the RSYNC daemon on the web server WWW, runs the client when the Backup is scheduled to back up the contents of the WEB server WWW. Configuring the RSYNC server side For the RSYNC server, the most important and complex is its configuration. The RSYNC server configuration file is /etc/rsyncd.conf, which controls authentication, access, logging, etc. This file consists of one or more module structures.
A module defines the beginning of the module name in the square, until the next module definition begins or the file end, the module contains the parameter definition of Name = Value. Each module is actually a directory tree that needs to be backed up, and in the example environment, there are 3 directory trees that require backup: / www / and / mirror / file0 / and / mirror / file1 / directory, then need to configure Documentation is defined in the file, respectively correspond to 3 directory trees, respectively. The profile is a unit of behavior, that is, each new line represents a new annotation, module definition or parameter assignment. (Note: The RSYNC server referred to in this example is a server called WWW). For example, create RSYNCD's profile /etc/rsyncd.conf on www.blue.com.cn, as follows: [Root @ www /] cat /etc/rsyncd.confuid = Nobody GID = Nobody Use Chroot = Nomax Connections = 4pid file = /VAR/Run/rsyncd.pidlock file = /VAR/Run/rsync.lockLog file = /VAR/LOG/RsyncD.log[www]path = / mirror / www / comment = My = triagnore errorsread only = truelist = falseauth users = backuphosts allow = 12.23.34.57/32secrets file = /etc/rsyncd.secrets
[file0] path = / mirror / file0comment = file0ignore errorsread only = truelist = falseauth users = backuphosts allow = 12.23.34.57/32secrets file = /etc/rsyncd.secrets
[File1] path = / mirror / file1comment = file1ignore errorsread only = truelist = falseauth users = backuphosts allow = 12.23.34.57/32secrets file = /etc/rsyncd.secrets herein defined respectively [www], [file0], [file1] Modules, respectively correspond to three target trees that require backups. Only 12.23.34.57 backup data of the server WWW is allowed here, and the authentication is required. Both of the 3 module authorized backup users are backup, and user information is saved in file /etc/backserver.pas, and their contents are as follows: [Root @ www / etc] # cat /etc/backserver.pasbackup:BK_PASSWD and this file only Can be root user readable, otherwise rsyncd will be wrong when RSYNCD starts. After these files are configured, they need to start the RSYNCD server on the WWW server: [root @ www / etc] # GREP RSYNC Services Rsync 873 / TCP # rsyncrsync 873 / udp # rsync [root @ www / etc] Grep @ WWW / etc @ Stream TCP NOWAIT ROOT / USR / local / bin / rsync rsyncd -daemon [root @ www / etc] # rsync -daemon After executing the above command, RSYNC can start. The RSync default service port is 873, and the server receives a backup request for the client's anonymous or authentication mode. Execute the RSYNC client command Next to run the RSYNC client's startup command (this example is the server named Backup):
[backup @ backup /] / usr / local / bin / rsync -vzrtopg -delete -exclude "logs /" - exclude "conf / ssl. * /" --Progress backup@12.23.34.56 :: www / backup / www /--password-file=/etc/rsync.pass
The VZRTOPG in this command line is representative verbose; z is representing zip (compression); R is representing Recursive; TOPG is the original attribute of the file, such as the master, time parameters - Progress refers to the display of detailed progress; - delete means that if the server deletes this file, the client will delete the file accordingly, keep real consistency; - Exclude "logs /" is a representation There is no backup of files in / www / logs directory. The same - Exclude "conf / ssl. * /" Is a backup of files that do not have files in /www/conf/ssl.*/ directory. Backup@12.23.34.56 :: WWW is a backup of the command to the WWW module in Server 12.23.34.56, where the backup represents the module to back up the module using the Backup user. --password-file = / etc / rsync.pass to specify a password file so that you can use it in the script without entering the verification password interactively. It should be noted here that this password file authority attribute is to set only the current user readable by this command, and this example is Backup user. Here you will store the backup content in the backup machine / backup / www / directory. [backup @ backup /] / usr / local / bin / rsync -vzrtopg -delete -exclude "logs /" - exclude "conf / ssl. * /" --Progress backup@12.23.34.56 :: www / backup / www / --Password-file = / etc / rsync.passreceiving file list ... donea.txtwrote 100 bytes read 990409 bytes 220113.11 bytes / sectotal size is 2779708994 Speedup is 2806.34 In this way, the RSYNC synchronization service is built, and finally we can The command executed on the client is performed through the crontab timing, or write some scripts, so the RSYNC synchronization service is more perfect. Some example scripts 1, every 7 days to do data towards the center server to increment backup #! / Bin / sh # this script does Personal Backups to a rsync backup server. You # with a 7 day rotating backup. The incrementals will Go # INTO SUBDIRECTORIES NAMED AFTER The day of the week, and the c # Full Backup Goes Into a Directory Called "Current" # tridge@linuxcare.com@lirectory to backup bdir = / home / $ user
# Excludes File Excludes = $ HOME / CRON / EXCLUDES