Backing Up Your Database

Richard Eriksson - June 7, 2006 - 14:22

The following only applies to those with SSH access to their own server.

Important note: This will not work for those on Bryght's shared hosted service: only customers with their own virtual private server can follow these steps. If you are using the Bryght hosted service, contact us for a backup of your site's database.

  1. ssh yourdomain.com -l admin
    • if you have a different account name than 'admin', use that account. It will need 'sudo' privileges.
    • replace yourdomain.com with the domain you have pointed to your server, or the IP address for your server. Then type in your password.
    • We recommend Putty for Windows users. Those on a Mac or Linux computer can use their terminal (or an open source equivalent like iTerm for the Mac).
  2. sudo su
    • [type your password if necessary]
  3. find your settings.php file. Possible locations are /var/www/html/sites/default or /var/www/html/sites/yourdomain.com
  4. cat /var/www/html/sites/yourdomain.com/settings.php | grep "mysql"
    • replacing the directory name as appropriate
  5. you should see something like: mysql://username:password@localhost/databasename
  6. mysqldump -uYourUser -pYourPassword Datbase_Name > yourdomain.com.MM.DD.YYYY.mysql
    • replace YourUser, YourPassword, Database_Name and the date (which is useful when going through old backups) as appropriate
  7. tar -czvf yourdomain.com.MM.DD.YYYY.tar.gz yourdomain.com.MM.DD.YYYY.mysql
    • again replace as appropriate
  8. download the resulting file at http://yourdomain.com/yourdomain.com.MM.DD.YYYY.tar.gz
  9. rm yourdomain.MM.DD.YYYY.*
    • delete the files to conserve space on your server
Creative Commons License

This work is licensed under a Creative Commons Attribution-Share Alike 2.5 License. This license applies to all text written by Bryght. All others retain full copyright to their text.