当前位置:网站首页>【shell脚本】——归档文件脚本
【shell脚本】——归档文件脚本
2022-07-06 08:58:00 【chaolei_9527】
需求
首先要对进行文件归档的目录,判断是否存在。如果存在,则进行文件归档,如果不存在,则标明该目录无法进行文件归档,并指出。
注意的点
1)对于tar命令,-f参数选项要放到最后,否则会如下错误
代码
存储需要进行文件归档的目录的配置文件:
cat conf_file
/root/tools
/root/software
/root/shell-ch
# 目录并不存在
/root/Dir_not_exist
脚本实现如下:
#!/bin/bash
DATE=$(date +%y%m%d)
FILE=archive$DATE.tar.gz
DESTINATION=/root/$FILE
[ ! -f conf_file ] && {
echo "there is no conf_file"
echo "Backup not completed due to missing Configuration File"
echo
exit 1
}
FILE_NO=1
confs=`cat conf_file | grep -v "^#"`
for single in $confs
do
#echo "$single"
if [ -f $single -o -d $single ];then
FILE_LIST="$FILE_LIST $single"
else
echo
echo "$single,do not exist............"
echo "It is on line $FILE_NO of the conf_file"
echo
fi
FILE_NO=$[$FILE_NO + 1]
done
echo "FILE_LIST : $FILE_LIST"
echo "Starting archive............"
echo
tar -czf $DESTINATION $FILE_LIST 2> /dev/null
echo "Archive completed........."
echo "The archive file is: $DESTINATION "
echo
边栏推荐
- 【剑指offer】序列化二叉树
- Simple use of promise in uniapp
- Show slave status \ read in G_ Master_ Log_ POS and relay_ Log_ The (size) relationship of POS
- Variable length parameter
- LeetCode:387. The first unique character in the string
- Unsupported operation exception
- [OC-Foundation框架]--<Copy对象复制>
- BMINF的后训练量化实现
- [OC]-<UI入门>--常用控件的学习
- Detailed explanation of dynamic planning
猜你喜欢
注意力机制的一种卷积替代方式
Selenium+pytest automated test framework practice (Part 2)
Intel distiller Toolkit - Quantitative implementation 3
数学建模2004B题(输电问题)
Simclr: comparative learning in NLP
广州推进儿童友好城市建设,将探索学校周边200米设安全区域
Mongodb installation and basic operation
Esp8266-rtos IOT development
【剑指offer】序列化二叉树
BMINF的后训练量化实现
随机推荐
LeetCode:836. 矩形重叠
Intel Distiller工具包-量化实现1
What is an R-value reference and what is the difference between it and an l-value?
多元聚类分析
[embedded] cortex m4f DSP Library
[oc foundation framework] - < copy object copy >
[OC]-<UI入门>--常用控件-UIButton
LeetCode:41. Missing first positive number
[today in history] February 13: the father of transistors was born The 20th anniversary of net; Agile software development manifesto was born
注意力机制的一种卷积替代方式
requests的深入刨析及封装调用
UML圖記憶技巧
Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges
[Hacker News Weekly] data visualization artifact; Top 10 Web hacker technologies; Postman supports grpc
LeetCode:214. 最短回文串
Navicat Premium 创建MySql 创建存储过程
LeetCode:41. 缺失的第一个正数
Mongodb installation and basic operation
力扣每日一题(二)
Cesium draw points, lines, and faces