当前位置:网站首页>[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
边栏推荐
- Mathematical modeling 2004b question (transmission problem)
- LeetCode:236. The nearest common ancestor of binary tree
- SimCLR:NLP中的对比学习
- Using label template to solve the problem of malicious input by users
- Super efficient! The secret of swagger Yapi
- 在QWidget上实现窗口阻塞
- 五层网络体系结构
- Pytest's collection use case rules and running specified use cases
- Leetcode刷题题解2.1.1
- Post training quantification of bminf
猜你喜欢
opencv+dlib实现给蒙娜丽莎“配”眼镜
Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges
Once you change the test steps, write all the code. Why not try yaml to realize data-driven?
An article takes you to understand the working principle of selenium in detail
Mathematical modeling 2004b question (transmission problem)
一篇文章带你了解-selenium工作原理详解
Different data-driven code executes the same test scenario
MySQL uninstallation and installation methods
Redis之五大基础数据结构深入、应用场景
CUDA implementation of self defined convolution attention operator
随机推荐
UML diagram memory skills
Improved deep embedded clustering with local structure preservation (Idec)
Seven layer network architecture
LeetCode:162. Looking for peak
[sword finger offer] serialized binary tree
KDD 2022论文合集(持续更新中)
Intel distiller Toolkit - Quantitative implementation 1
Problems encountered in connecting the database of the project and their solutions
Redis之Bitmap
Selenium+Pytest自动化测试框架实战
七层网络体系结构
Advanced Computer Network Review(3)——BBR
Once you change the test steps, write all the code. Why not try yaml to realize data-driven?
QML type: locale, date
[OC-Foundation框架]---【集合数组】
[oc]- < getting started with UI> -- common controls uibutton
随手记01
Leetcode problem solving 2.1.1
Li Kou daily question 1 (2)
Leetcode: Sword Finger offer 42. Somme maximale des sous - tableaux consécutifs