本站即日起正式部署SSL证书启用https安全连接, 联系站长:416326801#qq.com(#改成@)

Latest from the blog

备份Mysql并上传到ftp服务器

标签: 备份 MySQL Shell Linux

#!/bin/bash

#MySQL设置
MysqlHost=localhost
MysqlUser=root
MysqlPwd=password

#备份文件设置
BackupPath=/backup/db
FileName=$MysqlHost-$(date +%Y%m%d-%H%M%S)
FileFullPath=$BackupPath/$FileName

#ftp设置
FtpHost=10.206.4.121
FtpUser=iptv
FtpPwd=StarIptv
FtpPath=/ftp/backup/mysql

mkdir -p $BackupPath

#备份mysql并导出到文件
mysqldump -u$MysqlUser -p$MysqlPwd -h$MysqlHost --opt --all-databases -f > $FileFullPath.sql

#压缩备份文件
tar -Pzcvf $FileFullPath.tar.gz $FileFullPath.sql

#上传到ftp
ftp -n $FtpHost <<AUTOEOF
quote USER $FtpUser
quote PASS $FtpPwd
cd $FtpPath
binary
put $FileFullPath.tar.gz $FtpPath/$FileName.tar.gz
quit
AUTOEOF

#删除SQL文件
rm -rf $FileFullPath.sql

#删除30天之前的文件
find $BackupPath -type f -mtime +30 -exec rm -f {} \;

«« First 19 20 21 22 23 24