当前位置:网站首页>[shell script] - archive file script
[shell script] - archive file script
2022-07-06 09:10:00 【chaolei_ nine thousand five hundred and twenty-seven】
Script of archive file
demand
First of all, the directory for file archiving , Judge whether it exists . If there is , Then file , If it doesn't exist , Then it indicates that the directory cannot be archived , And point out that .
Points of attention
1) about tar command ,-f Parameter options should be put at the end , Otherwise, the following errors will occur 
Code
Store the configuration file of the directory that needs to be archived :
cat conf_file
/root/tools
/root/software
/root/shell-ch
# The directory does not exist
/root/Dir_not_exist
The script is implemented as follows :
#!/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
边栏推荐
- Go redis initialization connection
- [OC]-<UI入门>--常用控件的学习
- 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
- UML图记忆技巧
- Booking of tourism products in Gansu quadrupled: "green horse" became popular, and one room of B & B around Gansu museum was hard to find
- Mathematical modeling 2004b question (transmission problem)
- 数学建模2004B题(输电问题)
- Super efficient! The secret of swagger Yapi
- opencv+dlib实现给蒙娜丽莎“配”眼镜
- 五层网络体系结构
猜你喜欢

MYSQL卸载方法与安装方法

What is MySQL? What is the learning path of MySQL

opencv+dlib实现给蒙娜丽莎“配”眼镜

Pytest parameterization some tips you don't know / pytest you don't know

Mathematical modeling 2004b question (transmission problem)
![[OC-Foundation框架]-<字符串And日期与时间>](/img/75/e20064fd0066810135771a01f54360.png)
[OC-Foundation框架]-<字符串And日期与时间>

Advanced Computer Network Review(5)——COPE

数字人主播618手语带货,便捷2780万名听障人士

requests的深入刨析及封装调用

QDialog
随机推荐
Advanced Computer Network Review(5)——COPE
Nacos installation and service registration
Advance Computer Network Review(1)——FatTree
LeetCode:394. String decoding
[MySQL] limit implements paging
Leetcode: Sword finger offer 42 Maximum sum of continuous subarrays
ant-design的走马灯(Carousel)组件在TS(typescript)环境中调用prev以及next方法
Niuke winter vacation training 6 maze 2
【shell脚本】使用菜单命令构建在集群内创建文件夹的脚本
MySQL uninstallation and installation methods
CSP first week of question brushing
LeetCode:39. Combined sum
LeetCode:214. Shortest palindrome string
【图的三大存储方式】只会用邻接矩阵就out了
AcWing 2456. 记事本
Selenium+Pytest自动化测试框架实战
I-BERT
五层网络体系结构
[OC-Foundation框架]-<字符串And日期与时间>
【每日一题】搬运工 (DFS / DP)