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 ...
随机推荐
- Android 虹软2.0人脸识别,注册失败问题 分析synchronized的作用
人脸识别需要init初始化(FaceServer中),离开时需要unInit销毁:当一个含有人脸识别的界面A跳向另一个含有人脸识别的界面B时,由于初始化和销毁都是对FaceServer类加锁(sync ...
- flex属性导图
声明:部分图片转载自 http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html?utm_source=tuicool
- 最接近的三数之和(java实现)
题目: 给定一个包括 n 个整数的数组 nums 和 一个目标值 target.找出 nums 中的三个整数,使得它们的和与 target 最接近.返回这三个数的和.假定每组输入只存在唯一答案. 例如 ...
- 想做AI测试,需要学习哪些数学知识?
摘自知乎的回答 作者:者也 以上是个人读研以来感受用得最多的数学基础课,挂一漏万,大侠请补充指正 高等数学是基础中的基础,研究生以上级别的一切理工科都需要这个打底,数据挖掘.人工智能.模式识别此类跟数 ...
- guxh的python笔记三:装饰器
1,函数作用域 这种情况可以顺利执行: total = 0 def run(): print(total) 这种情况会报错: total = 0 def run(): print(total) tot ...
- Mysql按周,按月,按日,按小时分组统计数据
按周 select DATE_FORMAT(create_time,'%Y%u') weeks,count(caseid) count from tc_case group by weeks; ...
- Guava:好用的java类库 学习小记
基础功能 google guava中定义的String操作 在google guava中为字符串操作提供了很大的便利,有老牌的判断字符串是否为空字符串或者为null,用指定字符填充字符串,以及拆分合并 ...
- Android开发 ---xml构建选项菜单、上下文菜单(长按显示菜单)、发通知、发送下载通知
1.activity_main.xml 描述: 定义了一个TextView和三个按钮 <?xml version="1.0" encoding="utf-8&quo ...
- Echarts tooltip 坐标值修改
tooltip: { trigger: 'axis', position:function(p){ //其中p为当前鼠标的位置 console.log(p); ] + , p[] - ]; } },
- java学习笔记38(sql注入攻击及解决方法)
上一篇我们写了jdbc工具类:JDBCUtils ,在这里我们使用该工具类来连接数据库, 在之前我们使用 Statement接口下的executeQuery(sql)方法来执行搜索语句,但是这个接口并 ...