Skip to content

Instantly share code, notes, and snippets.

@wopfel
Created July 13, 2014 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wopfel/babe646a47d79753cb1e to your computer and use it in GitHub Desktop.
Save wopfel/babe646a47d79753cb1e to your computer and use it in GitHub Desktop.
Backup script for MariaDB (or MySQL). Placed in /etc/cron.hourly/. Creates a backup of all databases every hour and keeps the current plus nine previous versions.
#!/bin/bash
BASENAME="/var/backups/MySQL-Backup.gz"
x=9
rm "$BASENAME.$x"
while [ $x -gt 1 ]
do
y=$(( $x - 1 ))
mv "$BASENAME.$y" "$BASENAME.$x"
x=$(( $x - 1 ))
done
mv "$BASENAME" "$BASENAME.1"
umask 0027
# Seit 26.04.2013 kommt ohne "--events" die Meldung:
# Warning: Skipping the data of table mysql.event. Specify the --events option explicitly.
/usr/bin/mysqldump --all-databases --events --password=PASSWORD --user=root --host=localhost \
| gzip --stdout \
> "$BASENAME"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment