Skip to content

Instantly share code, notes, and snippets.

@bertomartin
Forked from i2bskn/backup_databash.sh
Created October 17, 2013 17:48
Show Gist options
  • Save bertomartin/7029253 to your computer and use it in GitHub Desktop.
Save bertomartin/7029253 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Backup database
host='localhost'
user='backup'
passwd='secret'
db_array=(dbname)
bk_dir=/usr/local/backup
for db in ${db_array[@]}; do
mysqldump -h${host} -P3306 -u${user} -p${passwd} ${db} > ${bk_dir}/${db}_`date +%Y%m%d%H%M%S`.sql
done
find ${bk_dir} -mtime +30 -type f -name '*.sql'|xargs rm -f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment