Froxlorbackup/backup-sql.sh

47 lines
1.3 KiB
Bash
Raw Normal View History

2014-02-25 19:11:29 +00:00
#!/bin/bash
# 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.
#
# contains lines from http://menzerath.eu/artikel/froxlor-alle-datenbanken-und-verzeichnisse-sichern/
#
2014-02-25 19:11:29 +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
# 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")
#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)"`
#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"
done
# Alle SQL-Dumps in ein Archiv packen
tar cfvz $temp/../backup-sql-$datum.tar.gz $temp
2014-02-25 19:11:29 +00:00
#Verschlüsseln und gepackte Datei löschen
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
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