脚本备份
1 前言
一个问题,一篇文章,一出故事。
今天有个需求需要使用rsync备份差异的问题,于是整理当前章节。
2.1 环境配置
rsync -avP --delete ~/Downloads/ ~/Downloads-Mirror/ mkdir -p ~/Downloads-Diff/ rm -rf ~/Downloads-Diff/*
然后,通过如下文件查看文件,
tree ~/Downloads*
可见如下显示,
/home/will/Downloads ├── haproxy.cfg ├── haproxytool └── haproxytool.conf /home/will/Downloads-Diff /home/will/Downloads-Mirror ├── haproxy.cfg ├── haproxytool └── haproxytool.conf 2 directories, 6 files
2.2 环境配置
2.2.1 新增文件
echo testFile > ~/Downloads/testFile.txt rsync -rltD --delete -b --backup-dir=/home/will/Downloads-Diff/ ~/Downloads/ ~/Downloads-Mirror/ --itemize-changes --out-format="%i|%n"
然后,通过如下文件查看文件的变化,
tree ~/Downloads*
可见如下显示,
/home/will/Downloads ├── haproxy.cfg ├── haproxytool ├── haproxytool.conf └── testFile.txt /home/will/Downloads-Mirror ├── haproxy.cfg ├── haproxytool ├── haproxytool.conf └── testFile.txt 2 directories, 8 files
2.2.2 删除文件
rm -f ~/Downloads/testFile.txt rsync -rltD --delete -b --backup-dir=/home/will/Downloads-Diff/ ~/Downloads/ ~/Downloads-Mirror/ --itemize-changes --out-format="%i|%n"
然后,通过如下文件查看文件的变化,
tree ~/Downloads*
可见如下显示,
/home/will/Downloads ├── haproxy.cfg ├── haproxytool └── haproxytool.conf /home/will/Downloads-Diff └── testFile.txt /home/will/Downloads-Mirror ├── haproxy.cfg ├── haproxytool └── haproxytool.conf 3 directories, 7 files
没有评论