testtestHome

Zichzelf per mail een backup sturen van een MySQL-databank…

30.10.2008 door Mich - lire la version francophone

Het is iets dat men op dedicated servers als amateur soms wel vergeet: een backupje maken. Meestal heb je van je hostingbedrijf geen backup, tenzij je hiervoor betaalt. Ik ben hiervoor nogal gierig, en maakte onder andere een belachelijk klein scriptje die mij de inhoud van mijn MySQL-databank dagelijks per mail stuurt.

Deze tutorial werkt met een MySQL-databank op een Ubuntu Server. Opdat u mails zou kunnen sturen met attachments, installeer je best mutt:

sudo apt-get install mutt

Ik heb als directory voor dit voorbeeldje /home/emich/mysqlbackup gemaakt :

cd /home/emich/mysqlbackup

Maak daar een file aan, « mysqlbackup.txt », met een tekstje naar uw zin. Deze is de body van uw mail.

echo 'SQL-dagschotel! Smakelijk!' > mysqlbackup.txt

Maak daarna een file met het scriptje zelf, « mysqlbackup.sh », met de volgende inhoud:

/usr/bin/mysqldump --user=username --password=password --all-databases > /home/emich/mysqlbackup/db_backup.sql

/bin/tar -czf /home/emich/mysqlbackup/backupsql.tar.gz /home/emich/mysqlbackup/*.sql

/usr/bin/mutt -s "[eMich] Daily backup" -a /home/emich/mysqlbackup/backupsql.tar.gz lemich@gmail.com < /home/emich/mysqlbackup/mysqlbackup.txt

/bin/rm /home/emich/mysqlbackup/*.sql

/bin/rm /home/emich/mysqlbackup/*.tar.gz

of doe gewoon een domme wget en pas de file aan uw noden aan :

wget http://www.emich.bemisc/mysqlbackup.sh

Ik stuur trouwens de mail naar een gmail-mailbox, want de backup moet altijd elders beschikbaar zijn.

Verander daarna de permissies van het scriptje:

chmod +x mysqlbackup.sh

En voeg dit uiteindelijk toe aan crontab, zodat deze dit dagelijks om 4u 's ochtends uitvoert. Voer daarvoor volgend commando uit:

crontab -e

In de editor voeg je dan de volgende lijn toe, en klaar ben je !

0 4 * * * /home/emich/mysqlbackup/mysqlbackup.sh &> /dev/null

Ik zet dit online opdat andere mensen hier ook gebruik van zouden kunnen maken. Het scriptje heeft zich bij mij al bewezen maar ik zeg niet dat het niet beter kan.

tags: . . . |
[...]I wouldn’t be capable to pursue all of these various goals whilst simultaneously dedicating the vitality [...]
[...] we like to remember many other sites on the internet, whether or not they may not be linked to us, by linking to them. Below are some webpages really worth visiting [...]
[...] always check below, are a number of utterly unrelated sites to ours, on the other hand, these are generally most trustworthy sources that we use [...]
[...] Now each time a person looks at the existing fashion assertion, it is usually measurement zero [...]
[...] Below are a few of the sites that we strongly recommend for our guests [...]
[...] Just one site which I could possibly think of for deeper info [...]
[...] entails fairly long time for achieving good results. One should always have real persistence [...]
nopalea psoriasis - Great links (25/04/2012 @ 05:59)
[...] pursuing are a few links to online websites which I actually communicate with because we think these are worthwhile checking out [...]
[...] Blogpost: article .. spotted this article pertaining to [...]
[...] Now any time a man or woman looks at the current fashion assertion, it is usually measurement zero [...]
[...] may potentially have worn out the lack of this points driven by way of your self on [...]
[...] we really like to honor a number of sites on the internet, even if they are not linked to us, simply by linking to them. Below are some sites truly worth checking out [...]
[...] Listed are some of the sites that we recommend for our visitors [...]
Zeg het eens...
  • Naam *

  • email *

  • Webstek

  • Uw reactie *

  • * = verplicht veld


  • Vergeet niet wie ik ben!