zoukankan      html  css  js  c++  java
  • backupMysql.sh

    #!/bin/sh
    #!/bin/bash
    function backup()
    {
            for i in $*
            do
               mysqldump -h$hostip -P$port -u$username -p$password -E -R $i >> $filelocation/$edate/DB_$i'_'$edate.sql
            done
    #    echo  $filelocation"records listed below:"
    #    echo `ls $filelocation`
        for x in `ls $filelocation`
        do
        
        echo "for" $x 
            if [ -d "$filelocation/$x" ];then
                #echo $(date +%s -d $edate)
                #echo $(date +%s -d $x) 
                time1=$(($(date +%s -d $edate) - $(date +%s -d $x)));
                time1=$(($time1/60/24/60))
                echo "the dis is "$time1" days"
                if [ $time1 -gt $dis ];then
                    #echo $dis '<' $time1
                    #echo 'delete dir '$x
                    `rm -rf $filelocation/$x`
    #            else
                    #echo $dis '>' $time1
                    #echo 'save dir' $x    
                fi
            fi
        done
    
    }
    
    
    
    
    username=root
    password="password"
    hostip=127.0.0.1
    port=3306
    filelocation=/home/jet/backup/mysql
    edate=`date +%Y-%m-%d`
    dis=7
    if [ ! -d $filelocation  ]; then
        `mkdir "$filelocation"`
    fi
    if [ ! -d "$filelocation/$edate" ];then
        `mkdir "$filelocation/$edate"`
    fi
    backup datebase1 database2 database3
  • 相关阅读:
    Bubble Sort (5775)
    Dertouzos (5750)
    codeforces 360 E
    codeforces 360 D
    codeforces 360 C
    Mike and Cellphone
    训练2——B
    训练1——A
    符号三角形
    Sudoku Killer
  • 原文地址:https://www.cnblogs.com/irockcode/p/6800869.html
Copyright © 2011-2022 走看看