Automating Mysql backups

Menù di navigazione
  • Home
  • Contacts
HOME | Index |

Automating Mysql backups

Automating Mysql backups

Well this is the scenario: you have a lot of machines around there, all with important data stored into Mysql tables. All the machines are Linux based and you want to backup all MySQL data each night....

We have something for you!

First step

Log in as root into the machine you want to backup. Here you need a local working directory: we call it /home/localdumps

mkdir /home/localdumps

Then log in into the target machine, where you want to stored the backup datas and choose a new directory where to put the backups.

mkdir /home/storedbackups

In this machine we need a fully functional ftp server and an ftp user to write down the backups.

The script itself

Go back to the source machine, the one you want to backup. Here you can create the script backupmysql

pico /bin/backupmysql

Copy the following lines and edit the first parameters to match your configuration:

#!/bin/bash

LOCALDIR="/home/localdumps"

TARGET=""
TARGETPORT=""
TARGETUSER=""
TARGETPASS=""
TARGETDIR=""
TARGETRETRYCONNECT=6

MAILTO="YOUREMAILADDRESSHERE"

MYSQLPASS=""

namefile=$(date +%y.%m.%d)
SOURCE=`hostname`
cd $LOCALDIR
/usr/bin/mysqldump -RaAcel --add-drop-table -h localhost -u root -p$MYSQLPASS > mysqldump.sql
tar -czf mysqldump.tar.gz mysqldump.sql
ftp -i -n -v $TARGET $TARGETPORT 1> mysqldump-ftptest.log 2> mysqldump-ftptest.log <user $TARGETUSER $TARGETPASS
cd $TARGETDIR
bin
put mysqldump.tar.gz $SOURCE.$namefile.tar.gz
quit
!EOF!
mail -s "MysqlDUMP on $SOURCE" $MAILTO < mysqldump-ftptest.log
rm -f mysqldump.tar.gz
chmod 700 mysqldump.sql

Now we transform it into executable

chmod 700 /bin/backupmysql

and then we can put it into crontab as usual.

Labs
  • CentOS + BlueQuartz
  • Installing Spamassassin ClamAv and Mailscanner on Bluequartz
  • SARE Rules & RulesDuJour
  • Installing MRTG
  • Mass Change IP
  • CCED problems
  • Deleting old logfiles
  • POP3 problems
  • Recalculate Quotas
  • How to block an IP address
  • NAMED and DNS
  • PHP
  • Enabling safe mode per-directory
  • Howto install php4 & php5 on Apache2
  • Linux
  • Automating Mysql backups
  • Restoring MySQL dumps
  • Replacing Text In Files
  • Firefox and flash on x86_64
  • Find user's files
  • Lines of code
  • Vsftp with virtual users
  • MSN
  • RandomCase

Home | Contacts | E.R.WEB Official Site