Skip to content

Instantly share code, notes, and snippets.

@tortillaj
Last active January 4, 2016 18:09
Show Gist options
  • Save tortillaj/8658592 to your computer and use it in GitHub Desktop.
Save tortillaj/8658592 to your computer and use it in GitHub Desktop.
Easy MySQL backups with Bash
#!/bin/bash
# Database credentials
user="XXXXX"
password="XXXXX"
host="XXXXX"
db_name="XXXXX"
# Other options
backup_path="/location/of/your/backups"
date=$(date +"%Y-%m-%d")
timestamp=$(date +"%H-%M-%S")
# 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-$timestamp.sql
# Delete files older than 5 days
find $backup_path/* -mtime +5 -exec rm {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment