Checking and restoring your backup

In a previous article i’ve discussed how i did some regular, encrypted and compressed database backups. It’s good when things are running, but we also have to check if they are running as planned.┬áMaybe nothing bad will happen (to the lucky) to the database you are protecting, but even so, what good are the┬ábackup files for if we don’t know how to restore them when necesary?

The steps are basically the same as in the previous article, the only difference is that they are in reverse order (logicaly)

Downloading your file from the backup location

I used curl to login to the ftp server where i have my backup placed. I used the “-o” parameter to choose my download location, which is in the folder “download” under the same filename as on the ftp.

curl -u user:pass ftp://ftpserver/db-backup-12-17-13.tar.gz.enc -o download/db-backup-12-17-13.tar.gz.enc

How to decrypt your backup

To decrypt your file, you have to use the same cypher used in crypting it. The “-in” parameter tell opennssl which file to process and the “-out” under which filename it should be saved.

openssl enc -d -aes-256-cbc -in db-backup-12-17-13.tar.gz.enc -out db-backup-12-17-13.tar.gz

How to decompress your backup

gunzip db-backup-12-17-13.tar.gz

How to untar your backup

tar xvfz db-backup-12-17-13.tar

If you just want the last 3 steps in a single line, you can join them using “&&” like so:

openssl enc -d -aes-256-cbc -in db-backup-12-17-13.tar.gz.enc -out db-backup-12-17-13.tar.gz && gunzip db-backup-12-17-13.tar.gz && tar xvfz db-backup-12-17-13.tar

Restoring your backup into the database

To import our backup into the database, we are going to login to the mysql server via the command line and direct the file to the appropriate database. You can notice that i am not using password authentication. This is due to the configuration file created in the initial post.

mysql -u DB_USER -h localhost DB_NAME < db-backup-12-17-13.sql