Monday, March 26, 2012

Backing up and restoring mySQL db

I am in phpMyAdmin and looking to automate the backing up of my db. Looks like the way to accomplish this is via a cron script, more on this later. First, I wanted to test a couple simple hypotheses about backing up and restoring a single db. Lets face it, if you cannot restore a backup file, what is the point. Its like practicing for disaster recovery.

Steps to Creating the backup file

  1. Click on the database
  2. and then on the Export tab.
  3. On the Export screen, choose Quick, with format of SQL, both defaults
  4. Click the Go button.
  5. A file download dialog appeared, click the Save button,
  6. Choose where to save the file.
  7. Rename the saving script if you like, default name is dbname.sql.

The download was real quick, as my db is very small, for now. I browsed to the folder to view the file, just to verify that it stored where i choose. The file is only 3 MB.

Restoring the script (actually importing).


From phpMyAdmin,

  • Click on the Export tab for my db
  • I clicked on Import
  • Browsed to my backup (export) file and selected it.
  • Leaving the default options alone, scrolled down and clicked the Go button and was presented with an error indicating a Duplicate record could not be inserted for a col that is a primary key for the initial table in my db. I did not expect to see this, but the error is obvious, the import was trying to restore to an existing table with the same values. I must be looking at something a little sideways.

My workaround was to
  1. simply delete the db, since it has *corrupt data (in my disaster scenario)

  2. Clicked on
  3. and the re-create the db with the same name.
  • Click on Databases,
  • Type in new name
  1. Click Create
  2. Select the newly created db
  3. Click on the Import tab
  4. Browse to the file
  5. Click Go and walla, the import worked like a charm.

There is probably a better way than for me to physically delete the corrupt db, re-create and then import into a empty db, but that will come at a later time.

An interesting side note, the importing of the restore script ran 384 queries, the script is just a bunch of create and insert queries for each of the 228 moodle 2.2 tables.

Moral of the story?

Test you disaster recovery plans when there is not an actual disaster at hand.

1 comment:

  1. The most effective method to Recover Dropped Database on MySQL through DB Recovery Support |Cognegic|
    Dropping a database is most happening issue which typically asked by the clients. Be that as it may, recuperating this database is some place vital. In more often than not your IT overseer likewise not ready to recuperate it. That is the reason I am instructing you to recoup your dropped database with the assistance of Cognegic's DB Recovery Support or Exchange Database Recovery. We completely comprehend the issues or difficulties looked by you with respect to information recuperation. By remembering these things we give Backup Recovery to a wide range of databases including MongoDB, Cassandra, and MySQL et cetera.
    For More Info: https://cognegicsystems.com/
    Contact Number: 1-800-450-8670
    Email Address- info@cognegicsystems.com
    Company’s Address- 507 Copper Square Drive Bethel Connecticut (USA) 06801

    ReplyDelete