Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2320753
  • 博文数量: 535
  • 博客积分: 8689
  • 博客等级: 中将
  • 技术积分: 7066
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-26 10:00
文章分类

全部博文(535)

文章存档

2024年(4)

2023年(4)

2022年(16)

2014年(90)

2013年(76)

2012年(125)

2011年(184)

2010年(37)

分类: LINUX

2011-07-01 15:59:25






这个是更新后的,也就是同时上传到多台服务器上.

cat  /var/script/tab_bak2.sh   
#!/bin/bash

backupDir=/backup/mysql

ftpUser=femar4t43a
ftpPWD='d:8G2l'

file=`ls -t /backup/mysql|grep '[0-9]\{11,12\}' |sed -n '20,$p'`
for i in $file;do
rm -rf  /backup/mysql/$i
done

DATE=`date +%Y%m%d%H%M`
MYSQL='mysql -uroot -p'1Iw8wdg''
IP='8.8.8.8'

        cd /backup/mysql &&  mkdir -p $DATE && cd $DATE

        for table in `$MYSQL -e "use femart; show tables" |sed '1d'` ; do

            /usr/local/mysql/bin/mysqldump  -uroot -p'1Ig' femart $table |gzip > femart.$table.sql.gz

        echo "`date +%Y%m%d%H%M`  mysqlback stop,start compress!" >>"$backupDir"/`date +%Y%m%d`.log

        date=`date +%Y%m%d-%H%M`
        
    done

            tar cvf mysql-$IP-$DATE.tar  *.gz

        echo "`date +%Y%m%d%H%M`  mysqlback end!" >>"$backupDir"/`date +%Y%m%d`.log

rm -rf  *.sql.gz

date0=`date +%Y%m%d`
cd $backupDir/$DATE

/usr/bin/ftp -n<
open 192.168.0.124 60017
user $ftpUser  $ftpPWD
bin
#passive
mkdir $date0
cd $date0
put mysql-$IP-$DATE.tar
bye
quit
EOF


ftpUser2=femar
ftpPWD2='d@8G2l'

date0=`date +%Y%m%d`
cd $backupDir/$DATE
/usr/bin/ftp -n<
open 192.168.0.115 21
user $ftpUser2 $ftpPWD2
bin
#passive
mkdir $date0
cd $date0
put mysql-$IP-$DATE.tar
bye
EOF




 


cat tab_bak.sh
#!/bin/bash

backupDir=/backup/mysql

ftpUser=femart_db_bak
ftpPWD='ftp_passwd'

file=`ls -t /backup/mysql|grep '[0-9]\{11,12\}' |sed -n '20,$p'`
for i in $file;do
rm -rf  /backup/mysql/$i
done

DATE=`date +%Y%m%d%H%M`
MYSQL='mysql -uroot -p'mysql_password''
IP='194.231.158.14'

        cd /backup/mysql &&  mkdir -p $DATE && cd $DATE

        for table in `$MYSQL -e "use femart; show tables" |sed '1d'` ; do

            /usr/local/mysql/bin/mysqldump  -uroot -p'mysql_password' femart $table |gzip > femart.$table.sql.gz

        echo "`date +%Y%m%d%H%M`  mysqlback stop,start compress!" >>"$backupDir"/`date +%Y%m%d`.log

        date=`date +%Y%m%d-%H%M`
        
    done

            tar cvf mysql-$IP-$DATE.tar  *.gz

        echo "`date +%Y%m%d%H%M`  mysqlback end!" >>"$backupDir"/`date +%Y%m%d`.log

rm -rf  *.sql.gz

date0=`date +%Y%m%d`
cd $backupDir/$DATE

/usr/bin/ftp -n<
open 192.168.0.124 60017
user $ftpUser  $ftpPWD
bin
#passive
mkdir $date0
cd $date0
put mysql-$IP-$DATE.tar
bye
EOF

date0=`date +%Y%m%d`
cd $backupDir/$DATE
/usr/bin/ftp -n<
open 209.86.18.210 60017
user $ftpUser $ftpPWD
bin
#passive
mkdir $date0
cd $date0
put mysql-$IP-$date.tar
bye
EOF



















cat tab_bak.sh_bak 
#!/bin/sh
IP=master-table-20.221.158.38
scriptsDir=`pwd`
dataDir=/data/mysql
tmpBackupDir=/tmp/mysqlbackup
backupDir=/backup/mysql

ftpUser=femart_db_bak
ftpPWD='d@sd2D$fsd:8G2l'
mysqlPWD='mysql_password'

if [[ -e $tmpBackupDir ]]; then
rm -rf $tmpBackupDir/*
else
mkdir $tmpBackupDir
fi

file=`ls -t /backup/mysql|grep master-table |sed -n '20,$p'`
for i in $file;do
rm -rf  /backup/mysql/$i
done
if [[ ! -e $backupDir ]];then
mkdir -p $backupDir
fi
echo "`date +%Y%m%d%H%M`  mysqlback start" >>"$backupDir"/`date +%Y%m%d`.log
dbname=`find "/data/mysql" -type d|sed -e "s#/data/mysql/##"|sed -e "s#/data/mysql##"|sed -e "s/^test$//"|grep -v "mysql"|grep -v femart_20111115 |grep -v proftpd |grep  -v  febay_sphinx |grep -v febay_guidang  |grep -v  febay |grep -v beifen_femart  |grep -v beifen_febay |grep -v beifen2_femart  |grep -v 2010|grep -v 2011|sed -e "/^$/d"`

#for databases in $dbname; do
#if [[ $databases == "" ]]; then
#continue
#else
#errfile="$backupDir"/`date +%Y%m%d`.err
#echo "dumping $databases">>$errfile
#/usr/local/mysql/bin/mysqldump -uroot -p$mysqlPWD -B --single-transaction  $databases   >"$tmpBackupDir"/"$databases".sql 2>>$errfile
#fi
#done

for table in  sdb_orders sdb_order_items sdb_order_log sdb_operators sdb_members ;  do
if [[ $table == "" ]] ; then 
continue 
else 
errfile="$backupDir"/`date +%Y%m%d`.err
echo "dumping $databases">>$errfile
/usr/local/mysql/bin/mysqldump -uroot -p$mysqlPWD  femart $table   >"$tmpBackupDir"/"femart_$table".sql 2>>$errfile
fi
done

echo "`date +%Y%m%d%H%M`  mysqlback stop,start compress!" >>"$backupDir"/`date +%Y%m%d`.log
date=`date +%Y%m%d-%H%M`
cd $tmpBackupDir
tar czf $backupDir/mysql-$IP-$date.tar.gz ./
echo "`date +%Y%m%d%H%M`  mysqlback end!" >>"$backupDir"/`date +%Y%m%d`.log
#End

date0=`date +%Y%m%d`
cd $backupDir
/usr/bin/ftp -n<
open 192.168.0.124 60017
user $ftpUser  $ftpPWD
bin
#passive
mkdir $date0
cd $date0
put  mysql-$IP-$date.tar.gz
bye
EOF















[root@china_blog sql]# cat  /root/yuanbloger_bak/back4_yuanbloger.sh
#some variable

BaseDir="/root/yuanbloger_bak/sql"
BaseName="yuanbloger_"
LatestSql=$BaseDir"/yuanbloger_latest.sql"
Now=$(date +%Y%m%d%H%M%S)
NowD=$(date +%Y%m%d)
NowH=$(date +%Y%m%d%H0000)
DailyDir=$BaseName$NowD
HourlySql=$BaseDir"/"$BaseName"sql_"$NowH".sql"
LoggerFile=$BaseDir"/sj_logger.log"

#dump sql file
echo $Now" started!">>$LoggerFile
mysqldump --opt wwwyuanblogercom -h localhost -uwwwyuanblogercom -pwwwyuanblogercom --add-drop-table --lock-tables=0 >$HourlySql


























8># cat  /data/backup/mysql_backup
#!/bin/bash
DBUser=backup
DBPasswd=7dgfdssf
DBName=`echo "select SCHEMA_NAME from information_schema.SCHEMATA where schema_name not in ('information_schema','mysql','test');" | mysql -u$DBUser -p$DBPasswd -S /tmp/mysql.sock`
BackupPath=/data/backup/
LogFile=/data/backup/log/mysql_backup.log


pushd $BackupPath >> $LogFile
NewFile=$(date +%Y%m%d).tgz
DumpFile2=*.sql
OldFile=$(date +%Y%m%d --date='7 days ago').tgz
echo $OldFile
echo "-------------------------------------------" >> $LogFile
echo $(date +"%Y-%m-%d %H:%M:%S") >> $LogFile
echo "--------------------------" >> $LogFile
#Delete Old File
if [ -f $OldFile ]
then
   rm -f $OldFile >> $LogFile 2>&1
   echo "[$OldFile]Delete Old File Success!" >> $LogFile
else
   echo "[$OldFile]No Old Backup File!" >> $LogFile
fi
if [ -f $NewFile ]
then
   echo "[$NewFile]The Backup File is exists,Can't Backup!" >> $LogFile
else
   for item in $DBName
   do
       DumpFile=$item".sql"
       if [ -z $DBPasswd ]
       then
           mysqldump -S /tmp/mysql.sock -u$DBUser -p$DBPasswd -B --single-transaction --default-character-set=utf8 $item > $DumpFile
       else
           mysqldump -S /tmp/mysql.sock -u$DBUser -p$DBPasswd -B --single-transaction --default-character-set=utf8 $item > $DumpFile
       fi
   done
   /bin/tar czvf $NewFile $DumpFile2 >> $LogFile 2>&1
   echo "[$NewFile]Backup Success!" >> $LogFile
   /bin/rm -f *.sql
fi
echo "-------------------------------------------" >> $LogFile
popd 







cat  dbbak.sh

#!/bin/sh

IP=monitor-220.231.158.124
scriptsDir=`pwd`
dataDir=/data/mysql
tmpBackupDir=/tmp/mysqlbackup
backupDir=/backup/mysql

#ftpUser=silidbbak
#ftpPWD='falk*k2lLjdk752KDSLD'
mysqlPWD='123456'

if [[ -e $tmpBackupDir ]]; then
rm -rf $tmpBackupDir/*
else
mkdir $tmpBackupDir
fi

file=`ls -t /backup/mysql|grep tar|sed -n '5,$p'`
for i in $file;do
rm -rf  /backup/mysql/$i
done
if [[ ! -e $backupDir ]];then
mkdir -p $backupDir
fi
echo "`date +%Y%m%d%H%M`  mysqlback start" >>"$backupDir"/`date +%Y%m%d`.log
dbname=`find "/data/mysql" -type d|sed -e "s#/data/mysql/##"|sed -e "s#/data/mysql##"|sed -e "s/^test$//"|grep -v 2011|grep -v 2012|sed -e "/^$/d"`

for databases in $dbname; do
if [[ $databases == "" ]]; then
continue
else
errfile="$backupDir"/`date +%Y%m%d`.err
echo "dumping $databases">>$errfile
/usr/local/mysql/bin/mysqldump -uroot -p$mysqlPWD $databases >"$tmpBackupDir"/"$databases".sql 2>>$errfile
fi
done

echo "`date +%Y%m%d%H%M`  mysqlback stop,start compress!" >>"$backupDir"/`date +%Y%m%d`.log
date=`date +%Y%m%d-%H%M`
cd $tmpBackupDir
tar czf $backupDir/mysql-$IP-$date.tar.gz ./
echo "`date +%Y%m%d%H%M`  mysqlback end!" >>"$backupDir"/`date +%Y%m%d`.log
#End

#date0=`date +%Y%m%d`
#cd $backupDir
#/usr/bin/ftp -n<
#open 10.20.137.138 21
#user $ftpUser  $ftpPWD
#bin
#passive
#mkdir $date0
#cd $date0
#put  mysql-$IP-$date.tar.gz
#bye
#EOF





阅读(1198) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~