Use rsync to back up images from linux to linux or to windows
Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
Use rsync to back up images for websites from linux to linux or to windows-Linux Enterprise applications-Linux server applications. For more information, see the following. 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
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.5.tgz
$ Rsync-2.6.5 cd
$ 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
The most important and complex rsync server 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 = 188.8.131.52 # 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
The three modules [attachment], [98 htdocs], and [98 html] are defined here, which correspond to the three target 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:
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
[Root @ www/etc] # mkdir/var/log/rsync
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:
In the preceding command line-In vzrtopg, v represents verbose (details), z represents zip (compression), and r represents recursive (recursion ), topg is a parameter that maintains the original attributes of a 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.
firstname.lastname@example.org: 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 download the cwRsync tool, 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 email@example.com: 98 html. \ bak \
We can see that:
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
After the backup is complete
The password can be read from a file:
Rsync-vzrtopg -- progress -- delete firstname.lastname@example.org: 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 version here: cwRsync_1.2.8_Installer.exe
Note: The reference address is http://www.vfocus.net/blog/mt-tb.cgi/6. Respect originality, and indicate the source if any reposted information is provided.
Q: How can I perform rsync through ssh without entering a password?
A: follow these steps:
1. Use ssh-keygen to create an ssh keys on server a. do not specify a password ~ /. Ssh: the identity and identity. pub files are displayed.
2. Create a subdirectory. ssh in the home directory on server B.
3. Copy identity. pub OF a to server B.
4. Add identity. pub ~ [User B]/. ssh/authorized_keys
5. So user a on server a can use the following command to ssh user B to server B.
E.g. ssh-l userb serverb
In this way, user a on server a can log on to server B as user B without a password.
Q: How can I use rsync through the firewall without compromising security?
A: The answer is as follows:
There are two common cases: one is that the server is inside the firewall and the other is outside the firewall. In either case, ssh is usually used. In this case, it is best to create a backup user and configure sshd to only allow this user to access through rsa Authentication.
If the server is in the firewall, it is best to limit the IP address of the client and reject all other connections. If the client is in the firewall, you can simply allow the firewall to open the ssh outbound connection on tcp port 22.
Q: Can I back up the changed or deleted files?
A: Of course:
You can use commands such as rsync-other-options-backupdir =./backup-2000-2-13.
In this case, if the source file is/path/to/some/file. c changed, so the old file will be moved. /backup-2000-2-13/path/to/some/file. c,
Here, this directory requires you
Q: What ports do I need to open on the firewall to adapt to rsync?
A: depends on the situation.
Rsync can directly transfer files through tcp connection on port 873, or through ssh on port 22, but you can also change the port through the following command:
Rsync -- port 8730 otherhost ::
Rsync-e 'ssh-p 2002 'otherhost:
Q: How can I copy only the directory structure through rsync and ignore the file?
A: rsync-av -- include '*/' -- exclude '* 'source-dir dest-dir
Q: Why do I always see the "read-only file system" error?
A: Check if you forget to set "read only = no ".
Q: Why do I encounter the '@ error: invalid gid' error?
A: During rsync, uid = nobody is used by default; gid = nobody is used for running. If your system does not have a nobody group, this error will occur, you can try gid = nogroup or another
Q: Why does port 873 fail to be bound?
A: If you do not run the daemon with the root permission, this error will occur because the ports below port 1024 are privileged ports. You can use the -- port parameter to change the value.
Q: Why does my authentication fail?
A: From the Perspective of your command line:
You are using:
> Bash $ rsync-a 184.108.40.206: test
> @ Error: auth failed on module test
> I dont understand this. can somebody explain as to how to acomplish this.
> All suggestions are welcome.
There should be no issues caused by login with your username, try rsync-a email@example.com: test
Ii. Some useful scripts
These scripts are examples on the rsync Website:
1. Incremental backup of data to the central server every seven days
# This script does personal backups to a rsync backup server. you will end up
# With a 7-day rotating incremental backup. the incrementals will go
# Into subdirectories named after the day of the week, and the current
# Full backup goes into a directory called "current"
# Directory to backup
Bdir =/home/$ user
# Excludes file-this contains a wildcard pattern per line of files to exclude
Excludes = $ home/cron/excludes
# The name of the backup machine
Bserver = owl
# Your password on the backup server
Export rsync_password = xxxxxx
You can use this method to list the files to be backed up. This method seems to be rarely used.
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to firstname.lastname@example.org. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
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:
and provide relevant evidence. A staff member will contact you within 5 working days.