2014-02-25 19:11:29 +00:00
|
|
|
#!/bin/bash
|
2014-03-12 17:59:14 +00:00
|
|
|
# 2014 by Mainboarder.de
|
2014-02-25 19:11:29 +00:00
|
|
|
#
|
|
|
|
# Keep this comment untouched and do not use this software for military purposes.
|
|
|
|
# you are allowed to use this just like you want on your own risk.
|
2014-03-12 17:59:14 +00:00
|
|
|
#
|
2014-03-11 18:08:23 +00:00
|
|
|
# contains lines from http://menzerath.eu/artikel/froxlor-alle-datenbanken-und-verzeichnisse-sichern/
|
|
|
|
#
|
2014-02-25 19:11:29 +00:00
|
|
|
|
2014-03-12 17:59:14 +00:00
|
|
|
temp="var/customers/temp-backup-path"
|
|
|
|
backuppath="/mnt/usb/backups"
|
|
|
|
encryption="/path/to/enc.key"
|
2014-04-15 19:23:55 +00:00
|
|
|
sshkey="/etc/ssh/ssh_host_dsa_key"
|
2014-02-25 19:11:29 +00:00
|
|
|
external="user@extern.server.de"
|
2014-04-15 19:23:55 +00:00
|
|
|
mysql_user="root"
|
|
|
|
mysql_password="root"
|
2014-02-25 19:11:29 +00:00
|
|
|
|
2014-03-12 17:59:14 +00:00
|
|
|
# Programm
|
|
|
|
|
2014-02-25 19:11:29 +00:00
|
|
|
# um <<tar - Entferne führende „/“ von Elementnamen>> zu vermeiden
|
|
|
|
cd /
|
|
|
|
|
|
|
|
#Datum erstellen
|
|
|
|
datum=$(date +"%d"."%m"."%y")
|
|
|
|
|
2014-03-11 18:08:23 +00:00
|
|
|
#Datenbanken finden
|
2014-04-15 19:23:55 +00:00
|
|
|
databases=`mysql -u $mysql_user -p$mysql_password -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema|mysql)"`
|
2014-03-11 18:08:23 +00:00
|
|
|
|
|
|
|
#Datenbanken exportieren
|
|
|
|
for db in $databases; do
|
2014-04-15 19:23:55 +00:00
|
|
|
mysqldump -u $mysql_user -p$mysql_password $db > "$temp/$db.sql"
|
2014-03-11 18:08:23 +00:00
|
|
|
done
|
2014-03-12 17:59:14 +00:00
|
|
|
|
2014-03-11 18:08:23 +00:00
|
|
|
# Alle SQL-Dumps in ein Archiv packen
|
2014-03-12 17:59:14 +00:00
|
|
|
tar cfvz $temp/../backup-sql-$datum.tar.gz $temp
|
2014-02-25 19:11:29 +00:00
|
|
|
|
|
|
|
#Verschlüsseln und gepackte Datei löschen
|
2014-03-12 17:59:14 +00:00
|
|
|
openssl aes-256-cbc -kfile $encryption -in $temp/../backup-sql-$datum.tar.gz -out $temp/backup-sql-$datum.enc.tar.gz
|
2014-02-25 19:11:29 +00:00
|
|
|
|
2014-03-12 17:59:14 +00:00
|
|
|
rm $temp/../backup-sql-$datum.tar.gz
|
2014-02-25 19:11:29 +00:00
|
|
|
|
|
|
|
#Kopieren und verschlüsselte Datei löschen
|
2014-04-15 19:23:55 +00:00
|
|
|
scp -i $sshkey $temp/backup-sql-$datum.enc.tar.gz $external:$backuppath
|
2014-02-25 19:11:29 +00:00
|
|
|
|
|
|
|
rm -r $temp
|
|
|
|
mkdir $temp
|