当前位置:网站首页>[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
边栏推荐
- Redis之性能指标、监控方式
- SAP ui5 date type sap ui. model. type. Analysis of the parsing format of date
- 项目连接数据库遇到的问题及解决
- LeetCode:394. String decoding
- A convolution substitution of attention mechanism
- 注意力机制的一种卷积替代方式
- [OC-Foundation框架]-<字符串And日期与时间>
- Leetcode: Sword Finger offer 42. Somme maximale des sous - tableaux consécutifs
- MySQL uninstallation and installation methods
- Leetcode刷题题解2.1.1
猜你喜欢
Parameterization of postman
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
Redis之五大基础数据结构深入、应用场景
MYSQL卸载方法与安装方法
Advanced Computer Network Review(3)——BBR
Alibaba cloud server mining virus solution (practiced)
Advanced Computer Network Review(5)——COPE
Selenium+pytest automated test framework practice
Selenium+Pytest自动化测试框架实战
Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges
随机推荐
什么是MySQL?MySql的学习之路是怎样的
Advanced Computer Network Review(5)——COPE
A convolution substitution of attention mechanism
Selenium+Pytest自动化测试框架实战
LeetCode:394. 字符串解码
After reading the programmer's story, I can't help covering my chest...
项目连接数据库遇到的问题及解决
I-BERT
Show slave status \ read in G_ Master_ Log_ POS and relay_ Log_ The (size) relationship of POS
Opencv+dlib realizes "matching" glasses for Mona Lisa
BMINF的后训练量化实现
七层网络体系结构
Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges
Leetcode problem solving 2.1.1
LeetCode:236. The nearest common ancestor of binary tree
LeetCode:836. 矩形重叠
[OC]-<UI入门>--常用控件-UIButton
xargs命令的基本用法
[sword finger offer] serialized binary tree
AcWing 2456. 记事本