|
本帖最后由 piazini 于 2022-3-27 21:32 编辑
openwrt的dl目录下载多费事我就不说了,但是每次更新后,都全部打包一遍,浪费时间也浪费空间。
写了sh脚本,方便增量备份。
dl.zip文件下载连接在文末。
2022/03/27:更新内容:
更新后总体显示更简洁,只保留打包好的zip文件和列表文件。其他临时文件删除或隐藏。(提示:按Ctrl+h组合键可显示.点开头的隐藏文件)
*.隐藏了一些记录文件。
*.取消了temp文件。
*.增加清理临时文件。
*.修改了一些命令,支持备份文件夹
*首次使用前,把“openwrt路径”和“旧的dl.zip文件路径”改成你的 - #!/bin/bash
- #!/bin/bash
- # Date:2022/03/12
- # Date:2022/03/27
- #查看dl.zip和lede/dl/文件夹,包的差异
- #并自动复制打包
- datetime=`date +"%Y%m%d"`
- # openwrt的主目录,双引号里修改成你自己openwrt(lede)的dl路径
- openwrt_home=~/lede/dl/
- ## 当前备份shell脚本所在目录,不用改,自动获取sh文件自己所在目录
- sh_pwd=`pwd`
- #echo ${sh_pwd}
- ## 新建目录
- if [ ! -d ~/dl ];then
- mkdir -p ${sh_pwd}/dl/
- fi
- ##新建.last_bak_pkg_lists.txt文件
- if [ ! -f .last_bak_pkg_lists.txt ];then
- echo " " >> .last_bak_pkg_lists.txt
- fi
- ##新建dl_${datetime}.zip_lists.txt文件
- if [ ! -f dl_${datetime}.zip_lists.txt ];then
- echo " " >> dl_${datetime}.zip_lists.txt
- fi
- ## 列出本级当前openwrt(lede)/dl/目录文件
- ls -1 ${openwrt_home} >.current_dl_lists_temp.txt
- ## 列出老的dl.zip包文件名
- unzip -v ~/dl.zip |awk -F'/' '{print $2}' | grep -vE "^$" > .old_dl_zip_lists.txt
- ## 列出dl.zip包里目录内容,对比后,差异放入dl_${datetime}.zip_lists.txt
- #unzip -v dl.zip |awk -F'/' '{print $2}' |grep -v "`cat 2dl.txt`" <-- 错误的过滤顺序
- cat .current_dl_lists_temp.txt| grep -v "`cat .old_dl_zip_lists.txt`"|grep -v "`cat .last_bak_pkg_lists.txt`"| grep -vE "^$" > dl_${datetime}.zip_lists.txt
- ## 备份列表空,则退出
- num_list=`wc -l dl_${datetime}.zip_lists.txt| awk '{print $1}'`
- if [ ${num_list} -eq 0 ];then
- echo ""
- ### 清理已经备份的临时dl文件夹(不是你openwrt(lede)目录的dl文件夹)
- rm -rf dl/
- ### 清理临时文件
- rm -f .current_dl_lists_temp.txt .old_dl_zip_lists.txt dl_${datetime}.zip_lists.txt
- echo "[ info ] Back list is null . wc -l dl_${datetime}.zip_lists.txt = ${num_list}"
- echo ""
- exit
- fi
- ## 备份新包
- cd ${openwrt_home}
- #pwd
- echo "[ info ] Begin copy 'dl_${datetime}.zip_lists.txt'"
- for file in `cat ${sh_pwd}/dl_${datetime}.zip_lists.txt`
- do
- \cp -ar ${file} ${sh_pwd}/dl/
- done
- ##切换回sh文件所在目录
- cd ${sh_pwd}
- pwd
- ##打包
- zip -r dl_${datetime}.zip dl/
- ## 本次备份过的列表追加到上一次列表中
- ## 防止重复备份
- cat ${sh_pwd}/dl_${datetime}.zip_lists.txt >> ${sh_pwd}/.last_bak_pkg_lists.txt
- ## 清理已经备份的临时dl文件夹(不是你openwrt(lede)目录的dl文件夹)
- rm -rf dl/
- ## 清理临时文件
- rm -f .current_dl_lists_temp.txt .old_dl_zip_lists.txt
- echo ""
- echo "[ info ] Backup ZIP file name : dl_${datetime}.zip"
- echo "[ info ] Backup ZIP lists log file name : dl_${datetime}.zip_lists.txt"
- echo ""
- echo "[ info ] Backup 'dl' pkg done."
- echo ""
复制代码
截图:有背景色的就是,增量备份好的压缩包。
问:Linux下为什么不用tar包,用zip打包呢?
答:是为了通用性,win的机器上用打开tar需要额外装软件,而zip大部分系统都默认支持。
dl.zip下载连接:https://pan.baidu.com/s/1j9qZ2G7zyF7h5YF3nQJ4SA
dl文件链接下载来源:http://cnblogs.com/sbkill1r/p/14115667.html
|
|