当前位置:网站首页>[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
边栏推荐
- Improved deep embedded clustering with local structure preservation (Idec)
- Nacos installation and service registration
- 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
- Leetcode: Jianzhi offer 03 Duplicate numbers in array
- I-BERT
- LeetCode:39. Combined sum
- 一改测试步骤代码就全写 为什么不试试用 Yaml实现数据驱动?
- [oc]- < getting started with UI> -- common controls uibutton
- Super efficient! The secret of swagger Yapi
- Implement window blocking on QWidget
猜你喜欢
随机推荐
Leetcode刷题题解2.1.1
In depth analysis and encapsulation call of requests
Nacos installation and service registration
LeetCode:836. Rectangle overlap
I-BERT
Selenium+Pytest自动化测试框架实战(下)
Leetcode: Sword finger offer 48 The longest substring without repeated characters
Advanced Computer Network Review(3)——BBR
Mongodb installation and basic operation
MongoDB 的安装和基本操作
Advance Computer Network Review(1)——FatTree
Redis之五大基础数据结构深入、应用场景
BN folding and its quantification
SimCLR:NLP中的对比学习
Advanced Computer Network Review(5)——COPE
[OC-Foundation框架]--<Copy对象复制>
LeetCode:39. Combined sum
随手记01
AcWing 2456. Notepad
LeetCode:34. Find the first and last positions of elements in a sorted array