Rsync data image backup tool in Linux

Source: Internet
Author: User
Rsync is a data image backup tool in Linux. It can be seen from the software name-Remote Sync. Rsync supports most UNIX-like systems, including Linux, Solaris, and BSD. The latest version of rsync can be found at http://rsync.samba.org/rsync. Its features are as follows:
1. images can be used to save the entire directory tree and file system.
2. It is easy to maintain the permissions, time, and soft links of the original file.
3. installation without special permissions.
4. optimized process, high file transmission efficiency.
5. You can use RCP, ssh, and other methods to transmit files. Of course, you can also use a direct socket connection.
This article describes how to use the rsync service for remote backup from Linux to Windows and Linux.
1. Configure the server
Software Download
The home address of rysnc is http://rsync.samba.org/. you can download the rysninstallation software from here.
Compile and install
Rsync compilation and installation are very simple. You only need to perform the following steps (install both servers ):
$ Tar xvf rsync-2.6.3.tgz
$ Rsync-2.6.3 CD
$./Configure
$ Make
$ Make install
However, you must install rsync on both the master server and synchronization server. The master server runs rsync in server mode, while the synchronization server runs rsync in client mode. In this way, the rsyn daemon is run on the master server, and crond is used to regularly run the client program to synchronize the content to be synchronized on the master server.
Configure the rsync server
For the rsync server, the most important and complex is its configuration. The configuration file of the rsync server is/etc/rsyncd. conf, which controls authentication, access, and logging. This file is composed of one or more modules. A module definition starts with the module name in square brackets until the definition of the next module starts or the file ends. The module contains the Parameter definition in the format of name = value. Each module corresponds to a directory tree to be backed up. For example, in our instance environment, there are three directory trees to be backed up: the/www/AND/mirror/file0/AND/mirror/file1/directories must be defined in the configuration file. The configuration file is the unit of action, that is, each new line represents a new comment, module definition, or parameter value assignment.

For example, create the rsyncd configuration file/etc/rsyncd. conf on 168. The content is as follows:
Uid = Nobody # ID of the backup, user ID
Gid = Nobody # ID of the backup, group ID
# Note that this user ID and group ID can be set to root for convenience, so Rsync is almost ready.
# To read any files and directories, but it also brings security risks. We recommend that you set it to read data only.
# Copies of directories and files.
# Use chroot = No
Max connections = 0 # no limit on the maximum number of connections
PID file =/var/log/rsync/rsyncd. PID
Lock file =/var/log/rsync. Lock
Log File =/var/log/rsync/rsyncd. Log
[Attachment] # specify the name of the authenticated backup module
Path =/www/htdocs/pub/attachment/# directory to be backed up
Comment = backup attachment # comment
Ignore errors # ignore unrelated Io errors
Read Only = false # Set to read-only
List = false # column Files Not Allowed
# Hosts allow = 210.51.0.80 # IP address of the host that allows connection to the server
# Hosts deny = 0.0.0.0/0.0.0.0 # disallow access to the server's Host IP Address
Auth users = msyn # The authenticated user name. If this row is not used, it indicates that it is anonymous.
Secrets file =/etc/rsyncd. scrt # authentication file name, used to store the password
[98 htdocs]
Uid = nobody
Gid = nobody
Path =/www/htdocs/
# Ignore errors
Read Only = false
List = false
# Hosts allow = 210.51.0.98
# Hosts deny = 202.108.211.38
# Hosts deny = 0.0.0.0/0.0.0.0
Auth users = msyn
Secrets file =/etc/rsyncd. scrt
[98 HTML]
Uid = ejbftp
Gid = nobody
Path =/www/htdocs/pub/html/
# Ignore errors
Read Only = false
List = false
# Hosts allow = 210.51.0.98
# Hosts deny = 0.0.0.0/0.0.0.0
Auth users = 98syn
Secrets file =/etc/rsync98.scrt
The three modules [Attachment], [98 htdocs], and [98 HTML] are defined respectively, which correspond to three object trees to be backed up. The backup users authorized by the three modules are msyn, msyn, and 98syn, respectively. The user information is stored in the file/etc/rsyncd. scrt and/etc/rsync98.scrt. The content is as follows:
[Root @ www/etc] # Cat/etc/rsyncd. scrt
Msyn: XXXXXXXXX
In addition, this file can only be read and written by the root user. Note that for security purposes, the attribute of this file must only be readable by the owner; otherwise, rsync will refuse to run. We can set its property to 600:
[Root @ www/etc] # chmod 600/etc/rsyncd. scrt
After these files are configured, you need to start the rsyncd service on the master server:
[Root @ www/etc] #/usr/local/bin/rsync -- daemon

After the preceding command is executed, rsync can be started. The default service port of rsync is 873. The server receives anonymous or authenticated backup requests from the customer on this port.
Ii. Configure the client
1. Run the rsync Client Command in Linux
The next step is to run the rsync client startup command:
[Backup @ backup/]/usr/bin/rsync-vlzrtogp -- Progress -- delete 98syn@x.x.x.168 :: 98 html/usr/local/Apache/htdocs/pub/html/-- password-file =/etc/rsync98.scrt
In the above command line, the V in vzrtopg represents verbose (detailed), Z represents zip (Compressed), and R represents recursive (recursive ), topg is a parameter that maintains the original attributes of the file, such as the owner and time. -- Progress indicates that the detailed progress is displayed. -- delete indicates that if the server deletes the file, the client also deletes the file to ensure true consistency.
98syn@x.x.x.168: 98 HTML indicates that the command is to back up the 98html module in server x. x. x.168, where 98syn indicates that 98syn is used to back up the module. -- Password-file =/etc/rsync98.scrt to specify the password file, which can be used in the script without the need to enter the verification password interactively, note that the permission attribute of the password file must be set to only the current user who executes the command. In this example, it is a 98syn user. The backup content is stored in the/usr/local/Apache/htdocs/pub/html/directory of the backup machine.
In this way, the rsync synchronization service has been set up. Finally, we can use the crontab command executed on the client to implement automatic backup or write some scripts, in this way, the rsync synchronization service is more perfect.
2. Configure the Windows Client
To use rsync in windows, we need to downloadCwrsyncTool, which is an rsync for Windows version.
Now we can run rsync in windows. For example, use the following command to connect to the server and start backing up directories and files:
Rsync-vzrtopg -- Progress -- delete 98syn@xx.xx.xx.xx: 98 html. \ Bak \
We can see that:
Password:
A prompt asking you to enter the password should be displayed after you enter the password correctly.
There are several possibilities for this error. One is that you did not enter the correct user name or password, and the other is that the file storing the password on your server does not have the correct permission, that is, your password file is not a permission similar to this:
-RW ------- 1 Root
The password can be read from a file:
Rsync-vzrtopg -- Progress -- delete 98syn@xx.xx.xx.xx: 98 html. \ Bak \ -- password-file =. \ rsync98.scrt
You can write batch processing to implement scheduled tasks in windows and perform scheduled tasks to implement automatic backup.
You can also download the cwRsync-1.2.8 here:Cwrsync_1.2.8_installer.exe

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.