首页 > Mysql, Shell > Linux下mysql定时自动备份并FTP到远程脚本

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

2010年8月27日 发表评论 阅读评论

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点执行

分类: Mysql, Shell 标签: , ,
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.