shell脚本实现定时备份某文件
1:目标




#!/bin/bash
input_sourcefile_location(){
dialog --title "Input you base information" --form "Please enter you information about mysql backup information: (Please input Absolutely location) \nThe source location is you need backups file" "The source file location:" "" > /tmp/source.location
result=$?
if [ $result -eq ] ;then
echo -e "\e[2J\e[1;1H"
exit ;
elif [ $result -eq ] ;then
echo -e "\e[2J\e[1;1H"
exit ;
fi
input_destination_dir
} input_destination_dir(){
dialog --title "Input you base information" --form "Please enter you information about mysql backup information: (Please input Absolutely location) \nThe distination dir (you only need input the dir,everydays back file will output the dir where use date is dir) is you need backups file" "The destination dir location:" "" > /tmp/destination_dir
result=$?
if [ $result -eq ] ;then
input_sourcefile_location;
elif [ $result -eq ] ;then
echo -e "\e[2J\e[1;1H"
exit ;
fi
set_crontab_time
}
set_crontab_time(){
dialog --title "Input you base information" --form "Please enter you information about mysql backup information: \nThe crontab seting ,minutes,hours,day,mouth,week (eg:* */2 * * *) " "The minutes set:" "" "The hours set:" "" "The day set:" "" "The month set:" "" "The week set:" "" > /tmp/crontab
result=$?
echo $result > lll
if [ $result -eq ] ;then
input_destination_dir
elif [ $result -eq ] ;then
echo -e "\e[2J\e[1;1H"
exit ;
fi
crontab_exec
}
crontab_exec(){
cat /tmp/crontab |tr "\n" " " > /tmp/day
sed -i 's/$/export DISPLAY=:0.0 ;gnome-terminal -x \/bin\/bash -c "\/shell\/2.sh 2>>\/tmp\/log" /g' /tmp/day
cat /tmp/day >> /var/spool/cron/root
echo >> /var/spool/cron/root
}
input_sourcefile_location
#!/bin/bash
dirname=`date +%Y%m%d%H%M`
destination_dir=`cat /tmp/destination_dir`
source_file=`cat /tmp/source.location`
source_dir=`echo ${source_file%/*}`
file_name=`awk -F / '{print $NF}' /tmp/source.location`
tar_file=$file_name.tar.gz if [ ! -d $destination_dir ] ;then
mkdir -p $destination_dir
fi
mkdir $destination_dir/$dirname
cd $source_dir
tar -zcf $tar_file $file_name
cp $tar_file $destination_dir/$dirname
rm -rf $tar_file
shell脚本实现定时备份某文件的更多相关文章
- 用shell脚本实现定时备份数据库
1.备份数据库的方法 可以使用命令查看 ls /usr/local/mysql/bin 这个mysqldump就是系统内置的用来备份数据库的工具. 2.实现方法 ①先随便进入一个位置创建一个目录 ② ...
- 【shell脚本】定时备份日志===logBackup.sh
定时备份日志 设置执行权限 [root@VM_0_10_centos shellScript]# chmod a+x logBackup,sh 脚本内容 [root@VM_0_10_centos sh ...
- 【shell脚本】定时备份数据库===dbbackup.sh
定时备份数据库是很有必要的 一.脚本内容 [root@localhost dbbackup]# cat dbbackup.sh #!/bin/bash #备份数据库 mysqldump -uroot ...
- shell 脚本实现定时备份mysql数据库
首先要知道直接在脚本中输入mysql的密码是不被允许的,但是我们可以曲线救国 1. 在新建一个文件专门用来存储用户密码 如: vim ./.mysql.conf [mysqldump] user=yo ...
- shell脚本----周期压缩备份日志文件
一.日志文件样式 二.目标 1.备份压缩.log结尾&&时间样式为“date +%Y%m%d”的日志文件(如:20170912.20160311等) 2.可指定压缩范围(N天前至当天) ...
- CentOS/Linux内存占用大,用Shell脚本自动定时清除/释放内存
CentOS/Linux内存占用大,用Shell脚本自动定时清除/释放内存来自:互联网 时间:2020-03-22 阅读:114以下情况可能造成Linux内存占用过高服务配置存在直接分配错误,或隐性分 ...
- Shell脚本调用ftp上传文件
Shell脚本调用ftp上传文件 1.脚本如下 ftp -n<<! open x.x.x.x ###x.x.x.x为ftp地址 user username password ###user ...
- Centos上通过shell脚本实现数据库备份和还原
最近有个这样的需求,通过shell脚本实现数据库备份还原,最后通过网上查询自己测试实现,将脚本分享给大家 1.数据库备份脚本 #!/bin/bash ds=`` list=`date +%Y`/`da ...
- 七牛云qshell工具定时备份空间文件到本地
qshell 是利用七牛文档上公开的 API实现的一个方便开发者测试和使用七牛API服务的命令行工具,使用该工具可以实现很多的功能,今天就分享一下利用qshell定时备份空间文件到本地 1.下载qsh ...
随机推荐
- HDFS常用操作命令
启动hdfs#start-all.sh查看hdfs的配置文件#cat hdfs-site.sh#hadoop fs -put /soft/jdk /#HDFS上传文件命令查看上传后的文件属性#hado ...
- 更改ssh,ftp默认端口
1. 更改ssh端口 放置升级openssh之后做此步骤 配置文件/etc/ssh/sshd_config 注释掉Subsystem sftp /usr/libexec/openss ...
- Java原生API访问MongoDB
1.pom.xml <dependency> <groupId>org.mongodb</groupId> <artifactId>mongo-java ...
- Ruby on Rails Tutorial 第一章笔记
搭建开发环境 作者介绍了 Cloud9\ Coding.net 这样的云端开发环境 安装 Rails 1. 新建 rails 应用 首先,调用 rails new 命令创建一个新的 Rails 应用, ...
- 安卓MVP框架
一.理解MVP 原文地址 我的Demo 效果图: 项目结构: 实现 一.Model层 首先定义一个实体类User package app.qcu.pmit.cn.mvpdemo.model; /** ...
- CAM(Content Addressable Memory)介绍
CAM是一种特殊的存储器.所谓CAM,即内容寻址存储器.CAM存储器在其每个存储单元都包含了一个内嵌的比较逻辑,写入CAM的数据会和其内部存储的每一个数据进行比较,并返回与端口数据相同的所有内部数据的 ...
- 『Python』多进程处理
尝试学习python的多进程模组,对比多线程,大概的区别在: 1.多进程的处理速度更快 2.多进程的各个子进程之间交换数据很不方便 多进程调用方式 进程基本使用multicore() 进程池优化进程的 ...
- ProtoBuf3.3 安装记录
翻了很多教程,下载了 PB 的源码在自己的 mac 上编译及安装,记录下新的 1. 首先是下载源码了 https://github.com/google/protobuf/releases 虽然是 g ...
- QChartView绘制饼状图
效果图: #include "mainwindow.h" #include "form.h" #include <QApplication> #in ...
- GDT全局描述符表
GDT全局描述符表 什么是GDT全局描述符表 GDT全称为Global Descriptor Table,全局描述符表. 保护模式的寻址方式不在使用寄存器分段的方式直接寻址方式了.而采用的是使用GDT ...