Flipkart

Wednesday, June 2, 2010

Restoring from a Database Backup (with GZip Compression)

So you’ve got a backup of your database (either using the method above, or some other way), and something has gone wrong and you need to restore, or you’re migrating it to a new server. You could use one of the other tools mentioned before, but in the example of phpMyAdmin, what if your database backup file is bigger than the allowed upload size? Well luckily, the command-line doesn’t mind.
The command to restore is very similar to the one for backing up. Firstly, without GZip compression:
  1. cat db_backup.sql | mysql -u mysqluser -p mysqldatabase  
We use the “cat” command to output the contents of the backup script, and pipe its contents into the mysql program. As you can see, the mysql program takes the same options as the mysqldump one does in section two.
Now if the script was GZip compressed, we can’t just output its contents into mysql, as it will be compressed data instead of a nice SQL script. So we do the following:
  1. gunzip < db_backup.sql.gz | mysql -u mysqluser -p mysqldatabase  
See, it's very familiar, just switched around a bit.

No comments:

Post a Comment