Last active
January 4, 2016 18:09
-
-
Save tortillaj/8658592 to your computer and use it in GitHub Desktop.
Easy MySQL backups with Bash
This file contains hidden or 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 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