Jun 29 2005

Simple MySQL backup

Donncha shared his simple MySQL backup script that backs up individual WordPress tables into separate .sql.gz files, and keeps a week worth of them just in case something horrible happens.

This is exactly what I did this morning! Write a simple Bash script that loops through 20+ databases, and create .sql.gz files per database. I did this to exclude some of the databases that I do not intend to backup and they used up quite a bit of space. I did not try the “weekly” thing, as I already have my own weekly incremental backups running.

for db in `echo "SHOW DATABASES;" | mysql -s`
do
  case "$db" in
    cache|pmadb|spamlog|test|other DB I don't intend to backup)
      ;;
    *)
      mysqldump --add-drop-table -qc "$db" | \
        gzip -c > "$HOME/archive/mysql/$db.sql.gz"
      ;;
  esac
done

No Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>