Как сделать резервную копию MySql всех баз данных

Хочу поделится с вами небольшим скриптом для создания резервных копий всех баз данных MySql.

#!/bin/bash

MyUSER="dbuser"
MyPASS="dbpass"
MyHOST="localhost"

MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"

#MYSQL="/usr/local/bin/mysql"
#MYSQLDUMP="/usr/local/bin/mysqldump"

CHOWN="$(which chown)"
CHMOD="$(which chmod)"
GZIP="$(which gzip)"

DEST="./db_backup"

MBD="$DEST"
HOST="$(hostname)"
NOW="$(date +"%Y%m%d")"

FILE=""
DBS=""

# DO NOT BACKUP these databases, delemiter SPACE
IGN="information_schema"

# Get all database list first
DBS="$($MYSQL -u $MyUSER -h $MyHOST -p$MyPASS -Bse 'show databases')"

for db in $DBS
do

    skipdb=-1
    if [ "$IGN" != "" ]; then
        for i in $IGN
        do
            [ "$db" == "$i" ] && skipdb=1 || :
        done
    fi

    if [ "$skipdb" == "-1" ] ; then
        MBD="$DEST/$db"    	
        [ ! -d $MBD ] && mkdir -p $MBD || :
        FILE="$MBD/$NOW.sql.gz"
            $MYSQLDUMP --opt -u $MyUSER -h $MyHOST -p$MyPASS $db | $GZIP -9 > $FILE
        FNUM="$(find $MBD/* | wc -l)"
        if [ $FNUM -ge 0 ] ; then
            find $MBD/* -type f -mtime 20 -exec rm -rf {} \;
        fi
    fi

done

26 комментариев к “Как сделать резервную копию MySql всех баз данных

  1. When I originally commented I clicked the -Inform me when new remarks are included- checkbox as well as currently each time a remark is included I get four emails with the exact same remark. Is there any way you can remove me from that service? Thanks!

  2. Aw, this was a truly nice blog post. In suggestion I wish to put in composing similar to this furthermore? requiring time and also actual initiative to make a very good write-up? however what can I state? I procrastinate alot and never appear to obtain something done.

  3. The next time I read a blog site, I hope that it doesn’t dissatisfy me as much as this one. I suggest, I understand it was my option to read, however I actually thought youd have something interesting to claim. All I listen to is a lot of whimpering regarding something that you might fix if you werent as well active trying to find attention.

  4. Can I just say what a relief to discover someone that really understands what theyre talking about on the internet. You most definitely recognize just how to bring a problem to light as well as make it essential. Even more individuals require to read this as well as comprehend this side of the tale. I angle think youre not more prominent due to the fact that you most definitely have the gift.

  5. An excellent share, I simply offered this onto a coworker who was doing a little evaluation on this. And he actually acquired me breakfast since I located it for him. smile. So let me reword that: Thnx for the reward! But yeah Thnkx for investing the moment to review this, I really feel highly about it and also love reading more on this topic. Preferably, as you end up being expertise, would you mind updating your blog site with more details? It is very handy for me. Big thumb up for this article!

  6. Does your site have a contact page? I’m having trouble locating it but, I’d like to shoot you an e-mail. I’ve got some suggestions for your blog you might be interested in hearing. Either way, great website and I look forward to seeing it develop over time.

  7. A formidable share, I just given this onto a colleague who was doing a little bit analysis on this. And he in actual fact bought me breakfast because I found it for him.. smile. So let me reword that: Thnx for the treat! However yeah Thnkx for spending the time to discuss this, I feel strongly about it and love studying extra on this topic. If attainable, as you grow to be expertise, would you thoughts updating your blog with extra particulars? It’s extremely helpful for me. Large thumb up for this blog publish!

  8. An impressive share, I simply given this onto a colleague that was doing a little evaluation on this. And also he as a matter of fact got me breakfast since I located it for him. smile. So let me reword that: Thnx for the reward! But yeah Thnkx for spending the moment to review this, I feel highly concerning it and like learning more on this subject. When possible, as you become expertise, would certainly you mind updating your blog site with more details? It is highly useful for me. Huge thumb up for this article!

Оставить ответ к when is generic viagra Отменить ответ

Ваш адрес email не будет опубликован. Обязательные поля помечены *