成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Linux 中 Rsync 備份數據使用實例

系統 Linux
rsync工具用于將文件和目錄從一個位置同步到另一個位置。同步的位置可以在本地服務器或遠程服務器上。

[[404604]]

rsync工具用于將文件和目錄從一個位置同步到另一個位置。同步的位置可以在本地服務器或遠程服務器上。

在Centos中使用下面命令安裝rsync:

  1. [root@localhost ~]# yum -y install rsync 

實例一:本機中的兩個目錄進行同步

要同步本地計算機中的兩個目錄,使用rsync -zvr命令:

  1. [root@localhost ~]# rsync -zvr /var/log/ /root/temp
  2. sending incremental file list 
  3. btmp 
  4. dnf.librepo.log 
  5. ... 
  6. sssd/sssd_implicit_files.log 
  7. sssd/sssd_nss.log 
  8. tuned/tuned.log 
  9.  
  10. sent 516,136 bytes  received 605 bytes  1,033,482.00 bytes/sec 
  11. total size is 5,451,242  speedup is 10.55 

參數解釋:

  • -z 啟用壓縮
  • -v 輸出詳細信息
  • -r 表示遞歸

查看一下/root/temp目錄,發現rsync在同步期間未保留時間戳。

實例二:使用rsync -a在同步期間保留時間戳

rsync命令的-a選項表示存檔模式。-a選項遞歸同步、保留符號鏈接、保留權限、保留時間戳、保留所有者和組。

現在,執行以下命令,然后查看文件的時間:

  1. [root@localhost ~]# rsync -azv /var/log/ /root/temp
  2. sending incremental file list 
  3. ./ 
  4. btmp 
  5. dnf.librepo.log 
  6. dnf.log 
  7. dnf.rpm.log 
  8. ... 
  9. sssd/sssd_nss.log 
  10. tuned/ 
  11. tuned/tuned.log 
  12.  
  13. sent 516,231 bytes  received 629 bytes  1,033,720.00 bytes/sec 
  14. total size is 5,451,789  speedup is 10.55 

如下所示,rsync在同步期間保留了時間戳。

實例三:將文件從本地同步到遠程目錄

rsync允許在本地和遠程系統之間同步文件/目錄,前提是本地和遠程系統都要安裝rsync才行,否則會提示如下信息:

  1. [root@localhost ~]# rsync -avz /root/temp/ root@192.168.43.137:/root/temp 
  2. root@192.168.43.137's password:  
  3. sending incremental file list 
  4. created directory /root/temp 
  5. ./ 
  6. btmp 
  7. dnf.librepo.log 
  8. dnf.log 
  9. dnf.rpm.log 
  10. ... 
  11. sssd/sssd_nss.log 
  12. tuned/ 
  13. tuned/tuned.log 
  14.  
  15. sent 516,231 bytes  received 662 bytes  206,757.20 bytes/sec 
  16. total size is 5,451,789  speedup is 10.55 

下面是在遠程系統里面查看已同步的目錄:

上面可以看到同步時需要輸入密碼,有時候不希望將文件從本地服務器備份到遠程服務器時輸入密碼,可以在兩臺主機間設置免密要登錄。

實例四:將文件從遠程目錄同步到本地

要將文件從遠程系統同步到本地時,如下所示,在源中指定遠程路徑,在目標中指定本地路徑即可:

  1. [root@localhost ~]# rsync -avz root@192.168.43.137:/root/temp /root/temp 
  2. root@192.168.43.137's password:  
  3. receiving incremental file list 
  4. temp
  5. temp/btmp 
  6. temp/dnf.librepo.log 
  7. temp/dnf.log 
  8. ... 
  9. temp/tuned/ 
  10. temp/tuned/tuned.log 
  11.  
  12. sent 634 bytes  received 516,247 bytes  206,752.40 bytes/sec 
  13. total size is 5,451,789  speedup is 10.55 

實例五:不要覆蓋目標位置上已修改的文件

如果在目標位置修改了文件,我們可能不想用源位置的舊文件覆蓋該文件。使用-u選項就可以做到這一點。在下面的示例中,在本地將test.txt文件修改了內容。它不會被遠程系統的test.txt文件所覆蓋:

  1. # 查看一下遠程系統temp目錄下的test.txt文件大小 
  2. [root@localhost ~]# ssh root@192.168.43.137 ls -l /root/temp 
  3. root@192.168.43.137's password:  
  4. total 4 
  5. -rw-r--r--. 1 root root 7 Apr  7  2021 test.txt 
  6. # 查看一下本機的temp目錄下的test.txt文件大小,本機的test.txt文件已修改,所以比遠程系統里面的test.txt文件大 
  7. [root@localhost ~]# ll /root/temp
  8. total 4 
  9. -rw-r--r--. 1 root root 77 Apr  7 21:10 test.txt 
  10. # 執行rsync -avzu同步一下 
  11. [root@localhost ~]# rsync -avzu root@192.168.43.137:/root/temp /root/ 
  12. root@192.168.43.137's password:  
  13. receiving incremental file list 
  14.  
  15. sent 25 bytes  received 76 bytes  40.40 bytes/sec 
  16. total size is 7  speedup is 0.07 

下面查看一下本機的/root/temp目錄里面的test.txt是否被覆蓋:

發現并沒有被覆蓋。

實例六:在傳輸過程中查看rsync進度

使用--progress選項顯示rsync執行的詳細進度,如下所示:

  1. [root@localhost ~]# rsync -avz --progress /root/temp/ root@192.168.43.137:/root/temp 

實例七:在目標目錄中刪除源目錄不存在的文件

如果文件不在源中而是在目標中存在,則可能希望在rsync同步期間刪除目標上的文件。在這種情況下,請使用--delete選項:

  1. # 查看一下源目錄里面的文件 
  2. [root@localhost ~]# ll /root/temp
  3. total 0 
  4. -rw-r--r--. 1 root root 0 Apr  7 21:46 name.csv 
  5. # 查看一下目標目錄里面的文件 
  6. [root@localhost ~]# ssh root@192.168.43.137 ls -l /root/temp 
  7. root@192.168.43.137's password:  
  8. total 944 
  9. drwxr-xr-x. 2 root root      6 Apr  7  2021 anaconda 
  10. drwx------. 2 root root      6 Apr  7  2021 audit 
  11. -rw-------. 1 root root      0 Apr  7  2021 btmp 
  12. -rw-------. 1 root root      0 Apr  7  2021 btmp-20210406 
  13. drwxr-xr-x. 2 root root      6 Apr  7  2021 chrony 
  14. -rw-------. 1 root root   8432 Apr  7  2021 cron 
  15. -rw-------. 1 root root  12200 Apr  7  2021 cron-20210221 
  16. -rw-------. 1 root root  48130 Apr  7  2021 cron-20210228 
  17. -rw-------. 1 root root   3910 Apr  7  2021 cron-20210308 
  18. -rw-------. 1 root root  22455 Apr  7  2021 cron-20210406 
  19. -rw-------. 1 root root 383369 Apr  7  2021 dnf.librepo.log 
  20. -rw-------. 1 root root 476949 Apr  7  2021 dnf.librepo.log-20210221 
  21. # rsync使用--delete選項刪除目標目錄中不包含源目錄的文件 
  22. [root@localhost ~]# rsync -avz --delete /root/temp root@192.168.43.137:/root 
  23. root@192.168.43.137's password:  
  24. sending incremental file list 
  25. deleting temp/chrony/ 
  26. deleting temp/audit/ 
  27. deleting temp/anaconda/ 
  28. deleting temp/dnf.librepo.log-20210221 
  29. deleting temp/dnf.librepo.log 
  30. deleting temp/cron-20210406 
  31. deleting temp/cron-20210308 
  32. deleting temp/cron-20210228 
  33. deleting temp/cron-20210221 
  34. deleting temp/cron 
  35. deleting temp/btmp-20210406 
  36. deleting temp/btmp 
  37. temp
  38. temp/name.csv 
  39.  
  40. sent 123 bytes  received 281 bytes  161.60 bytes/sec 
  41. total size is 0  speedup is 0.00 

在查看一下目標目錄是否刪除:

實例八:文件傳輸過程中的include和exclude模式

rsync允許在進行同步時提供要包括和排除文件或目錄的模式。

  1. [root@localhost ~]# rsync -avz --include 'P*' --exclude '*' root@192.168.43.137:/var/lib/rpm/ /root/temp/ 

在上面的示例中,它僅包括以'P'開頭的文件或目錄,并排除所有其他文件。

實例九:不傳輸大文件

可以使用rsync --max-size選項告訴rsync不要傳輸大于指定大小的文件。

  1. [root@localhost ~]# rsync -avz --max-size='1M' root@192.168.43.137:/var/lib/rpm/ /root/temp/ 

--max-size=1M使rsync僅傳輸小于或等于1M的文件。單位可以是K,M,G等。

還可以使用--min-size=參數,指定傳輸最小文件的大小。

本文轉載自微信公眾號「Linux就該這么學」,可以通過以下二維碼關注。轉載本文請聯系Linux就該這么學公眾號。

 

責任編輯:武曉燕 來源: Linux就該這么學
相關推薦

2021-06-18 10:28:56

Linuxrsync命令

2017-03-01 12:19:17

rsync Linux系統

2010-09-14 09:15:03

RsyncLinux備份遠程數據同步

2011-08-22 16:03:30

linuxVPS備份數據庫

2021-09-13 15:31:28

戴爾

2024-04-12 13:57:51

2011-03-17 16:42:00

2010-05-26 09:01:43

mysqldump備份

2015-08-21 18:58:05

亞馬遜EBS備份增量備份

2009-03-09 20:57:28

linuxrsync文件同步備份

2010-06-07 14:09:12

mysqldump備份

2017-02-10 10:40:29

macOSTime MachinGitlab

2010-10-26 10:02:05

oracle備份命令

2010-03-02 09:47:03

Fedora MySQ

2021-03-01 09:40:54

數據安全軟件

2019-05-17 08:24:11

LinuxLinux備份rsync命令

2022-02-08 12:19:36

LinuxJQ命令

2010-09-13 16:46:10

SQL Server觸

2014-12-23 09:37:09

Linuxrsync

2020-11-12 09:38:31

安全數據勒索軟件
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 国产成人精品一区二区三区网站观看 | 久久国产精品免费一区二区三区 | 日韩在线免费视频 | 免费一级做a爰片久久毛片潮喷 | 精品欧美一区二区三区 | 亚洲一区在线日韩在线深爱 | 嫩草国产 | 免费观看成人性生生活片 | av永久免费 | 波多野结衣中文字幕一区二区三区 | 一级欧美一级日韩片免费观看 | 国产传媒在线观看 | 国产精品久久久久久高潮 | 国产精品一区二区无线 | 精品国产一区二区 | 91精品国产综合久久久密闭 | www.国产一区 | 精品国产青草久久久久96 | 中文字幕在线免费观看 | www.xxxx欧美 | 天天干天天谢 | 午夜精品久久 | 久久99视频免费观看 | 精品欧美一区二区三区久久久小说 | 日韩在线电影 | 欧美激情精品久久久久久 | 成人国产一区二区三区精品麻豆 | 黄色国产| 久久久久国产一区二区三区四区 | 99在线资源| 日本精品一区二区三区在线观看视频 | 国产91在线精品 | 亚洲精品一区中文字幕乱码 | 午夜小视频在线播放 | 日韩精品视频中文字幕 | 中文一区| 国产在线观看av | 国产精品乱码一二三区的特点 | www.操.com| 亚洲人成人一区二区在线观看 | 久久久青草婷婷精品综合日韩 |