当前位置:网站首页>Shell comprehensive application cases, archive files
Shell comprehensive application cases, archive files
2022-07-26 20:46:00 【Redamancy06】
List of articles
1. The archive
In practical production application , It is often necessary to archive and back up important data .
demand : Implement a script that archives and backs up the specified directory every day , Enter a directory name ( It doesn't end with /), Archive and save all files in the directory on a daily basis , And attach the filing date to the file name , Put it in /root/archive Next .
The archive command is used here : tar
You can add -c Option means archive , add -z Option means to compress at the same time , The resulting file suffix is .tar.gz
1.1 Script implementation

#!/bin/bash
# First, judge whether the number of input parameters is 1
if [ $# -ne 1 ]
then
echo " Wrong number of parameters ! You should enter a parameter , As the archive directory name "
exit
fi
# Get the directory name from the parameter
if [ -d $1 ]
then
echo
else
echo
echo " directory does not exist !"
echo
exit
fi
DIR_NAME=$(basename $1)
DIR_PATH=$(cd $(dirname $1); pwd)
# Get current date
FILE=archive_${
DIR_NAME}_$DATE.tar.gz
DEST=/root/archive/$FILE
# Start archiving catalog files
echo " Start filing ..."
echo
tar -czf $DEST $DIR_PATH/$DIR_NAME
if [ $? -eq 0 ]
then
echo
echo " Archive success !"
echo " Archive file is :$DEST"
echo
else
echo " There is a problem with archiving !"
echo
fi
exit
1.2 test



Then create a file 

Archive success
1.3 Regular filing
Use crontab
crontab The code in
0 2 * * * /root/scripts/daily_archive.sh /root/scripts

边栏推荐
- Numpy中ndarray的常见操作
- 培训软件测试能不能就业
- 消息队列——引入的问题:重复消费&顺序消费&分布式事务
- Establishment of APP automation testing framework (VIII) -- establishment of ATX server2 multi device cluster environment
- hello 你好吗
- Installation and configuration of [basic services] [database] Clickhouse
- Correct the classpath of your application so that it contains compatible versions of the classes com
- Experiment 6 BGP federal comprehensive experiment
- 软件测试-开发提测内容规范(项目提测模板)
- Keepalived高可用介绍与配置详解
猜你喜欢

消息队列——引入的问题:重复消费&顺序消费&分布式事务

Execution context and Lexical Environment

【微信小程序】零基础学 | 小程序语法
![Shell函数、系统函数、basename [string / pathname] [suffix] 可以理解为取路径里的文件名称 、dirname 文件绝对路径、自定义函数](/img/3d/d7276d2010f1d77a3bd572cc66eced.png)
Shell函数、系统函数、basename [string / pathname] [suffix] 可以理解为取路径里的文件名称 、dirname 文件绝对路径、自定义函数

如何组装一个注册中心?
![[基础服务] [数据库] ClickHouse的安装和配置](/img/fe/5c24e4c3dc17a6a96985e4fe97024e.png)
[基础服务] [数据库] ClickHouse的安装和配置

Houdini 求中点,点连成线

Experiment 6 BGP federal comprehensive experiment
![[experiment sharing] CCIE BGP routing black hole experiment]](/img/c8/7ccb879ad7c739d3573637fd14f4e1.png)
[experiment sharing] CCIE BGP routing black hole experiment]

Shell综合应用案例,归档文件
随机推荐
App uploader download and installation
从零开始搭建Prometheus自动监控报警系统
09_ue4进阶_进入下一关并保留血量
Keepalived高可用介绍与配置详解
BGP--边界网关协议
Experiment 6 BGP federal comprehensive experiment
BUU刷题记4
【Delphi】FMX Form的BorderStyles不同平台说明
Summary of message queue knowledge points
培训软件测试能不能就业
HM中如何获取CU块划分信息并用Matlab绘图
[experiment sharing] CCIE BGP routing black hole experiment]
It is said that HP / Dell / Microsoft / Amazon are considering transferring some hardware production lines outside the mainland
解决IBGP的水平分割和BGP选路原则
如何查看你使用的pytorch是否为GPU版本
Can the training software test be employed
Common operations of ndarray in numpy
QT driving school subject examination system -- from implementation to release
Leetcode-300 longest increasing subsequence
美司法部律师团队要求法官拒绝受理华为诉讼