Linux下mysql定时自动备份并FTP到远程脚本
Posted 岁月如梭
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux下mysql定时自动备份并FTP到远程脚本相关的知识,希望对你有一定的参考价值。
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到远程脚本的主要内容,如果未能解决你的问题,请参考以下文章