diff --git a/backup-sql.sh b/backup-sql.sh index 81bc222..18070f9 100644 --- a/backup-sql.sh +++ b/backup-sql.sh @@ -4,31 +4,32 @@ # 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/ +# path="var/customers/backups/" temp="var/customers/temp-backup-path/" encryption="path/to/enc.key" external="user@extern.server.de" +MYSQL_USER="root" +MYSQL_PASSWORD="root" # um <> zu vermeiden cd / -# Ordner finden -for f in $( ls $path); do - -# SQL-Dateien finden - for g in $( ls $path$f | grep sql); do - -# Dateien kopieren - cp $path$f/$g $temp - done -done - #Datum erstellen datum=$(date +"%d"."%m"."%y") -#Dateien zusammenpacken und komprimieren -tar cfvz backup-sql-$datum.tar.gz $temp +#Datenbanken finden +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 + 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 #Verschlüsseln und gepackte Datei löschen openssl aes-256-cbc -kfile $encryption -in backup-sql-$datum.tar.gz -out ./backup-sql-$datum.enc.tar.gz