• 数据库备份脚本shell


    #!/bin/bash  
    #----------------------------
    #Target machine configuration
    #----------------------------
    #DBUser->Database user name
    #DBPasswd->Database password ,not null
    #DBName->Database name
    #SERVER->IP address
    #----------------------------
    DBUser=****
    DBPasswd=****
    DBName=*****
    SERVER=****
    
    
    #--------------------------------
    #The local machine configuration
    #--------------------------------
    #LocalDBUser->Database user name
    #LocalDBPasswd->Database password,not null
    #LocalDBName->Database name
    #BackupPath->Backup path,end with '/'
    #LogFile->Log file
    #num->backup numbers
    #--------------------------------
    LocalDBUser=**
    LocalDBPasswd=***
    LocalDBName=****
    BackupPath=****
    LogFile=****
    #num=2 -----> Has not been completed
    #-------------------------------
    
    #-------------------------------
    #Other configuration
    #-------------------------------
    #IgnoreTables->ignore tables,like this:
    #IgnoreTables= '--ignore-table=DBName.TableName1 --ignore-table=DBName.TableName2 .....'
    #NeedTables->need backup tables,if you want to backup all tables,please let it empty
    #like this: NeedTables='table1 table2 table3'
    #-------------------------------
    IgnoreTables='****‘ 
    NeedTables=
    #begin
    
    
    NewFile="$BackupPath"dbBackup$(date +%y%m%d).sql  
    OldFile="$BackupPath"dbBackup$(date +%y%m%d --date='5 days ago').sql 
    
    echo "-------------------------------------------" >> $LogFile  
    echo $(date +"%y-%m-%d %H:%M:%S") >> $LogFile  
    echo $(date +%y%m%d --date='5 days ago') >>$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 
       echo "Begin ro recover the data...."  
       mysql -u$LocalDBUser -p$LocalDBPasswd --default-character-set='utf8' $LocalDBName <$NewFile
       echo "Data has been restored!" >>$LogFile
    else  
    	mysqldump -h$SERVER -u$DBUser -p$DBPasswd --default-character-set='utf8' --quick --single-transaction  $DBName  $NeedTables    $IgnoreTables  >$NewFile
        echo "[$NewFile]Backup Success!" >> $LogFile  
    fi
    echo "-------------------------------------------"
    echo
    
    
    

  • 相关阅读:
    3139:[HNOI2013]比赛
    3143: [Hnoi2013]游走
    目前游戏行业内部主要几款游戏引擎的技术对比
    6.使用AngularJS模板来创建视图
    css选择器(E[att^=”val”]序号选择器)
    5.把作用域实现为数据模型
    4.了解AngularJS模块和依赖注入
    3.创建基本的AngularJS应用
    2.AngularJS MVC
    1.AngularJS初探
  • 原文地址:https://www.cnblogs.com/chenjianhong/p/4145053.html
Copyright © 2020-2023  润新知