Created
November 4, 2010 14:52
-
-
Save bencates/662567 to your computer and use it in GitHub Desktop.
Cron script to back up a database daily
This file contains 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 connection info | |
user=ssh_username | |
password=ssh_password | |
host=ssh_host | |
db=ssh_database | |
# Filename settings | |
path=~/dbbackups/ | |
name=dbbackup`date +%y%m%d`.sql.bz2 | |
link=dbbackup.sql.bz2 | |
# Dump and bzip the databases | |
mysqldump --add-drop-table \ | |
--user=$user --password=$password --host=$host \ | |
--databases $db \ | |
| bzip2 > $path$name | |
# Symlink the newest backup to a static filename | |
ln -sf $path$name $path$link | |
# Delete backups older than a week | |
find $path -name "*.sql.bz2" -mtime +7 -type f -delete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment