Skip to content

Instantly share code, notes, and snippets.

@relkai relkai/dbbackup.sh
Last active Sep 3, 2018

Embed
What would you like to do?
Backup aller MySQL Datenbanken
#!/bin/bash
db="db1 db2 db3 db4"
passwd="mysql-root-passwort"
backup_date=$(date +%Y%m%d)
backup_path="/mnt/backup/db"
# Loeschen der bin-logs
echo '* bin-logs werden geloescht'
mysql --password=${passwd} < /root/scripts/backup/bin-log-reset.sql
echo
# Loeschen alter DB-Backups
find ${backup_path}/ -mtime +7 -exec rm {} \;
# Datenbank Backup
echo '* Datenbanken werden gesichert'
for db_name in ${db} ; do
echo Backup der Datenbank ${db_name}
backup_file="${backup_path}/${db_name}_${backup_date}.sql.gz"
mysqldump --opt --password=${passwd} ${db_name} | gzip -c > ${backup_file}
done
echo
# Optimierung aller Datenbanken
echo '* Datenbanken werden optimiert'
mysqloptimize --all-databases --auto-repair --password=${passwd}
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.