Last active
September 17, 2021 21:10
-
-
Save dallin/6c6b1d5c7a42af6a4396b6eac82959e3 to your computer and use it in GitHub Desktop.
Simple MySQL backup script
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/bash | |
database="" | |
username="" | |
password="" | |
backupdir="/home/forge/backups/mysql" | |
date=`date +%Y-%m-%d` | |
suffix="-${database}.sql.gz" | |
filename="${date}${suffix}" | |
mkdir -p /${backupdir}/ | |
mysqldump --user=${username} --password=${password} ${database} --lock-tables=false --add-drop-table --compress --routines | gzip > /${backupdir}/${filename} | |
find ${backupdir} -type f -name "*${suffix}" -mtime +30 -delete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment