当前位置:网站首页>【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:41. Missing first positive number
- 一改测试步骤代码就全写 为什么不试试用 Yaml实现数据驱动?
- MongoDB 的安装和基本操作
- [text generation] recommended in the collection of papers - Stanford researchers introduce time control methods to make long text generation more smooth
- Compétences en mémoire des graphiques UML
- Mise en œuvre de la quantification post - formation du bminf
- [OC-Foundation框架]--<Copy对象复制>
- LeetCode:394. String decoding
- LeetCode:673. 最长递增子序列的个数
- Intel distiller Toolkit - Quantitative implementation 1
猜你喜欢
Advance Computer Network Review(1)——FatTree
数字人主播618手语带货,便捷2780万名听障人士
LeetCode41——First Missing Positive——hashing in place & swap
Using pkgbuild:: find in R language_ Rtools check whether rtools is available and use sys The which function checks whether make exists, installs it if not, and binds R and rtools with the writelines
【嵌入式】Cortex M4F DSP库
Nacos 的安装与服务的注册
LeetCode:221. 最大正方形
[oc foundation framework] - < copy object copy >
TP-LINK enterprise router PPTP configuration
After reading the programmer's story, I can't help covering my chest...
随机推荐
MySQL uninstallation and installation methods
LeetCode:41. 缺失的第一个正数
IJCAI2022论文合集(持续更新中)
项目连接数据库遇到的问题及解决
Super efficient! The secret of swagger Yapi
Simple use of promise in uniapp
Guangzhou will promote the construction of a child friendly city, and will explore the establishment of a safe area 200 meters around the school
在QWidget上实现窗口阻塞
LeetCode:214. Shortest palindrome string
Leetcode: Jianzhi offer 04 Search in two-dimensional array
LeetCode:162. Looking for peak
Pytest参数化你不知道的一些使用技巧 /你不知道的pytest
LeetCode:剑指 Offer 42. 连续子数组的最大和
MongoDB 的安装和基本操作
Intel Distiller工具包-量化实现3
Post training quantification of bminf
LeetCode:673. Number of longest increasing subsequences
【剑指offer】序列化二叉树
R language uses the principal function of psych package to perform principal component analysis on the specified data set. PCA performs data dimensionality reduction (input as correlation matrix), cus
Niuke winter vacation training 6 maze 2