Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure RSync File backup synchronization Linux Server

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to configure RSync file backup synchronization Linux server". In daily operation, I believe many people have doubts about how to configure RSync file backup synchronization Linux server. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to configure RSync file backup synchronization Linux server". Next, please follow the editor to study!

Rsync (remote synchronize) is a remote data synchronization tool that allows you to quickly synchronize files between multiple hosts through LAN/WAN, or to synchronize different directories on your local hard disk using Rsync. Rsync is a tool to replace rcp. Rsync uses the so-called "Rsync algorithm" to synchronize files between local and remote hosts. This algorithm transfers only different parts of the two files, rather than the whole file each time, so it is quite fast. You can refer to How Rsync Works A Practical Overview to learn more about how rsync works.

Rsync supports most Unix-like systems, and has been well tested on Linux, Solaris, and BSD. In addition, it also has corresponding versions under the windows platform, the more well-known are cwRsync and Sync2NAS.

It is important to note that rsync must be installed on both servers An and B, where server A runs rsync in server mode and rsync runs on B in client mode. This runs the rsync daemon on web server An and the client program periodically on B to back up what needs to be backed up on web server A.

What is rsync

As the name implies, rsync,remote synchronize knows that it is a software that can synchronize files remotely. While synchronizing files, it can keep the permissions, time, soft and hard links and other additional information of the original files. Rsync uses the "rsync algorithm" to provide a fast way to synchronize files between the client and the remote file server, and can transfer files through ssh, so its confidentiality is also very good, in addition, it is also free software.

Rsync includes the following features:

Ability to update entire directories and trees and file systems

Selectively maintain symbolic chains, hard links, file ownership, permissions, devices, time, etc.

There are no special permission requirements for installation

For multiple files, internal pipelining reduces the delay of file waiting

Can use rsh, ssh or direct port as input port

Supports anonymous rsync synchronization of files and is an ideal mirroring tool

Second, set up rsync server

It is relatively simple to set up a rsync server, write a configuration file rsyncd.conf. There are also rules for writing documents, and we can refer to the documents on rsync.samba.org. Of course, we have to install the software rsync first.

A, installation of rsync

Get rsync

The latest version is available on rysnc's official website: http://rsync.samba.org/. The latest version is 3.05. Of course, because rsync is such a useful software, it is included in many Linux distributions.

Software package installation

# sudo apt-get install rsync Note: online installation methods such as debian and ubuntu

# yum install rsync Note: online installation methods such as Fedora and Redhat

# rpm-ivh rsync Note: installation methods of rpm packages such as Fedora, Redhat, etc.

For other Linux distributions, please use the appropriate package management method to install.

Source package installation

Tar xvf rsync-xxx.tar.gz

Cd rsync-xxx

. / configure-- prefix=/usr; make; make install Note: before compiling and installing with the source package, you have to install gcc and other compilers.

B, configuration file

Rsync mainly has the following three configuration files: rsyncd.conf (main configuration file), rsyncd.secrets (password file) and rsyncd.motd (rysnc server information).

Server configuration file (/ etc/rsyncd.conf), which does not exist by default, please create it.

The specific steps are as follows:

# touch / etc/rsyncd.conf # create rsyncd.conf, which is the configuration file for the rsync server.

# touch / etc/rsyncd.secrets # create rsyncd.secrets, which is the user password file.

# chmod 600 / etc/rsyncd/rsyncd.secrets # set the file attribute of the password file rsyncd.secrets to be owned by root, and the permissions must be set to 600, otherwise the backup will not be successful!

# touch / etc/rsyncd.motd

It's time for us to modify the rsyncd.conf and rsyncd.secrets and rsyncd.motd files next.

Settings / etc/rsyncd.conf

Rsyncd.conf is the main configuration file for the rsync server. Let's start with a simple example, which will be explained in detail later.

For example, we want to back up / home and / opt on the server. In / home, I want to exclude easylife and samba directories.

# Distributed under the terms of the GNU General Public License v2

# Minimal configuration file for rsync daemon

# See rsync (1) and rsyncd.conf (5) man pages for help

# This line is required by the / etc/init.d/rsyncd script

Pid file = / var/run/rsyncd.pid

Port = 873

Address = 192.168.1.171

# uid = nobody

# gid = nobody

Uid = root

Gid = root

Use chroot = yes

Read only = yes

# limit access to private LANs

Hosts allow=192.168.1.0/255.255.255.0 10.0.1.0/255.255.255.0

Hosts deny=*

Max connections = 5

Motd file = / etc/rsyncd.motd

# This will give you a separate log file

# log file = / var/log/rsync.log

# This will log every file transferred-up to 85000 + per user, per sync

# transfer logging = yes

Log format =% t% a% m f% b

Syslog facility = local3

Timeout = 300

[rhel4home]

Path = / home

List=yes

Ignore errors

Auth users = root

Secrets file = / etc/rsyncd.secrets

Comment = This is RHEL 4 data

Exclude = easylife/ samba/

[rhel4opt]

Path = / opt

List=no

Ignore errors

Comment = This is RHEL 4 opt

Auth users = easylife

Secrets file = / etc/rsyncd/rsyncd.secrets

Note: auth users is a real system user that must exist on the server, if you want to separate multiple users with a, sign, such as auth users = easylife,root

Set password file

The password file format is simple, and the content format of rsyncd.secrets is:

User name: password

In our example, the content of rsyncd.secrets is similar; in the document, it is said that some systems do not support long passwords, so try to set them yourself.

Easylife:keer

Root:mike

Chown root.root rsyncd.secrets # modify the owner

Chmod 600 rsyncd.secrets # modify permissions

Note: 1. Set the file attribute of the rsyncd.secrets password file to be owned by root, and the permissions should be set to 600. otherwise, the backup will not be successful! For security purposes, the properties of the file must be readable only to the owner.

2. The password here is worth noting. For the sake of security, you can't write the password of the system user here. For example, if your system user's easylife password is 000000, you can make the easylife in rsync keer for security. This is similar to the password principle of samba user authentication.

Set up rsyncd.motd fil

It defines rysnc server information, that is, user login information. For example, let the user know who provided the server; similar to the linuxsir.org ftp we see when the ftp server logs in. Of course, this is not necessary when defining variables globally, you can write out or delete it with the # sign; I wrote a rsyncd.motd here as follows:

+

Welcome to use the mike.org.cn rsync services!

2002-2009

+

III. Detailed explanation of the configuration of rsyncd.conf server

A, global definition

In the rsync server, there are several global definitions that are critical, according to the configuration file rsyncd.conf file we gave earlier

Pid file = / var/run/rsyncd.pid Note: tell the process to write to the / var/run/rsyncd.pid file

Port = 873.Note: specify the running port. Default is 873. You can specify it yourself.

Address = 192.168.1.171 Note: specify the server IP address

Uid = nobody

Gid = nobdoy

Note: when transferring files on the server side, which user and user group should be sent for execution? the default is nobody. If you use nobody users and user groups, you may encounter permission problems, and some files cannot be pulled from the server. So I slacked off and used root for convenience. However, you can resolve permissions by specifying users in the modules defined when defining directories to synchronize.

Use chroot = yes

Note: with chroot, the server daemon sends chroot to a directory in the file system before transferring files, which has the advantage of protecting the system from installation vulnerabilities. The disadvantage is that superuser privileges are required. In addition, symbolic link files will be excluded. That is to say, if you have a symbolic link on the rsync server, when you run the client's synchronization data on the backup server, you will only synchronize the symbolic link name, not the content of the symbolic link; you need to try this for yourself.

Read only = yes

Note: read only is a read-only option, that is, clients are not allowed to upload files to the server. There is also a write only option, try to do what it is for

# limit access to private LANs

Hosts allow=192.168.1.0/255.255.255.0 10.0.1.0/255.255.255.0

Note: you can specify either a single IP or the entire network segment, which can improve security. The format is to be separated by spaces between ip and ip, ip and network segments, and network segments.

Max connections = 5

Note: maximum number of client connections

Motd file = / etc/rsyncd/rsyncd.motd

Note: motd file defines the server information and writes the contents of the rsyncd.motd file by yourself. Users will see this message when they log in. For example, I wrote:

+

Welcome to use the mike.org.cn rsync services!

2002-2009

+

Log file = / var/log/rsync.log

Note: log of rsync server

Transfer logging = yes

Note: this is the log of the transferred file.

Log format =% t% a% m f% b

Syslog facility = local3

Timeout = 300

B, module definition

What does the module define? The main purpose is to define which directory of the server will be synchronized. Each module is in the form of [name]. This name is the name you saw on the rsync client, but it's actually a bit like the share name provided by the Samba server. The data that the server actually synchronizes is specified through path. We can specify multiple modules according to our own needs. Each module should specify authenticated users, password file, but exclusion is not necessary.

Here is an example of the previous configuration file module:

[rhel4home] # module, which provides us with the name of a link, which is linked to the / home directory in this module; in the form of [name]

Path = / home # specifies the location of the file directory, which must be specified

Auth users = root # authenticated user is root and must exist on the server

List=yes # list means to list the directories on the rsync server that provide synchronized data on the server whether the module is displayed or not. The default is yes. If you don't want to list it, no it; if no is more secure, at least others don't know which directories are available on your server. You just need to know it yourself.

Ignore errors # ignores IO errors

Secrets file = / etc/rsyncd.secrets # which file does the password exist

Comment = linuxsir home data # comments can be defined by yourself

Exclude = beinan/ samba/

Note: exclude means to exclude, that is, to exclude easylife and samba under the / home directory; there is a space between the easylife/ and samba/ directories

[rhel4opt]

Path = / opt

List=no

Comment = optdir

Auth users = beinan

Secrets file = / etc/rsyncd/rsyncd.secrets

Ignore errors

Start the rsync server and the settings of the firewall

Starting the rsync server is fairly simple, and there are several ways to do it

A,-- daemon parameter mode, which allows rsync to run in server mode

# / usr/bin/rsync-- daemon-- config=/etc/rsyncd/rsyncd.conf #-- config is used to specify the location of the rsyncd.conf. You don't have to write it under / etc.

B, xinetd mode

Modify services to add the following

# nano-w / etc/services

Rsync 873/tcp # rsync

Rsync 873/udp # rsync

You don't have to do this step, usually with these two lines (my RHEL4 and GENTOO have both by default). The purpose of the modification is to let the system know that the service name corresponding to port 873 is rsync. If not, join yourself.

Set / etc/xinetd.d/rsync. A simple example is as follows:

# default: off

# description: The rsync server is a good addition to am ftp server, as it\

# allows crc checksumming etc.

Service rsync

{

Disable = no

Socket_type = stream

Wait = no

User = root

Server = / usr/bin/rsync

Server_args =-- daemon

Log_on_failure + = USERID

}

The main purpose of the above is to open the daemon of rsync, and once there is a rsync client to connect, xinetd will refer it to rsyncd (port 873). Then service xinetd restart to make the above settings take effect.

Rsync servers and firewalls

The Linux firewall uses iptables, so we should at least let your defined rsync server port through on the server side and on the client side.

# iptables-An INPUT-p tcp-m state-- state NEW-m tcp-- dport 873-j ACCEPT

# iptables-L check if the firewall has port 873 open

If you don't know how to configure the firewall, you can turn off the firewall by service iptables stop first. Of course, this is very dangerous in the production environment, you can only do this by doing experiments.

Fifth, synchronize data through rsync client

A. detailed explanation of grammar

After configuring the rsync server, you can issue rsync commands from the client to achieve various synchronization operations. There are many functional options for rsync. Here are some common options:

The command format for rsync can be:

1. Rsync [OPTION]... SRC [SRC]... [USER@] HOST:DEST

2. Rsync [OPTION]... [USER@] HOST:SRC DEST

3. Rsync [OPTION]... SRC [SRC]... DEST

4. Rsync [OPTION]... [USER@] HOST::SRC [DEST]

5. Rsync [OPTION]... SRC [SRC]... [USER@] HOST::DEST

6. Rsync [OPTION]... Rsync:// [USER@] HOST [: PORT] / SRC [DEST]

Rsync has six different modes of operation:

1. Copy local files; start this working mode when neither SRC nor DES path information contains a single colon: delimiter.

two。 Use a remote shell program (such as rsh, ssh) to copy the contents of the local machine to the remote machine. Start this mode when the DST path address contains a single colon ":" separator.

3. Use a remote shell program (such as rsh, ssh) to copy the contents of the remote machine to the local machine. Start this mode when the SRC address path contains a single colon ":" separator.

4. Copy files from a remote rsync server to the local machine. This mode is started when the SRC path information contains the "::" delimiter.

5. Copy files from the local machine to the remote rsync server. This mode is started when the DST path information contains the "::" delimiter.

6. List the files for the remote machine. This is similar to rsync transport, except that the local machine information is omitted from the command.

-an operate in archive mode, copy directories, symbolic links are equivalent to-rlptgoD

Parameters in rsync

-r is recursive

-l is a linked file, meaning to copy a linked file;-p means to keep the original permissions of the file;-t to keep the original time of the file;-g to keep the original user group of the file;-o to keep the original owner of the file;-D is equivalent to a block device file.

-z compression during transmission

-P transmission progress

The progress of-v transmission and other information has something to do with-P, try it yourself. You can read the document.

The parameters of-e ssh establish an encrypted connection.

-u updates only to prevent new local files from being rewritten. Note that both machines' clocks are at the same time

Progress means to show a detailed progress.

-- delete means that if the server deletes the file, then the client deletes the file accordingly to maintain true consistency

-- password-file=/password/path/file to specify the password file so that it can be used in the script without having to enter the authentication password interactively. It is important to note that the permission attribute of this password file should be set to be readable only by the owner.

B, some examples

B1. List the synchronization content provided on the rsync server

First: let's look at what available data sources are available on the rsync server

# rsync-list-only root@192.168.145.5::

+

Welcome to use the mike.org.cn rsync services!

2002-2009

+

Rhel4home This is RHEL 4 data

Note: the data source provided by rsync is the [rhel4home] module we wrote in rsyncd.conf. "This is RHEL 4 data" is provided by comment = This is RHEL 4 data in the [rhel4home] module; why isn't the rhel4opt data source listed? Because we have already put list=no in [rhel4opt].

$rsync-list-only root@192.168.145.5::::rhel4home

+

Welcome to use the mike.org.cn rsync services!

2002-2009

+

Password:

Drwxr-xr-x 4096 2009-03-15 21:33:13.

-rw-r--r-- 1018 02:33:41 ks.cfg on 2009-03-02

-rwxr-xr-x 21288 21:33:13 wgetpaste on 2009-03-15

Drwxrwxr-x 4096 2008-10-28 21:04:05 cvsroot

Drwx- 4096 2008-11-30 16:30:58 easylife

Drwsr-sr-x 4096 2008-09-20 22:18:05 giddir

Drwx- 4096 2008-09-29 14:18:46 quser1

Drwx- 4096 2008-09-27 14:38:12 quser2

Drwx- 4096 2008-11-14 06:10:19 test

Drwx- 4096 2008-09-22 16:50:37 vbird1

Drwx- 4096 2008-09-19 15:28:45 vbird2

In the following root@ip, root is the user name in the specified password file, followed by:: rhel4home, which is the name of the rhel4home module

B2 and rsync clients synchronize data

# rsync-avzP root@192.168.145.5::rhel4home rhel4home

Password: enter the password of the root here, which is provided by the server-side rsyncd.secrets. In the previous example, we used mike. The password entered is not echoed. Enter the key once you have typed it.

Note: this command means that you log in to the server with the root user and synchronize the rhel4home data to the local current directory rhel4home. Of course, the local directory can be defined by yourself. If you do not have the rhel4home directory under the current operating directory on the client, the system will automatically create one for you; when it exists in the rhel4home directory, you should pay attention to its write permissions.

# rsync-avzP-- delete linuxsir@linuxsir.org::rhel4home rhel4home

This time we introduce a-- delete option, which means that the data on the client side should be exactly the same as the server side, and if there are files in the linuxsirhome directory that do not exist on the server, delete them. The ultimate goal is to keep the data on the linuxsirhome directory exactly the same as on the server; be careful when using it, it is best not to use the directory that already has important numbers as a local update directory, otherwise all your data will be deleted

Set rsync client

Set password file

# rsync-avzP-delete-password-file=rsyncd.secrets root@192.168.145.5::rhel4home rhel4home

This time we added an option-password-file=rsyncd.secrets, which means that when we log in to the rsync server to synchronize data as a root user, the password will read the rsyncd.secrets file. The content of this file is only the password of the root user. We need to do the following

# touch rsyncd.secrets

# chmod 600 rsyncd.secrets

# echo "mike" > rsyncd.secrets

# rsync-avzP-delete-password-file=rsyncd.secrets root@192.168.145.5::rhel4home rhel4home

Note: it should be noted here that the permission attribute of this password file should be set to be readable only to the owner.

This eliminates the need for a password; in fact, this is more important, because it is necessary for the server to schedule tasks through crond

B3. Let rsync client automatically synchronize data with server

The server is a heavyweight application, so the network backup of data is extremely important. We can configure the rsync server on the production server. We can think of a machine with rysnc as a backup server. Let the backup server synchronize the data on the server at 4: 00 a. M. every day; and each backup is a full backup. Sometimes the hard drive is broken, or the server data is deleted, and a full backup is still very important. This kind of backup is equivalent to mirroring the data of the server every day. When there is an accident on the production server, we can easily recover the data and minimize the data loss. Is that the case?

Step1: creating synchronization scripts and password files

# mkdir / etc/cron.daily.rsync

# cd / etc/cron.daily.rsync

# touch rhel4home.sh rhel4opt.sh

# chmod 755 / etc/cron.daily.rsync/*.sh

# mkdir / etc/rsyncd/

# touch / etc/rsyncd/rsyncrhel4root.secrets

# touch / etc/rsyncd/rsyncrhel4easylife.secrets

# chmod 600 / etc/rsyncd/rsync.*

Note: we created two files, rhel4home.sh and rhel4opt.sh, in / etc/cron.daily/, with permissions of 755. Created two password files root user uses rsyncrhel4root.secrets, easylife user uses rsyncrhel4easylife.secrets, permission is 600,

We edit the rhel4home.sh and the content is as follows:

#! / bin/sh

# backup 192.168.145.5:/home

/ usr/bin/rsync-avzP-- password-file=/etc/rsyncd/rsyncrhel4root.password root@192.168.145.5::rhel4home / home/rhel4homebak/$ (date +'% MMI% dMY% y')

We edit the rhel4opt.sh, which reads:

#! / bin/sh

# backup 192.168.145.5:/opt

/ usr/bin/rsync-avzP-- password-file=/etc/rsyncd/rsyncrhel4easylife.secrets easylife@192.168.145.5::rhel4opt / home/rhel4hoptbak/$ (date +'% MMI% dMY% y')

Note: you can merge the contents of rhel4home.sh and rhel4opt.sh into one file, such as writing them to rhel4bak.sh.

Then we modify the contents of / etc/rsyncd/rsyncrhel4root.secrets and rsyncrhel4easylife.secrets

# echo "mike" > / etc/rsyncd/rsyncrhel4root.secrets

# echo "keer" > / etc/rsyncd/rsyncrhel4easylife.secrets

Then we create rhel4homebak and rhel4optbak directories under the / home directory, which means that the server-side rhel4home data is synchronized to / home/rhel4homebak on the backup server, and rhel4opt data is synchronized to the / home/rhel4optbak/ directory. And archive the catalogue according to the day of the year; the backup is archived every day.

# mkdir / home/rhel4homebak

# mkdir / home/rhel4optbak

Step2: modify the configuration file of the crond server to add to the scheduled task

# crontab-e

Add the following:

# Run daily cron jobs at 4:10 every day backup rhel4 data:

10 4 * / usr/bin/run-parts / etc/cron.daily.rsync 1 > / dev/null

Note: the first line is a comment and a description, so that you can remember it by yourself.

The second line indicates that the executable script task under / etc/cron.daily.rsync is run at 04:10 every morning

Once configured, restart the crond server

# killall crond Note: the process that killed the crond server

# ps aux | grep crond Note: check to see if it has been killed

# / usr/sbin/crond Note: start the crond server

# ps aux | grep crond Note: check to see if it is enabled.

Root 3815 0.0 0.0 1860 664? S 14:44 0:00 / usr/sbin/crond

Root 3819 0.0 2188 808 pts/1 S + 14:45 0:00 grep crond

VI. FAQ

Q: how to rsync via ssh without entering a password?

A: you can go through the following steps

1. Set up SSH keys on server A through ssh-keygen. Do not specify a password. You will see identity and identity.pub files under ~ / .ssh.

two。 Create a subdirectory in the home directory on server B. ssh

3. Copy the identity.pub of A to server B

4. Add identity.pub to ~ [user b] / .ssh/authorized_keys

5. So user An on server A can ssh user B to server B with the following command. E.g. Ssh-l userB serverB. This allows user An on server A to log in to server B without a password for ssh as user B.

Q: how do I use rsync through a firewall without compromising security?

A: the answer is as follows:

There are usually two situations, one is that the server is inside the firewall, and the other is that the server is outside the firewall. In either case, ssh is usually used, so it's best to create a new backup user and configure sshd to allow only that user to enter through RSA authentication. If the server is inside the firewall, it is best to limit the IP address of the client and deny all other connections. If the client is inside the firewall, you can simply allow the fire wall to open the ssh outgoing connection of TCP port 22 to ok.

Q: can I back up the files that have been changed or deleted?

A: of course. You can use things such as rsync-other-options-backupdir =. / backup-2000-2-13. To achieve such a command. So if the source file: / path/to/some/file.c changes, the old file will be moved to. / backup- 2000-2-13/path/to/some/file.c, where the directory needs to be created manually.

Q: which ports do I need to open on the firewall to accommodate rsync?

A: it depends. Rsync can transfer files directly through the tcp connection of port 873, or through the ssh of port 22, but you can also change its port with the following command:

Rsync-port 8730 otherhost::

Or

Rsync-e 'ssh-p 2002' otherhost:

Q: how can I just copy the directory structure through rsync and ignore the files?

A:rsync-av-- include'* /-- exclude'* 'source-dir dest-dir

Q: why do I always make "Read-only file system" mistakes?

A: see if you forgot to set "read only = no"

Q: why do I have the error of'@ ERROR: invalid gid''?

A:rsync is run with uid=nobody;gid=nobody by default. If there is no nobody group on your system, this error will occur. You can try gid= ogroup or something else.

Q: what is the failure to bind port 873?

A: if you are not running this daemon with root privileges, this error will occur because the ports below port 1024 are privileged ports. You can change it with the-- port parameter.

Q: why did my authentication fail?

A: from your command line, you are using

Bash$ rsync-a 144.16.251.213::test test

> Password:

> @ ERROR: auth failed on module test

>

> I dont understand this. Can somebody explain as to how to acomplish this.

> All suggestions are welcome.

It should be the problem caused by not logging in with your user name. Try rsync-a max@144.16.251.213::test test

Q: what's going on with the following message?

@ ERROR: auth failed on module xxxxx

Rsync: connection unexpectedly closed (90 bytes read so far)

Rsync error: error in rsync protocol data stream (code 12) at io.c

A: this is because the password is set wrong and you cannot log in successfully. Please check the password setting in rsyncd.secrets again. Is it consistent between the two ends?

Q: what's going on with the following message?

Password file must not be other-accessible

Continuing without password file

Password:

A: this means that the file permission property of rsyncd.secrets is incorrect and should be set to 600. Please download chmod 600rsyncd.secrets.

Q: what's going on with the following message?

@ ERROR: chroot failed

Rsync: connection unexpectedly closed (75 bytes read so far)

Rsync error: error in rsync protocol data stream (code 12) at io.c

A: this is usually because the directory set by the path path in your rsyncd.conf does not exist. Please use mkdir to open the backup directory first.

g. Server-side file details

5.2. Client configuration

a. Client installs rsync

# yum-y install rsync

b. Synchronize data through the rsync client

Scenario 1:

# rsync-avzP david@172.16.1.135::davidhome / tmp/david/

Password: enter the password of david here, which is provided by the server. In the previous example, we used asdf, and the password entered is not shown. Enter enter after typing.

Note: this command means that you log in to the server with the david user and synchronize the davidhome data to the local directory / tmp/david/. Of course, you can define the local directory, such as dave; when you are on the client, there is no davidhome directory under the current operation directory, the system will automatically create one for you; when it exists in the davidhome directory, you should pay attention to its write permission.

Description:

-a parameter, equivalent to-rlptgoD,-r is recursive-l is a linked file, meaning to copy a linked file;-p means to keep the original permissions of the file;-t to keep the original time of the file;-g to keep the original user group of the file;-o to keep the original owner of the file;-D is equivalent to the block device file.

-z compression during transmission

-P transmission progress

The progress of-v transmission and other information has something to do with-P, try it yourself. You can read the document.

Scenario 2:

# rsync-avzP-- delete david@172.16.1.135::davidhome / tmp/david/

This time we introduce a-delete option, which means that the data on the client side should be exactly the same as the server side, and if there are files in the / tmp/david/ directory that do not exist on the server, delete them. The ultimate goal is to keep the data on the / tmp/david/ directory exactly the same as on the server; be careful when using it, it is best not to use the directory that already has important numbers as a local update directory, otherwise all your data will be deleted

Scenario 3:

# rsync-avzP-- delete-- password-file=/tmp/rsync.password david@172.16.1.135::davidhome / tmp/david/

This time we added an option-password-file=rsync.password, so that when we log in to the rsync server as david to synchronize data, the password will read the file / tmp/rsync.password. The content of this file is only the password of the david user. We need to do the following

# touch / tmp/rsync.password

# chmod 600 / tmp/rsync.password

# echo "asdf" > / tmp/rsync.password

# rsync-avzP-- delete-- password-file=/tmp/rsync.password david@172.16.1.135::davidhome / tmp/david/

Note: this eliminates the need for a password; in fact, this is more important, because it is necessary for the server to schedule tasks through crond

At this point, the study on "how to configure RSync file backup synchronization Linux server" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report