<?xml version="1.0" encoding="UTF-8" ?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
    <title>Posteet: backup,mysql</title> 
    <link>http://www.posteet.com/</link> 
    <description>Recent posteets posted to Posteet</description>
    <ttl>60</ttl>

    
    <item>
        <title>Backup (logique) et restauration MySQL</title>
        <link>http://www.posteet.com/view/436</link>
        <description>
        <![CDATA[<pre>Backup :
mysqldump -u root -pSuperMotDePasse --all-databases &gt; backup.sql

Restauration :
mysql -u root -pSuperMotDePasse &lt; backup.sql</pre> <a href="http://www.posteet.com/tags/backup">[backup]</a>  <a href="http://www.posteet.com/tags/mysql">[mysql]</a>  <a href="http://www.posteet.com/tags/restauration">[restauration]</a>  <a href="http://www.posteet.com/tags/sauvegarde">[sauvegarde]</a> ]]>        </description>
        <dc:creator>skymaxs</dc:creator>
        <pubDate>Thu, 15 Nov 2007 09:31:25 +0000</pubDate>

            <category>backup</category>
            <category>mysql</category>
            <category>restauration</category>
            <category>sauvegarde</category>
    
    </item>

  
    <item>
        <title>Backup MySQL</title>
        <link>http://www.posteet.com/view/317</link>
        <description>
        <![CDATA[<pre>#
#Fichier de configuration (backup-mysql.conf)
#

###########################################################
# Fichier de configuration pour le script backup-mysql.sh #
###########################################################


#Serveur à backuper
SERVER='localhost'

#Utilisateur MySQL
DBUSER='root'

#Mot de passe MySQL
DBPASS='viOvyornye'

#On specifie les bases a backuper (&quot;all&quot; pour tout backuper)
DB='all'

#Date format
DATE_FORMAT='+%d-%m-%Y'

#Repertoire de backup
BACKUP_DIR='/var/backup/mysql/'

#Repertoire du jour
TODAY_DIR=$(date $DATE_FORMAT)

#Nomre de backups a conserver (en jours)
HISTORY='7'

#Type de compression (bzip2/gzip)
COMP_TYPE='bzip2'

#Creer un repertoire pour chaque base de donnees (yes/no)
SEP_DB='yes'

#Separer les tables en differents fichiers (yes/no)
SEP_TABLE='yes'

#Options pour le dump
#Utiliser 'man mysqldump' ou aller sur la configuration pour plus de details
OPTS='--default-character-set=latin1 --skip-extended-insert'

#Fichier de logs
LOG_FILE='/tmp/backup.log'

#Adresse mail pour les logs d'execution du script
MAIL_ADDR='admin@domain.tld'

#
#Script de backup MySQL 
#

#!/bin/bash 

CONF_PATH='/etc'
CONF_FILE='backup-mysql.conf'

if [ ! -d &quot;$CONF_PATH&quot; ] || [ ! -f &quot;$CONF_PATH/$CONF_FILE&quot; ]; then
        echo &quot;File : $CONF_PATH/$CONF_FILE missing !&quot;
        exit 1;
else
        . &quot;$CONF_PATH/$CONF_FILE&quot;
fi

send-mail () {
        cat &quot;$LOG_FILE&quot; | mail -s &quot;Rapport d'execution du script $(basename $0) sur $HOSTNAME&quot; $MAIL_ADDR
        rm &quot;$LOG_FILE&quot;
}

check_dirs () {
        #On verifie si le repertoire de backup existe
        if [ ! -d &quot;$BACKUP_DIR&quot; ]; then
                echo &quot;$BACKUP_DIR n'existe pas.&quot; &gt;&gt; &quot;$LOG_FILE&quot;
                send-mail
                exit 1;
        fi
        #On verifie si le repertoire du jour existe
        if [ ! -d &quot;$BACKUP_DIR/$TODAY_DIR&quot; ]; then
                mkdir &quot;$BACKUP_DIR/$TODAY_DIR&quot;
        fi
        #On supprime le backup le plus ancien
        TO_DELETE=$(date --date &quot;$HISTORY days ago&quot; $DATE_FORMAT)
        if [ -d &quot;$BACKUP_DIR/$TO_DELETE&quot; ]; then
                rm -r &quot;$BACKUP_DIR/$TO_DELETE&quot;
        fi
}

backup () {
        if [ -z &quot;$1&quot; ]; then
                echo 'Liste des bases non transmise' &gt;&gt; $LOG_FILE
                send-mail
                exit 1;
        else
                if [ &quot;$SEP_DB&quot; == 'yes' ]; then
                        for DB_TO_BACKUP in $1; do
                                #On cree le repertoire pour separer les bases
                                mkdir &quot;$BACKUP_DIR/$TODAY_DIR/$DB_TO_BACKUP&quot;
                                if [ &quot;$SEP_TABLE&quot; == 'yes' ]; then
                                        for TABLE_TO_BACKUP in $(mysql -h$SERVER -u$DBUSER -p$DBPASS --skip-column-names $DB_TO_BACKUP -e &quot;show tables&quot;); do
                                                mysqldump -h&quot;$SERVER&quot; -u&quot;$DBUSER&quot; -p&quot;$DBPASS&quot; $OPTS &quot;$DB_TO_BACKUP&quot; &quot;$TABLE_TO_BACKUP&quot; | &quot;$COMP_TYPE&quot; &gt; &quot;$BACKUP_DIR/$TODAY_DIR/$DB_TO_BACKUP/$DB_TO_BACKUP-$TABLE_TO_BACKUP-$TODAY_DIR.$FILE_EXT&quot;
                                        done
                                else 
                                        mysqldump -h&quot;$SERVER&quot; -u&quot;$DBUSER&quot; -p&quot;$DBPASS&quot; $OPTS &quot;$DB_TO_BACKUP&quot; &quot;$TABLE_TO_BACKUP&quot; | &quot;$COMP_TYPE&quot; &gt; &quot;$BACKUP_DIR/$TODAY_DIR/$DB_TO_BACKUP/$DB_TO_BACKUP-$TODAY_DIR.$FILE_EXT&quot;
                                fi
                        done
                                
                else
                        if [ &quot;$SEP_TABLE&quot; == 'yes' ]; then
                                for DB_TO_BACKUP in $1; do
                                        for TABLE_TO_BACKUP in $(mysql -h$SERVER -u$DBUSER -p$DBPASS --skip-column-names $DB_TO_BACKUP -e &quot;show tables&quot;); do
                                        mysqldump -h&quot;$SERVER&quot; -u&quot;$DBUSER&quot; -p&quot;$DBPASS&quot; $OPTS &quot;$DB_TO_BACKUP&quot; &quot;$TABLE_TO_BACKUP&quot; | &quot;$COMP_TYPE&quot; &gt; &quot;$BACKUP_DIR/$TODAY_DIR/$DB_TO_BACKUP-$TABLE_TO_BACKUP-$TODAY_DIR.$FILE_EXT&quot;
                                        done
                                done
                        else
                                mysqldump -h&quot;$SERVER&quot; -u&quot;$DBUSER&quot; -p&quot;$DBPASS&quot; $OPTS --all-databases | &quot;$COMP_TYPE&quot; &gt; &quot;$BACKUP_DIR/$TODAY_DIR/$TODAY_DIR.$FILE_EXT&quot;
                        fi
                fi
        fi
}

# On cree le fichier de log
touch &quot;$LOG_FILE&quot;
# on verifie que les bases a backuper sont bien renseignees
if [ -z &quot;$DB&quot; ]; then
        echo 'variable $DB vide.' &gt;&gt; &quot;$LOG_FILE&quot;
        send-mail
        exit 1;
elif [ &quot;$DB&quot; == &quot;all&quot; ]; then
        DB_LIST=$(mysql -h$SERVER -u$DBUSER -p$DBPASS --skip-column-names -e &quot;show databases&quot; | xargs)
else
        DB_LIST=&quot;$DB&quot;
fi      
# On verifie que la compression est correcte
if [ &quot;$COMP_TYPE&quot; == 'bzip2' ]; then
        FILE_EXT='sql.bz2'
elif [ &quot;$COMP_TYPE&quot; == 'gzip' ]; then
        FILE_EXT='sql.gz'
else
        echo '$COMP_TYPE non spécifié.' &gt;&gt; &quot;$LOG_FILE&quot;
        send-mail
        exit 1;
fi

check_dirs
backup &quot;$DB_LIST&quot;

#On verifie si le fichier de logs existe et qu'il est vide
if [ -f &quot;$LOG_FILE&quot; ] &amp;&amp; [ &quot;$(cat $LOG_FILE | wc -l)&quot; -eq 0 ]; then
        #Si il est vide on efface
        rm &quot;$LOG_FILE&quot;
else
        #Sinon on envoie le rapport
        send-mail
fi</pre> <a href="http://www.posteet.com/tags/backup">[backup]</a>  <a href="http://www.posteet.com/tags/mysql">[mysql]</a> ]]>        </description>
        <dc:creator>dave</dc:creator>
        <pubDate>Tue, 06 Nov 2007 13:23:45 +0000</pubDate>

            <category>backup</category>
            <category>mysql</category>
    
    </item>

  
    <item>
        <title>mysql_backup.sh</title>
        <link>http://www.posteet.com/view/125</link>
        <description>
        <![CDATA[<pre>#!/bin/bash

prefixe=backup
suffixe=$(date +%Y%m%d)
filename=$prefixe$suffixe.sql
host=host
database=database
user=user
characterSet=UTF8

mysqldump --skip-comments \
--complete-insert \
--default-character-set=$characterSet \
--no-create-info \
--skip-add-locks \
--skip-opt \
--host $host \
--user $user \
-p $database &gt; $filename

sed -i &quot;1iuse $database;\nSET CHARACTER SET '$characterSet';&quot; $filename
exit 0</pre> <a href="http://www.posteet.com/tags/backup">[backup]</a>  <a href="http://www.posteet.com/tags/bash">[bash]</a>  <a href="http://www.posteet.com/tags/data">[data]</a>  <a href="http://www.posteet.com/tags/données">[données]</a>  <a href="http://www.posteet.com/tags/mysql">[mysql]</a>  <a href="http://www.posteet.com/tags/sauvegarde">[sauvegarde]</a> ]]>        </description>
        <dc:creator>xavier</dc:creator>
        <pubDate>Sat, 03 Nov 2007 13:44:28 +0000</pubDate>

            <category>backup</category>
            <category>bash</category>
            <category>data</category>
            <category>données</category>
            <category>mysql</category>
            <category>sauvegarde</category>
    
    </item>


</channel>
</rss>
