你是否在寻找一个mysql备份脚本? |
你是否在寻找一个mysql备份脚本? Code
#!/bin/sh # mysql data backup script # by scud http://www.jscud.com # 2005-10-30 # # use mysqldump --help,get more detail. # BakDir=/backup/mysql LogFile=/backup/mysql/mysqlbak.log DATE=`date +%Y%m%d` echo " " >> $LogFile echo " " >> $LogFile echo "-------------------------------------------" >> $LogFile echo $(date +"%y-%m-%d %H:%M:%S") >> $LogFile echo "--------------------------" >> $LogFile cd $BakDir DumpFile=$DATE.sql GZDumpFile=$DATE.sql.tgz mysqldump --quick --all-databases --flush-logs --delete-master-logs --lock-all-tables > $DumpFile echo "Dump Done" >> $LogFile tar czvf $GZDumpFile $DumpFile >> $LogFile 2>&1 echo "[$GZDumpFile]Backup Success!" >> $LogFile rm -f $DumpFile #delete previous daily backup files:采用增量备份的文件,如果完整备份后,则删除增量备份的文件. cd $BakDir/daily rm -f * cd $BakDir echo "Backup Done!" echo "please Check $BakDir Directory!" echo "copy it to your local disk or ftp to somewhere !!!" ls -al $BakDir
Code
#!/bin/sh # # mysql binlog backup script # /usr/bin/mysqladmin flush-logs DATADIR=/var/lib/mysql BAKDIR=/backup/mysql/daily ###如果你做了特殊设置,请修改此处或者修改应用此变量的行:缺省取机器名,mysql缺省也是取机器名 HOSTNAME=`uname -n` cd $DATADIR FILELIST=`cat $HOSTNAME-bin.index` ##计算行数,也就是文件数 COUNTER=0 for file in $FILELIST do COUNTER=`expr $COUNTER + 1 ` done NextNum=0 for file in $FILELIST do base=`basename $file` NextNum=`expr $NextNum + 1` if [ $NextNum -eq $COUNTER ] then echo "skip lastest" else dest=$BAKDIR/$base if(test -e $dest) then echo "skip exist $base" else echo "copying $base" cp $base $BAKDIR fi fi done echo "backup mysql binlog ok"
|