2

Rsync的日常使用方法

 8 months ago
source link: https://bajie.dev/posts/20231228-rsync/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Rsync的日常使用方法

2023-12-28 2 分钟阅读

Rsync的基本参数

-a : 归档模式,递归拷贝,带属性。
-u : 同步时目标目录中如果某文件比源中文件时间要新,则保留不动。
-v : 详细显示信息
-z : 压缩
-h : 显示友好信息
-P : 显示传输进度百分比
-R : 使用相对路径,会保留源目录的目录结构。
-e : 使用ssh来传输
  源如果没有/,代表连同目录以及目录下的文件,统统拷贝到目的去
  源如果最后带/,意思是/*,代表只拷贝目录下的文件,不包括目录本身
  
  如果参数中带-R,那无论源后面有无/,都按原有目录状态拷过去

-R 使用相对路径,会保留源目录的目录结构。 如rsync -av /foo/bar/baz.c remote::/tmp/,会将baz.c传到/tmp下, 而使用了-R,则在/tmp下的文件结构将会是foo/bar/baz.c。

下面两种用法一样:

rsync -auvPR --exclude 'upload' new 172.18.34.38::new/
rsync -auvPR --exclude 'upload' ./new 172.18.34.38::new/

大规模传输细小文件的方法:

find ./new -mindepth 6 -maxdepth 6 -type d -print0 | xargs -P 30 -n 60 -I % -0 rsync -auvPR % 172.18.34.38::new/

-print0 -0 find命令有一个特别的参数-print0,指定输出的文件列表以null分隔。然后,xargs命令的-0参数表示用null当作分隔符。 -I -I指定每一项命令行参数的替代字符串。

注意上面,从最底层开始,逐步向上同步。同步完第6个,然后第5个,4 3 2 1 ……

最低的是第6层,每个文件价是一个日期,每个文件夹包含3000个文件左右。

rsync --bwlimit=500

bwlimit的单位是kb,所以500×8=4000kb=4000000,限速是4M(网络单位)

借用ssh

rsync -avzhe ssh backup.tar [email protected]:/backups/

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK