linux mysql 自动备份 ftp自动上传脚本

#!/bin/bash
date=`date +%Y-%m-%d`
#定义网站根目录、备份目录、备份网站目录文件名
webroot=/var/www/html
backuppath=/backup

mkdir $backuppath
htmlbackup=jf_html_`date +%Y-%m-%d`.zip
#定义数据库备份的用户名、密码、数据库名、备份文件名
dbuser=root
dbpasswd=dbpasswd
dbname=dbname
dumpfilename=$dbname-`date +%Y-%m-%d`.sql
#定义要上传到ftp上文件名
ftpbackname=jf_`date +%Y-%m-%d`.zip
ftpserver=111.111.111.111
ftpuser=administrator
ftppasswd=password
#shell
cd $webroot
zip -q -r /$backuppath/$htmlbackup  *
mysqldump -u$dbuser -p$dbpasswd $dbname >/$backuppath/$dumpfilename
cd $backuppath
zip -q -r  $ftpbackname *
rm -rf $htmlbackup $dumpfilename
ftp -n<<!
open $ftpserver
user $ftpuser $ftppasswd
bin
cd backup
mkdir $date
cd $date
hash
prompt
put $ftpbackname
close
bye
!
rm -rf $backuppath
点赞