Create MySql Backup


/ Published in: Bash
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #!/bin/sh
  2.  
  3. # -- backup.sh ---------------------------------------------------
  4. #
  5. # shell-script + phpmailer: roept het *nix commando 'mysqldump' direct aan
  6. # en dumpt het in een .gz bestand, wordt vervolgens door phpmailer als attachment
  7. # verstuurd naar opgegeven emailadres
  8. #
  9. # Waarom phpmailer? Omdat mijn webserver mutt niet ondersteunt en ik toch
  10. # een gzip attachment wil versturen :)
  11. #
  12. # Hoe te gebruiken:
  13. # ---------------------
  14. # 1. download de laatste versie van phpmailer: http://phpmailer.sourceforge.net
  15. # 2. plaats dit bestand + class.phpmailer.php, class.smtp.php (overige bestanden
  16. # van phpmailer heb je niet nodig) en mail-backup.php
  17. # in je webroot, dus BOVEN je /public_html of /www folder, zodat
  18. # men er vanuit de browser niet bij kan
  19. # 3. pas de variabelen in dit bestand en in mail-backup.php aan naar believen
  20. # 4. chmod=711 backup.sh
  21. # 5. cron: /bin/sh /absoluut/pad/naar/backupdir/backup.sh, kies zelf je cron-frequentie
  22. # 6. default cron mailer uitzetten; mailing wordt verzorgd door
  23. # het mail-backup.php script
  24. # ----------------------------------------------------------------
  25.  
  26.  
  27. # -- 1. vars declareren ------------------------------------------
  28.  
  29. # db gegevens - DBNAME wordt gebruikt in naam backupfile
  30. DBNAME=je_db_naam
  31. DBPASS=je_db_wachtwoord
  32. DBUSER=je_db_username
  33.  
  34. # absoluut pad backupdir (bv 'backups'). Gebruik evt. phpinfo() om dit te achterhalen
  35. BACKUPDIR=/pad/naar/jouw/webroot/backups
  36.  
  37. # naam sql file, wordt na elke cronjob overschreven
  38. SQLGZFILE=$BACKUPDIR/$DBNAME.sql.gz
  39.  
  40. # naam php file die mail verzorgt
  41. PHPBACKUPFILE=mail-backup.php
  42.  
  43. # absoluut pad naar mysqldump, standaard is /usr/local/bin/mysqldump
  44. MYSQLDUMP=/usr/local/bin/mysqldump
  45.  
  46. # absoluut pad naar php, standaard is /usr/bin/php
  47. PHP=/usr/bin/php
  48.  
  49.  
  50. # -- 2. uitvoeren ------------------------------------------------
  51.  
  52. # uitvoeren en pijpen (zucht) door gzip
  53. $MYSQLDUMP --opt -c -e -Q -u$DBUSER -p$DBPASS $DBNAME | gzip > $SQLGZFILE
  54.  
  55. # php mailer proggel aanroepen
  56. $PHP $BACKUPDIR/$PHPBACKUPFILE
  57.  
  58.  
  59. # -- Changelog ---------------------------------------------------
  60. #
  61. # 2007-06-20 Ramon Eijkemans <monchito [a] monlog [punt] nl>
  62. # * release 1.0, zie http://www.monlog.nl/tools/mysql-backup/
  63. # ----------------------------------------------------------------

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.