Last active
November 10, 2017 09:25
-
-
Save deponeWD/a01911ace3771d9af46d735015c5ba48 to your computer and use it in GitHub Desktop.
Backup of MySQL-Database
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 | |
# Getting username and password from .my.cnf | |
# [mysqldump] | |
# password=PASSWORD | |
# user=USERNAME | |
host="localhost" | |
db_name="NAME" | |
# Other options | |
backup_path="/path/to/backups" | |
date=$(date +"%Y-%m-%d") | |
# Set default file permissions | |
umask 177 | |
# Dump database into gzipped SQL file | |
mysqldump --host=$host $db_name | gzip > $backup_path/$db_name-$date.sql.gz | |
# Delete files older than 30 days | |
find $backup_path/* -name *.sql.gz -mtime +30 -exec rm {} \; |
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
@daily ~/bin/backup.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment