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 ...
随机推荐
- 问题1——之Linux虚拟机ip地址消失
原文转自 https://blog.csdn.net/keep_walk/article/details/75115926 以前一直通过ifconfig命令查看ip地址,但是今天用XShell连接自己 ...
- Redis中Pipeline的使用
通过Java访问Redis,我们一般使用Jedis,示例代码如下: Jedis jedis = new Jedis("172.23.88.107", 6379); jedis.se ...
- Python自学:第二章 注释
#向大家问好 print("Hello Python People") 输出为 Hello Python People
- VSCode汉化
1.打开VSCode 点击箭头指示地方 在搜索框中输入chinese 然后安装中文简体 2.按住 Ctrl+shift+p 选择配置显示语言 然后会看见下面的样子 添加 "locale&q ...
- K2在Gartner 2017 iBPMS魔力象限报告中上升为“挑战者”
在Gartner近期发布的iBPMS MQ报告中,Gartner分析了入选的19家厂商,将K2列为智能业务流程管理系统(iBPMS)MQ(魔力象限)的“挑战者”.从下列图中可以看出,相比上期,K2从魔 ...
- Java集合类框架的最佳实践有哪些?
1.根据应用需要正确选择要使用的集合类型对性能非常重要,比如:假如知道元素的大小是固定的,那么选用Array类型而不是ArrayList类型更为合适. 2.有些集合类型允许指定初始容量.因此,如果我们 ...
- Selenium+Eclipse+Python 环境搭建
第一步:安装Python 根据下面的地址,直接一键安装,全部默认方式. 下载地址:http://www.python.org/ftp/python/2.7.5/python-2.7.5.msi 安装到 ...
- 如何ASP.NET Core Razor中处理Ajax请求[转载]
在ASP.NET Core Razor(以下简称Razor)刚出来的时候,看了一下官方的文档,一直没怎么用过. 今天闲来无事,准备用Rozor做个项目熟练下,结果写第一个页面就卡住了..折腾半天才搞好 ...
- DAY 04运算符与流程控制
输入输出补充: python2与python3的输入输出不同 python2中有两种用户 输入方式,一种是raw_input,和input raw_input与python3的input是相同的 而p ...
- 返回指针的函数 ------ 指针函数(pointer function)
指针函数: 其本质是一个函数, 其函数返回值为某一类型的指针. 定义形式: 类型 *指针变量名(参数列表): 例如: int *p(int i,int j); p是一个函数名,该函数有2个整形参数,返 ...