mysql备份并zip加密压缩

currentpath=/backup/sql
backpath="test"
zipbackuptime=30
zippasswd="password"
zippath=/work/zip

function makedir(){
    echo $(date "+%Y-%m-%d %H:%M:%S")
    if [ -d $currentpath/$(date +%y%m%d) ]; then
        echo "$(date +%y%m%d) is exsit"
    else
        mkdir $currentpath/$(date +%y%m%d)
        echo "$(date +%y%m%d) is building"
    fi
}

function backupsql(){
    bakckpath=$currentpath/$(date +%y%m%d)
    for i in $backpath;
    do
          backuptime=$(date +%y%m%d%H%M)
      mysqldump -uroot -phh931130 $i>$bakckpath/$backuptime$i.sql
      timenum=${backuptime:8}
        if [ $timenum -eq $zipbackuptime ]; then
          makedirZip
          cd $bakckpath
          zip -rP $zippasswd $backuptime$i.zip $backuptime$i.sql
          mv $backuptime$i.zip $zippath/$(date +%y%m%d)
        fi
    done  

function makedirZip(){
    if [ -d $zippath/$(date +%y%m%d) ]; then
        echo "zip $(date +%y%m%d) is exsit"
    else
        mkdir $zippath/$(date +%y%m%d)
        touch $zippath/$(date +%y%m%d)/index.html
        echo "Zip $(date +%y%m%d) is building"
    fi
}

makedir
backupsql

你可能感兴趣的:(服务器配置,mysql)