Skip to content

Instantly share code, notes, and snippets.

@corentingi
Created November 27, 2017 19:32
Show Gist options
  • Save corentingi/6229d82d2907a41eb2f4dc508e098a27 to your computer and use it in GitHub Desktop.
Save corentingi/6229d82d2907a41eb2f4dc508e098a27 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Taken from https://simon-davies.name/bash/backing-up-mysql-databases
# Database credentials
user=""
password=""
host=""
db_name=""
# Other options
backup_path="/path/to/your/home/_backup/mysql"
date=$(date +"%d-%b-%Y")
# Set default file permissions
umask 177
# Dump database into SQL file
mysqldump --user=$user --password=$password --host=$host $db_name > $backup_path/$db_name-$date.sql
# Delete files older than 30 days
find $backup_path/* -mtime +30 -exec rm {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment