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 use Linux remote backup tool Rsync

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Editor to share with you how to use Linux remote backup tool Rsync, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Note: in all the examples below-there is actually no space between them, please delete the space when using it.

Rsync is a remote data synchronization tool that can quickly synchronize files between multiple hosts through LAN or the Internet. Rsync was originally a tool to replace rcp, which is currently maintained by rsync.samba.org. Rsync uses the so-called "Rsync algorithm" to synchronize files between local and remote hosts, which transfers only different parts of the two files instead of the whole file each time, so it is quite fast.

Features of Rsync:

Fast: * rsync will copy all the contents during the second synchronization, but only the modified files will be transferred next time.

Security: rsync allows data to be encrypted over the ssh protocol.

Less bandwidth: rsync can compress and decompress data during transmission, so less bandwidth can be used.

Privileges: no special permissions are required to install and execute rsync

Basic syntax:

Rsync options source destination

Both the source and destination can be local or remote, and the login name, remote server and file location need to be specified for remote transfer.

Example:

1 synchronize the two directories on the local machine

$rsync-zvr / var/opt/installation/inventory/ / root/tempbuilding file list... Donesva.xmlsvB.xml.sent 26385 bytes received 1098 bytes 54966.00 bytes/sectotal size is 44867 speedup is 1.63 $

Parameters:

-z turn on compression

-v details output

-r indicates recursion

2 make use of rsync-a to keep the time stamp during synchronization

The rsync option-a, called archive mode, does the following

Recursive mode

Retain symbolic links

Retain permissions

Retention time stamp

Keep user name and group name

$rsync-azv / var/opt/installation/inventory/ / root/temp/building file list... Done./sva.xmlsvB.xml.sent 26499 bytes received 1104 bytes 55206.00 bytes/sectotal size is 44867 speedup is 1.63 $

3 synchronize only one file

$rsync-v / var/lib/rpm/Pubkeys / root/temp/Pubkeyssent 42 bytes received 12380 bytes 3549.14 bytes/sectotal size is 12288 speedup is 0.99

4 synchronize files locally to a remote server

$rsync-avz / root/temp/ thegeekstuff@192.168.200.10:/home/thegeekstuff/temp/Password:building file list... Done./rpm/rpm/Basenamesrpm/Conflictnamesent 15810261 bytes received 412 bytes 2432411.23 bytes/sectotal size is 45305958 speedup is 2.87

As you can see, you need to add ssh login method to the remote directory in the format of username@machinename:path

5 synchronize remote files to local

Similar to the above, do the opposite.

$rsync-avz thegeekstuff@192.168.200.10:/var/lib/rpm / root/tempPassword:receiving file list... Donerpm/rpm/Basenames.sent 406 bytes received 15810230 bytes 2432405.54 bytes/sectotal size is 45305958 speedup is 2.87

6 specify remote shell when synchronizing

You can specify a remote ssh with the-e parameter, such as ssh with rsync-e ssh

$rsync-avz-e ssh thegeekstuff@192.168.200.10:/var/lib/rpm / root/tempPassword:receiving file list... Donerpm/rpm/Basenamessent 406 bytes received 15810230 bytes 2432405.54 bytes/sectotal size is 45305958 speedup is 2.87

7 do not overwrite the modified destination file

Use the rsync-u option to exclude modified destination files

$ls-l / root/temp/Basenamestotal 39088-rwxr-xr-x 1 root root 4096 Sep 2 11:35 Basenames$ rsync-avzu thegeekstuff@192.168.200.10:/var/lib/rpm / root/tempPassword:receiving file list … Donerpm/sent 122 bytes received 505 bytes 114.00 bytes/sectotal size is 45305958 speedup is 72258.31$ ls-lrttotal 39088-rwxr-xr-x 1 root root 4096 Sep 2 11:35 Basenames

8 only synchronize directory rights (do not synchronize files)

Use the-d parameter

$rsync-v-d thegeekstuff@192.168.200.10:/var/lib/. Password: receiving file list... Donelogrotate.statusCAM/YaST2/acpi/sent 240 bytes received 1830 bytes 318.46 bytes/sectotal size is 956 speedup is 0.46

9 View the transfer process of each file

Use the-- progress parameter

$rsync-avz-progress thegeekstuff@192.168.200.10:/var/lib/rpm/ / root/temp/Password:receiving file list... 19 files to consider./Basenames5357568 100% 14.98MB/s 0:00:00 (xfer#1, to-check=17/19) Conflictname12288 100% 35.09kB/s 0:00:00 (xfer#2, to-check=16/19)... sent 406 bytes received 15810211 bytes 2108082.27 bytes/sectotal size is 45305958 speedup is 2.87

10 Delete files created in the destination folder

With the-- delete parameter

# Source and target are in sync. Now creating new file at the target.$ > new-file.txt$ rsync-avz-- delete thegeekstuff@192.168.200.10:/var/lib/rpm/. Password: receiving file list... Donedeleting new-file.txt./sent 26 bytes received 390 bytes 48.94 bytes/sectotal size is 45305958 speedup is 108908.55

11 do not create new files in the destination folder

Sometimes if you want to synchronize only the files that exist in the destination and exclude the new files in the source file, you can use the-- exiting parameter

$rsync-avz-existing root@192.168.1.2:/var/lib/rpm/. Root@192.168.1.2's password:receiving file list... Done./sent 26 bytes received 419 bytes 46.84 bytes/sectotal size is 88551424 speedup is 198991.96

12 View the changes between the source and destination files

With the-I parameter

$rsync-avzi thegeekstuff@192.168.200.10:/var/lib/rpm/ / root/temp/Password:receiving file list... Done > f.st... . Basenames.f... .og. Dirnamessent 48 bytes received 2182544 bytes 291012.27 bytes/sectotal size is 45305958 speedup is 20.76

In the output, nine more letters are displayed at the front of each file, represented as

> has been transmitted

F indicates that this is a file

D indicates that this is a directory

S indicates that the size has been changed

There is a change in t time stamp

O user changed

G user group changed

13 enable include and exclude modes during transmission

$rsync-avz-- include 'playing'-- exclude'* 'thegeekstuff@192.168.200.10:/var/lib/rpm/ / root/temp/Password:receiving file list... Done./PackagesProvidenameProvideversionPubkeyssent 129 bytes received 10286798 bytes 2285983.78 bytes/sectotal size is 32768000 speedup is 3.19

14 do not transfer large files

Use the-- max-size parameter

$rsync-avz-max-size='100K' thegeekstuff@192.168.200.10:/var/lib/rpm/ / root/temp/Password:receiving file list... Done./ConflictnameGroupInstalltidNameSha1headerSigmd5Triggernamesent 252 bytes received 123081 bytes 18974.31 bytes/sectotal size is 45305958 speedup is 367.35

15 transfer all files

Transfer all the files again, with or without changes, with the-W parameter

# rsync-avzW thegeekstuff@192.168.200.10:/var/lib/rpm/ / root/tempPassword:receiving file list... Done./BasenamesConflictnameDirnamesFilemd5sGroupInstalltidNamesent 406 bytes received 15810211 bytes 2874657.64 bytes/sectotal size is 45305958 speedup is 2.87 are all the contents of this article entitled "how to use Rsync, a remote backup tool for Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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