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