linux以rsync对文件目录进行备份,利用exclude跳过指定类型文件

有时会有备份某些文件(例如脚本)的需求,但又不想把脚本执行的日志或一些结果文件备份,可以使用rsync中的exclude来解决。

  • 将oldfile文件夹拷贝至oldfile_bak文件夹,但需要过滤掉其中的.log文件
du -ha ./oldfile/ 
4.0K    ./oldfile/a/2222.csv
4.0K    ./oldfile/a/aabb.log
4.0K    ./oldfile/a/4321.sh
4.0K    ./oldfile/a/log/aabb2.log
4.0K    ./oldfile/a/log/1234.sh
12K     ./oldfile/a/log
4.0K    ./oldfile/a/55511.sh
4.0K    ./oldfile/a/data
36K     ./oldfile/a
4.0K    ./oldfile/b/uuss.sh
8.0K    ./oldfile/b
4.0K    ./oldfile/data
52K     ./oldfile/

执行命令:

rsync -av --exclude "*.log" ./oldfile/ ./oldfile_bak

执行结果:

sending incremental file list
./
data
a/
a/2222.csv
a/4321.sh
a/55511.sh
a/data/
a/log/
a/log/1234.sh
b/
b/uuss.sh

sent 568 bytes  received 145 bytes  1426.00 bytes/sec
total size is 43  speedup is 0.06

并没有复制

./oldfile/a/log/aabb2.log
./oldfile/a/log/aabb2.log

  • 将oldfile文件夹拷贝至oldfile_bak文件夹,但需要过滤掉其中的.log、.csv文件、data文件夹及其子文件

建立一个txt文件,将需要过滤掉的文件类型写入
vi exclude.txt
*.log
*.csv
data
执行命令:
rsync -av --exclude-from "exclude.txt" ./oldfile/ ./oldfile_bak  
执行结果:
sending incremental file list
./
a/
a/4321.sh
a/55511.sh
a/log/
a/log/1234.sh
b/
b/uuss.sh

sent 397 bytes  received 103 bytes  1000.00 bytes/sec
total size is 26  speedup is 0.05

.log、.csv以及data目录都没有被复制。




  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值