Skip to content

Instantly share code, notes, and snippets.

@deponeWD deponeWD/backup.sh
Last active Nov 10, 2017

Embed
What would you like to do?
Backup of MySQL-Database
#!/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 {} \;
@daily ~/bin/backup.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.