码迷,mamicode.com
首页 > 数据库 > 详细

Linux下mysql定时自动备份并FTP到远程脚本

时间:2017-02-22 16:30:28      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:this   www   ase   shel   path   shell   .com   off   mysqld   

1.添加backupmysqleveryday.sh(vi /data/shell/backupmysqleveryday.sh)
#!/bin/sh
#this shell is user for backup mysql data everyday
#author:www.ieliwb.com
#path-config
base_mysql_path=/data/webserver/mysql/
mysql_dump_path=/data/mysqlbackup/
mnt_back_path=/mnt/web/mysqlbackup/
ftp_back_path=mysql_data_backup/
#mysql-config
mysql_user=”root”
mysql_pass=”*******”
#ftp-config
ftp_host=”ip”
ftp_user=”********”
ftp_pass=”********”
backup_name=`date +%Y%m%d%H%M%S`
cd ${mysql_dump_path}
#mysqldump
${base_mysql_path}bin/mysqldump -u${mysql_user} -p${mysql_pass} -all-database > ${backup_name}.sql
#pack
tar zcf ${backup_name}.tar.gz ${backup_name}.sql
rm -f ${backup_name}.sql
#backup to mnt
cp ${backup_name}.tar.gz ${mnt_back_path}${backup_name}.tar.gz
#ftp to other host
ftp -n<
open ${ftp_host}
user ${ftp_user} ${ftp_pass}
bin
prompt off
cd ${ftp_back_path}
passive
put ${backup_name}.tar.gz
close
bye
!

2.添加定时计划(vi /etc/crontab)
01 0 * * * root /data/shell/backupmysqleveryday.sh
每天0:01点执行

Linux下mysql定时自动备份并FTP到远程脚本

标签:this   www   ase   shel   path   shell   .com   off   mysqld   

原文地址:http://www.cnblogs.com/hesitation/p/6429462.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!