Sep 27
A while ago I wrote an article about a script I created to backup databases. Since then I had to make little changes and decided to put it to Google code as Open-Source-Project and released the new version 0.1.1 with some minor changes.
If you're interested in the script, head over to its project page and check the appropriate pages like the Changelog and the Installation and Requirements page. Feel free to download and comment it.
Tags:
Backup,
gzip,
mySQL,
mysqldump,
php,
zip
Jun 27
Vor kurzem habe ich ein schönes Skript zum Sichern einer MySQL-Datenbank und anschließendem Versenden des Backups per Email hier gefunden.
Das Skript ist an sich ganz gut, aber mir hat es strukturell nicht gefallen, da man die Datenbankzugangsdaten inline eintragen muss und es ausserdem nur für eine Datenbank funktioniert. Deswegen habe ich das ganze ein wenig umgeschrieben und stelle das hier gerne zum Download bereit.
Was kann es?
- Backup mehrerer Datenbanken
- Versenden der Backups an mehrere Empfänger
Es wird dabei pro Datenbank eine Email versendet und auf dem Server bleiben keine Dateien liegen. Das ganze ist auch noch einfach zu konfigurieren.
Wie benutze ich das?
- Aktuelle Version (0.1) herunterladen
- Daten in backup.php anpassen (ist alles kommentiert)
- alles in ein Verzeichnis deiner Wahl hochladen
- ggf. einen cronjob anlegen, der das Skript periodisch ausführen
Hier die backup.php, welche die entsprechenden Klassen aufruft und das Backup anstößt (ist auch im Download mit enthalten):
ini_set('error_reporting', E_ALL);
// include the files
require_once 'MySQLConfig.php';
require_once 'MySQLBackup.php';
// add some databases to backup
// the domain will be appended to the email subject and is also included within the sql file for identification.
$cfgHost0 = new MySQLConfig('username0', 'password0', 'database_name0', 'domain0');
$cfgHost1 = new MySQLConfig('username1', 'password1', 'database_name1', 'domain1');
$backup = new MySQLBackup();
// the path to the directory where this script is resided
$backup->setExecutionPath('/srv/domain/backup/');
// add the database configs to backup
$backup->addDatabaseToBackup($cfgHost0);
$backup->addDatabaseToBackup($cfgHost1);
// the sender of the backup mail
$backup->setSender('admin@yourdomain.com');
// add some people to receive the backup
$backup->addRecipient('john@yourdomain.com');
$backup->addRecipient('frank@yourdomain.com');
// execute the whole thing
$backup->backup();
Falls es Probleme und/oder Anregungen gibt, bitte diesen Post kommentieren, danke!
PS: zum Anlegen eine Cronjobs per SSH auf deinem Server einloggen, dann "crontab -e" ausführen, dann z.B. "0 2 * * 0,3 wget http://yourdomain.com/backup/backup.php -nc -q -O /dev/null" für eine Ausführung Sonntags und Mittwochs um 2 Uhr nachts einfügen. Mit ":wq" speichern und die Datei schliessen, dann sollte es schon funktionieren
Tags:
Backup,
Email,
mySQL,
php
Recent Comments