文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Linux下Mysql自动备份并上传到远程FTP服务器

Linux下Mysql自动备份并上传到远程FTP服务器

时间:2007-07-23  来源:wxijin

http://loulan.lapp.cn/?action=show&id=107

文件: dcback[1].tar.gz
大小: 0KB
下载: 下载

如果大家还有什么更好的需求和建议请留言。

#!/bin/bash
#Mysql autobackup shell
#write by loulancn#163.com

#-------------------数据库相关的用户名、密码、需要备份的数据库名、备份目录等
dbuser=root
dbpasswd=
dbserver=localhost
dbname=dcradius
dbopt=--opt
backupdir=/dcbackup/

#-------------------是否开启FTP远程备份,0为否,1为是。
copytoftp=0
ftpserver=
ftpuser=
ftppasswd=

#-------------------以下参数

fileprefix=dcradius
dumpfilename=$backupdir`date +%F`.sql
newfile=$fileprefix-`date +%F`.tar.gz

keepdays=10
#-------------------以下为备份时的日志
logfile=/var/log/mysqlbackup.log
logtmp=/var/log/mybackup.tmp


#===============================================

if [ ! -d $backupdir ]
then
        echo "$backupdir is not exist, then make ..." >> $logfile
        mkdir -p $backupdir
fi

echo "start====================================>">>$logfile
echo "Beginning backup `date '+%F %T'`" >>$logfile

echo "Delete $keepdays days ago files ..." >>$logfile

find $backupdir -name $fileprefix* -mtime +$keepdays -fls $logtmp -exec rm {} \;
echo "Deleted Backup file is :">>$logfile
cat $logtmp >>$logfile
echo "Delete old file Success!" >>$logfile

if [ -f $backupdir$newfile ]
then
echo "$newfile backup exist, backup stop ..." >>$logfile
else
        if [ -z $dbpasswd ]
        then
        mysqldump -u$dbuser -h$dbserver $dbopt $dbname >$dumpfilename
        else
        mysqldump -u$dbuser -p$dbpasswd -h$dbserver $dbopt $dbname >$dumpfilename
        fi
        tar czvf $backupdir$newfile $dumpfilename >>$logfile 2>&1
        echo "$backupdir$newfile Backup Success!" >>$logfile
        rm -fr $dumpfilename


if [ $copytoftp = 1 ];  then
        if [ -z $ftpserver ];then
        echo "Ftp Server not set,Copy to Ftp Failed ..." >>$logfile
        exit 1
        elif [ -z $ftpuser ];then
        echo "Ftp user not set, Copy to Ftp Failed ..." >>$logfile
        exit 2
        elif [ -z $ftppasswd ]; then
        echo "Ftp password not set, Copy to Ftp Failed ..." >>$logfile
        exit 3
        else
        echo "Start copy to Ftp server ...." >> $logfile

ftp -n<<eof
open $ftpserver
user $ftpuser $ftppasswd
lcd $backupdir
hash
prompt
put $newfile
close
bye
eof

fi
fi
echo "End=======================================">>$logfile

fi

相关阅读 更多 +
排行榜 更多 +
找茬脑洞的世界安卓版

找茬脑洞的世界安卓版

休闲益智 下载
滑板英雄跑酷2手游

滑板英雄跑酷2手游

休闲益智 下载
披萨对对看下载

披萨对对看下载

休闲益智 下载