In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "how to use rsync backup data", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use rsync backup data" this article.
Rsync is a software to achieve remote synchronization function, while synchronizing files, you can maintain the permissions of the original files, time, soft and hard links and other additional information. Rsync is a fast algorithm that uses the rsync algorithm to provide file synchronization between the client and the remote file server, and can be transferred in the form of synchronous ssh.
Install rsync in Centos using the following command:
[root@localhost ~] # yum-y install rsync
Example 1: synchronize two directories on this machine
To synchronize two directories on the local computer, use the rsync-zvr command:
[root@localhost] # rsync-zvr / var/log/ / root/temp/sending incremental file listbtmpdnf.librepo.log...sssd/sssd_implicit_files.logsssd/sssd_nss.logtuned/tuned.logsent 516136 bytes received 605 bytes 1033482.00 bytes/sectotal size is 5451242 speedup is 10.55
Parameter explanation:
-z enable compression-v output details-r indicates recursion
Take a look at the / root/temp directory and find that rsync does not retain a timestamp during synchronization.
Example 2: use rsync-a to retain timestamps during synchronization
The-an option of the rsync command indicates the archive mode. The-an option recursively synchronizes, preserves symbolic links, preserves permissions, retains timestamps, retains owners and groups.
Now, execute the following command, and then view the time of the file:
[root@localhost] # rsync-azv / var/log/ / root/temp/sending incremental file list./btmpdnf.librepo.logdnf.logdnf.rpm.log...sssd/sssd_nss.logtuned/tuned/tuned.logsent 516231 bytes received 629 bytes 1033720.00 bytes/sectotal size is 5451789 speedup is 10.55
As shown below, rsync retains a timestamp during synchronization.
Example 3: synchronize files from local to remote directory
Rsync allows you to synchronize files / directories between local and remote systems, provided that rsync is installed on both local and remote systems, otherwise you will be prompted with the following information:
[root@localhost] # rsync-avz / root/temp/ root@192.168.43.137:/root/temproot@192.168.43.137's password:sending incremental file listcreated directory / root/temp./btmpdnf.librepo.logdnf.logdnf.rpm.log...sssd/sssd_nss.logtuned/tuned/tuned.logsent 516231 bytes received 662bytes 206757.20 bytes/sectotal size is 5451789 speedup is 10.55
The following is to view the synchronized directories in the remote system: you can see above that you need to enter a password during synchronization, and sometimes you do not want to enter a password when backing up files from the local server to the remote server. You can set password-free login between the two hosts.
Example 4: synchronize files from the remote directory to the local
To synchronize files from the remote system to the local, specify the remote path in the source and the local path in the destination, as shown below:
[root@localhost ~] # rsync-avz root@192.168.43.137:/root/temp / root/temproot@192.168.43.137's password:receiving incremental file listtemp/temp/btmptemp/dnf.librepo.logtemp/dnf.log...temp/tuned/temp/tuned/tuned.logsent 634 bytes received 516247 bytes 206752.40 bytes/sectotal size is 5451789 speedup is 10.55Linux rsync backup data usage instance Linux backup data usage instance
Example 5: do not overwrite modified files in the target location
If the file is modified at the target location, we may not want to overwrite it with the old file from the source location. You can do this using the-u option. In the following example, the contents of the test.txt file are modified locally. It is not overwritten by the test.txt file of the remote system:
# check the test.txt file size in the remote system temp directory [root@localhost ~] # ssh root@192.168.43.137 ls-l / root/temproot@192.168.43.137's password:total 4Murray RWMI. 1 root root 7 Apr 7 2021 test.txt# check the size of the test.txt file under the local temp directory. The local test.txt file has been modified, so it is larger than the test.txt file in the remote system [root@localhost] # ll / root/temp/total 4Murray. 1 root root 77 Apr 7 21:10 test.txt# execute rsync-avzu synchronization [root@localhost ~] # rsync-avzu root@192.168.43.137:/root/temp / root/root@192.168.43.137's password:receiving incremental file listsent 25 bytes received 76 bytes 40.40 bytes/sectotal size is 7 speedup is 0.07
Let's check to see if the test.txt in the local / root/temp directory is overwritten: it is not overwritten.
Example 6: check the progress of rsync during transmission
Use the-- progress option to display the detailed progress of rsync execution, as follows:
[root@localhost ~] # rsync-avz-- rsync backup data in progress / root/temp/ root@192.168.43.137:/root/tempLinux using instance rsync backup data in Linux
Example 7: delete files in the destination directory that do not exist in the source directory
If the file is not in the source but exists in the destination, you may want to delete the file on the destination during rsync synchronization. In this case, use the-- delete option:
# take a look at the files in the source directory [root@localhost ~] # ll / root/temp/total 0Murray RW Murray. 1 root root 0 Apr 7 21:46 name.csv# check the file [root@localhost ~] # ssh root@192.168.43.137 ls-l / root/temproot@192.168.43.137's password:total 944drwxr-xr-x in the target directory. 2 root root 6 Apr 7 2021 anacondadrwx-. 2 root root 6 Apr 7 2021 audit-rw-. 1 root root 0 Apr 7 2021 btmp-rw-. 1 root root 0 Apr 7 2021 btmp-20210406drwxr-xr-x. 2 root root 6 Apr 7 2021 chrony-rw-. 1 root root 8432 Apr 7 2021 cron-rw-. 1 root root 12200 Apr 7 2021 cron-20210221-rw-. 1 root root 48130 Apr 7 2021 cron-20210228-rw-. 1 root root 3910 Apr 7 2021 cron-20210308-rw-. 1 root root 22455 Apr 7 2021 cron-20210406-rw-. 1 root root 383369 Apr 7 2021 dnf.librepo.log-rw-. 1 rootroot 476949 Apr 7 2021 dnf.librepo.log-20210221# rsync use the-- delete option to delete files in the destination directory that do not contain the source directory [root@localhost ~] # rsync-avz-- delete / root/temp root@192.168.43.137:/rootroot@192.168.43.137's password:sending incremental file listdeleting temp/chrony/deleting temp/audit/deleting temp/anaconda/deleting temp/dnf.librepo.log-20210221deleting temp/dnf.librepo.logdeleting temp/cron-20210406deleting Temp/cron-20210308deleting temp/cron-20210228deleting temp/cron-20210221deleting temp/crondeleting temp/btmp-20210406deleting temp/btmptemp/temp/name.csvsent 123 bytes received 281 bytes 161.60 bytes/sectotal size is 0 speedup is 0.00
Check again to see if the target directory is deleted:
Example 8: include and exclude modes in file transfer
Rsync allows you to provide a mode to include and exclude files or directories when synchronizing.
[root@localhost] # rsync-avz-- include 'playing'-- exclude'* 'root@192.168.43.137:/var/lib/rpm/ / root/temp/
In the above example, it includes only files or directories that start with'P 'and excludes all other files.
Example 9: do not transfer large files
You can use the rsync-- max-size option to tell rsync not to transfer files larger than the specified size.
[root@localhost] # rsync-avz-- max-size='1M' root@192.168.43.137:/var/lib/rpm/ / root/temp/
-- max-size=1M causes rsync to transfer only files less than or equal to 1m. The unit can be K, M, G, etc.
You can also use the-- min-size= parameter to specify the size of the smallest file to be transferred.
The above is all the contents of the article "how to use rsync to back up data". 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.