Objective
Detail the procedure needed to restore an older database backup, not the default (which is the most recent snapshot).
Table of Contents
Background
By default, the most recent backup file in the backups directory will be used to restore the database. In some instances this may not be the desired effect. This tutorial provides the steps needed to restore an older backup (not from the default most recent snapshot). There are two different scenarios provided. You should align with the one that best suits your needs.
- Restore from a known snapshot
- Restore to a standalone database Server first
The time required to perform a restoration of the database will vary depending on its size.
Disclaimer
As always, proceed with caution when restoring the database to master and/or slave Servers. If you do not know precisely what you are doing, your actions could produce incorrect results. This could be devastating, particularly in a production environment.
Scenario 1 - Restore from a known snapshot
In this scenario, you are absolutely certain which snapshot to restore from. There is no need to verify the contents of the snapshot prior to performing the restore. If this is the case, you can follow the following steps. (Please read all of the steps prior to performing any of them to make sure this is what you need to do.)
- Clone your existing Master DB server
- Rename it something descriptive so you can distinguish it from other Servers. (e.g. Clone Master DB)
- Make sure that its Input, INIT_SLAVE_AT_BOOT = false
- You must edit the following Inputs in accord with the machine tags of the Snapshot you will restore from (Important! Use machine tag information not Snapshot name information.)
- If and only if the value for DB_EBS_PREFIX (e.g. if your snapshot is named 'my-prefix-slave-201106140340' the prefix is 'my-prefix-slave') is not correct, use the DB_RESTORE_PREFIX_OVERRIDE and set it to the rs_backup:lineage tag value. For example, if the Snapshot you want to restore has the following tag setting "rs_backup:lineage=mystripe", then set DB_RESTORE_PREFIX_OVERRIDE to "mystripe". (If DB_EBS_PREFIX is correct, "mystripe" in our example, then leave the override setting as "ignore". There is no need to override the lineage while restoring.)
- Set the OPT_DB_RESTORE_TIMESTAMP_OVERRIDE to the rs_backup:timestamp machine tag of the correct Snapshot you are restoring from. For example, if the tag is rs_backup:timestamp=1303852171 then you would set the timestamp override to "130385217" This setting uses Epoch time and will be unique.
-
Note: Leave the OPT_DB_RESTORE_VERSION_CHECKING set to "yes". Rarely (if ever) will you need to change this setting. (Only if you are migrating between version 5.0 and 5.1 databases.)
- Launch the Server (new master)
- Once operational, run the "DB EBS Restore and become Master" operational RightScript
- At the end of this RightScript a backup should have been for you
- Check progress from the Events pane
- Confirm completion from : Clouds -> CloudName -> EBS Snapshots. The current snapshot should progress from "pending" to "completed 100%"
- Note: If needed, you can take a "manual" backup. To do so run the "DB EBS Backup" operational RightScript
- When the backup has successfully completed, Edit Inputs. Remove the "DB_RESTORE_PREFIX_OVERRIDE" value you set earlier.
- Clone the Slave
- Make sure that INIT_SLAVE_AT_BOOT = true
- Launch the Slave
- Make sure the Slave is operational and the Volumes mounted ok. (Clouds -> CloudName -> EBS Volumes. The status should eventually change from "In-use (attaching)" to "In-use (attached)".
- Verify that the Master and Slave are up and running ok. There are several ways you can do this. Such as:
-
Checking Master or Slave Database status
- Verify that manual and/or scheduled snapshots are completing ok
- Check that your front end Servers are up, running and serving your application ok (check from your browser)
-
Important! Name the current Master and Slave DB Servers appropriately. If you fail to do this, confusion will certainly occur! For example, assuming your old master and slave names don't conflict, you could name them: Master DB and Slave DB, or Production Master DB and Production Slave DB.
- Cleanup tasks
- Terminate the old master and slave Servers
- Delete the old master and slave from your Deployment
Important! If, for instance, you end up performing the above steps and restore from a snapshot that is 4 hours old, when you are through, your database will be 4 hours old. That is, any and all updates after that snapshot will have been lost. Again, it is important to understand exactly what you need and why before restoring from a previous database backup.
Scenario 2 - Restore to a standalone database Server first
In this scenario, you may not know with complete certainty which snapshot you need to restore from. Hence, to find out you spin up a standalone database Server to restore what snapshot you think is correct and check the database to verify the database contents. (Please read all of the steps prior to performing any of them to make sure this is what you need to do.) When you have successfully completed all of these steps, you should have located the appropriate database snapshot to complete Scenario #1 with.
- Import the latest version of the "MySQL EBS Toolbox" ServerTemplate. (Note: Currently this ServerTemplate is beta, but it is tested and will work fine for this restoration process.)
- Clone your current Master DB Server. On the Clone:
- Verify that the Input INIT_SLAVE_AT_BOOT = false
-
Important! Make sure you name it clearly to avoid confusion! For example: TEMP CLONE Master DB
- Launch your temporary Clone DB Server. Once operational, go to its Scripts tab.
- Run the "DB EBS Restore" RightScript
- Expand the the "Any Script" section
- Select the "DB EBS Restore" RightScript from the drop down menu
- Select the "Run Script" action button to execute
- Credentials should be populated correctly for you
- DB_RESTORE_SNAPSHOT - Set this to the Snapshot you think you will want to restore eventually to your live database
- OPT_DB_FORCE_RESTORE - Set this to "false" for the initial run through this process.
- Additional runs through this process have this set to "true"
- If you set this to true, make extra sure you are on the cloned standalone Server! Otherwise, you could change your database on a live production Server. (Not the desired result.)
- SSH into your cloned standalone Server. Connect to the database and manually verify its contents.
- If correct, use this Snapshot and begin Scenario #1 above.
- If the restored Snapshot is not the correct one:
- Repeat the process (Steps 4 & 5 of this Scenario #2)
- This time set OPT_DB_FORCE_RESTORE = true when running the DB EBS Restore RightScript
- Cleanup
- Terminate the temporary standalone database Server
- Delete the temporary standalone database Server