Confixx: Difference between revisions

From Wiki
No edit summary
No edit summary
Line 10: Line 10:
<blockquote>
<blockquote>
<pre>
<pre>
#!/bin/bash
#
# confixx backup
#
# Variables
HOMEDIR="$(pwd)"
FILESDIR="$HOMEDIR/files"
LOGFILE="$FILESDIR/backup.log"
DATESTAMP="$(date "+%F %T")"
MySQL_USER="..."
MySQL_PASS="..."
MySQL_HOST="localhost"
MySQL_ignoredb=""
#MySQL_ignoredb="information_schema"
# Append log file
touch $LOGFILE
echo "$DATESTAMP Starting Backup" >> $LOGFILE
# remove old backup
mkdir $FILESDIR/backup
cd $FILESDIR/backup
rm *
mkdir $FILESDIR/backup_tmp
cd $FILESDIR/backup_tmp
rm *
# list databases
DBS="$(mysql -u $MySQL_USER -h $MySQL_HOST -p$MySQL_PASS -Bse 'show databases')"
echo "$DATESTAMP -> list databases" >> $LOGFILE
echo "$DBS" > $FILESDIR/backup_tmp/databases.list
# dump databases
#NUMDATABASES="$(cat $FILESDIR/backup_tmp/databases.list | grep -c '')"
echo "$DATESTAMP -> dumping databases" >> $LOGFILE
for db in $DBS
do
#    if [ "db" != "$MySQL_ignoredb" ];
#      then
      echo "$DATESTAMP   -> dumping database $db" >> $LOGFILE
      mysqldump -u $MySQL_USER -h $MySQL_HOST -p$MySQL_PASS $db > $FILESDIR/backup_tmp/mysql_"$db"_$(date +%F).mysql
#      fi
done


</pre>  
</pre>  
</blockquote>
</blockquote>

Revision as of 20:43, 17 November 2012

  • backup via crontab
    • create crontab
20     3     *     *     *     /var/www/$USER$/files/backup.sh >& /dev/null
  • backup script
#!/bin/bash
#
# confixx backup
#

# Variables
HOMEDIR="$(pwd)"
FILESDIR="$HOMEDIR/files"
LOGFILE="$FILESDIR/backup.log"
DATESTAMP="$(date "+%F %T")"

MySQL_USER="..."
MySQL_PASS="..."
MySQL_HOST="localhost"
MySQL_ignoredb=""
#MySQL_ignoredb="information_schema"


# Append log file
touch $LOGFILE
echo "$DATESTAMP	Starting Backup" >> $LOGFILE

# remove old backup
mkdir $FILESDIR/backup
cd $FILESDIR/backup
rm *
mkdir $FILESDIR/backup_tmp
cd $FILESDIR/backup_tmp
rm *

# list databases
DBS="$(mysql -u $MySQL_USER -h $MySQL_HOST -p$MySQL_PASS -Bse 'show databases')"
echo "$DATESTAMP	 -> list databases" >> $LOGFILE
echo "$DBS" > $FILESDIR/backup_tmp/databases.list


# dump databases
#NUMDATABASES="$(cat $FILESDIR/backup_tmp/databases.list | grep -c '')"
echo "$DATESTAMP	 -> dumping databases" >> $LOGFILE


for db in $DBS
do
#     if [ "db" != "$MySQL_ignoredb" ];
#      then
       echo "$DATESTAMP	   -> dumping database $db" >> $LOGFILE
       mysqldump -u $MySQL_USER -h $MySQL_HOST -p$MySQL_PASS $db > $FILESDIR/backup_tmp/mysql_"$db"_$(date +%F).mysql
#      fi
done