Last active
October 25, 2022 08:54
-
-
Save admackin/1136210 to your computer and use it in GitHub Desktop.
Rolling MySQL database backups
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# use with cron entries such as: | |
#3 */2 * * * $HOME/bin/mysql-backup.sh dbname backupname hourly H | |
#8 1 * * * $HOME/bin/mysql-backup.sh dbname backupname daily a | |
#33 2 1,8,15,23 * * $HOME/bin/mysql-backup.sh dbname backupname weekly d | |
#33 2 28 * * $HOME/bin/mysql-backup.sh dbname backupname monthly b | |
DB_NAME="$1" | |
BACK_ROOT="$2" | |
PERIOD_NAME="$3" | |
DATE_FMT="$4" | |
DB_PASSWORD="password1234" | |
DB_USER="backup" | |
DUMP_NAME="${BACK_ROOT}/${PERIOD_NAME}/${DB_NAME}.`date +%${DATE_FMT}`.sql" | |
DB_SERVER="127.0.0.1" | |
nice mysqldump -u $DB_USER -p$DB_PASSWORD -h $DB_SERVER $DB_NAME | gzip -1 --rsyncable > "$DUMP_NAME.gz" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please add automatic directory tree creation line 16