MySQL backup

mkdir /home/mento/sql
mkdir /home/mento/sql/1-Mon /home/mento/sql/2-Tue /home/mento/sql/3-Wed /home/mento/sql/4-Thu /home/mento/sql/5-Fri /home/mento/sql/6-Sat /home/mento/sql/7-Sun
#!/bin/bash

BACKUP="/home/mento/sql"
DATE=`date "+%Y%m%d_%H%M"`
TODAY=`date "+%u-%a"`

DUMP="/usr/bin/mysqldump --defaults-file=/etc/mysql/debian.cnf --extended-insert --force"

DB="db1 db2"

ulimit -f unlimited
ulimit -e 5

if [ "$TODAY" == "1-Mon" ]; then
    $DUMP --all-databases >"$BACKUP/$TODAY/mysqlall_$DATE.dump"
    /bin/gzip "$BACKUP/$TODAY/mysqlall_$DATE.dump"
  else
    for d in $DB
    do
        $DUMP $d >"$BACKUP/$TODAY/mysql_$d""_$DATE.dump"
        /bin/bzip2 "$BACKUP/$TODAY/mysql_$d""_$DATE.dump"
    done
fi

/bin/sync

/usr/bin/find $BACKUP -type f -name mysql_* -mtime +35 -print0 |/usr/bin/xargs -r -0 /bin/rm

exit 0
 
Logged in as: Oszkár Kmetti
backup/sqlbackup.txt · Last modified: 2008.08.04 23:50 by oszi
 
Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki