Skip to content

Instantly share code, notes, and snippets.

@dallin
Last active September 17, 2021 21:10
Show Gist options
  • Save dallin/6c6b1d5c7a42af6a4396b6eac82959e3 to your computer and use it in GitHub Desktop.
Save dallin/6c6b1d5c7a42af6a4396b6eac82959e3 to your computer and use it in GitHub Desktop.
Simple MySQL backup script
#!/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