当前位置:网站首页>【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
边栏推荐
- 使用标签模板解决用户恶意输入的问题
- LeetCode:162. Looking for peak
- Leetcode刷题题解2.1.1
- BMINF的後訓練量化實現
- 数字人主播618手语带货,便捷2780万名听障人士
- Guangzhou will promote the construction of a child friendly city, and will explore the establishment of a safe area 200 meters around the school
- Leetcode: Jianzhi offer 03 Duplicate numbers in array
- Intel distiller Toolkit - Quantitative implementation 3
- Post training quantification of bminf
- Pytorch view tensor memory size
猜你喜欢

Intel distiller Toolkit - Quantitative implementation 1
![[MySQL] multi table query](/img/eb/9d54df9a5c6aef44e35c7a63b286a6.jpg)
[MySQL] multi table query

A convolution substitution of attention mechanism

Advanced Computer Network Review(3)——BBR

UML diagram memory skills

Post training quantification of bminf

什么是MySQL?MySql的学习之路是怎样的

vb.net 随窗口改变,缩放控件大小以及保持相对位置

Problems encountered in connecting the database of the project and their solutions
![[sword finger offer] serialized binary tree](/img/e2/25c9322da3acda06c4517b0c50f81e.png)
[sword finger offer] serialized binary tree
随机推荐
SimCLR:NLP中的对比学习
[oc]- < getting started with UI> -- common controls - prompt dialog box and wait for the prompt (circle)
Advanced Computer Network Review(4)——Congestion Control of MPTCP
Notes 01
[embedded] cortex m4f DSP Library
LeetCode:剑指 Offer 04. 二维数组中的查找
Simclr: comparative learning in NLP
LeetCode:394. 字符串解码
Using label template to solve the problem of malicious input by users
opencv+dlib实现给蒙娜丽莎“配”眼镜
vb. Net changes with the window, scales the size of the control and maintains its relative position
To effectively improve the quality of software products, find a third-party software evaluation organization
力扣每日一题(二)
Mise en œuvre de la quantification post - formation du bminf
Implement window blocking on QWidget
Show slave status \ read in G_ Master_ Log_ POS and relay_ Log_ The (size) relationship of POS
CUDA implementation of self defined convolution attention operator
How to effectively conduct automated testing?
Booking of tourism products in Gansu quadrupled: "green horse" became popular, and one room of B & B around Gansu museum was hard to find
LeetCode:387. 字符串中的第一个唯一字符