当前位置:网站首页>【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:673. Number of longest increasing subsequences
- SAP ui5 date type sap ui. model. type. Analysis of the parsing format of date
- Pytorch view tensor memory size
- What is an R-value reference and what is the difference between it and an l-value?
- 甘肃旅游产品预订增四倍:“绿马”走红,甘肃博物馆周边民宿一房难求
- LeetCode:673. 最长递增子序列的个数
- 数字人主播618手语带货,便捷2780万名听障人士
- Marathon envs project environment configuration (strengthen learning and imitate reference actions)
- BN折叠及其量化
- LeetCode:剑指 Offer 42. 连续子数组的最大和
猜你喜欢

Esp8266-rtos IOT development

多元聚类分析

UML圖記憶技巧

LeetCode:124. Maximum path sum in binary tree

Post training quantification of bminf

Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges

甘肃旅游产品预订增四倍:“绿马”走红,甘肃博物馆周边民宿一房难求
![[OC-Foundation框架]---【集合数组】](/img/b5/5e49ab9d026c60816f90f0c47b2ad8.png)
[OC-Foundation框架]---【集合数组】

I-BERT

Excellent software testers have these abilities
随机推荐
CUDA implementation of self defined convolution attention operator
如何正确截取字符串(例:应用报错信息截取入库操作)
vb. Net changes with the window, scales the size of the control and maintains its relative position
[OC-Foundation框架]-<字符串And日期与时间>
IJCAI2022论文合集(持续更新中)
BMINF的后训练量化实现
Leetcode刷题题解2.1.1
A convolution substitution of attention mechanism
Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges
TDengine 社区问题双周精选 | 第三期
[oc]- < getting started with UI> -- learning common controls
Notes 01
Advanced Computer Network Review(5)——COPE
[MySQL] limit implements paging
Problems encountered in connecting the database of the project and their solutions
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
Using C language to complete a simple calculator (function pointer array and callback function)
Niuke winter vacation training 6 maze 2
What is the role of automated testing frameworks? Shanghai professional third-party software testing company Amway
LeetCode:剑指 Offer 48. 最长不含重复字符的子字符串