当前位置:网站首页>【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
边栏推荐
- 不同的数据驱动代码执行相同的测试场景
- Digital people anchor 618 sign language with goods, convenient for 27.8 million people with hearing impairment
- [embedded] cortex m4f DSP Library
- [MySQL] limit implements paging
- Using pkgbuild:: find in R language_ Rtools check whether rtools is available and use sys The which function checks whether make exists, installs it if not, and binds R and rtools with the writelines
- 【剑指offer】序列化二叉树
- Leetcode: Sword finger offer 42 Maximum sum of continuous subarrays
- LeetCode:394. String decoding
- LeetCode:673. 最长递增子序列的个数
- To effectively improve the quality of software products, find a third-party software evaluation organization
猜你喜欢
requests的深入刨析及封装调用
[MySQL] multi table query
Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges
opencv+dlib实现给蒙娜丽莎“配”眼镜
Booking of tourism products in Gansu quadrupled: "green horse" became popular, and one room of B & B around Gansu museum was hard to find
CUDA realizes focal_ loss
使用latex导出IEEE文献格式
SimCLR:NLP中的对比学习
[sword finger offer] serialized binary tree
TP-LINK enterprise router PPTP configuration
随机推荐
After reading the programmer's story, I can't help covering my chest...
可变长参数
LeetCode:剑指 Offer 42. 连续子数组的最大和
Leetcode刷题题解2.1.1
Compétences en mémoire des graphiques UML
什么是MySQL?MySql的学习之路是怎样的
项目连接数据库遇到的问题及解决
使用标签模板解决用户恶意输入的问题
LeetCode:498. 对角线遍历
力扣每日一题(二)
LeetCode:836. Rectangle overlap
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Advanced Computer Network Review(3)——BBR
UML图记忆技巧
Simclr: comparative learning in NLP
Export IEEE document format using latex
LeetCode:124. Maximum path sum in binary tree
LeetCode:394. 字符串解码
超高效!Swagger-Yapi的秘密
Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges