Showing posts with label Restore. Show all posts
Showing posts with label Restore. Show all posts

2015-12-16

Pulling Single DB from Mysqldump's --all-databases backup files

When backing up a MySQL DB, it's often times quick and easy to do a simple:
mysqldump --all-databases --single-transaction | bzip2 > <filename>.sql.bz2

But then someone comes along and asks you "hey, you know that one blog out of 50 that you host? Well, I messed it up and need a restore." You don't want to restore the full dump, but you know you have the data. Here's a quick way to rip out of that file, exactly what you need (after, of course, you extract it from whatever compression you use):

#!/bin/bash
head -n40 $2 | sed -n '/^-- MySQL/,/^-- Current Database:/p'|grep SET > $1-dump.sql
sed -n '/^-- Current Database: `$1`/,/^-- Current Database: `/p' $2 >> $1-dump.sql
$1 = DB Requested
$2 = Input Filename
That script will leave you with a file that has the SET lines before and after the dump, as well as the contents of just the DB you're looking for. Then, just run 'mysql [database_name] < [file_name]' and you'll have your data back to what they wanted!

2014-03-04

Restoring MS SQL Analysis Server Database or Cube with Specific ID

Restoring a MS SQL Database in 2008 and later is really easy, but I recently found that it won't always result in the Database having the ID you want it to. In my case, I needed to restore the database next to one that already existed. Upon doing so, it automatically changed the ID of the database to match that of the name I gave it. This is nice, but not what I wanted. I have a lot of jobs that refer to the database by it's ID, and you can't change an ID once it's in place. Furthermore, the restore dialog doesn't give you the option to specify your ID either, however, the Script button does... XMLA Scripts to the rescue!

Step Through It

  1. Open up Management Studio
  2. Connect to your Analysis Services Server
  3. Right Click on the Databases and hit "Restore..."
  4. When the Restore window comes up, fill in as much info as you can, but instead of hitting "OK", hit the "Script" button at the top. A new script will open behind your window. Close the window and go to the script, it should look something like this.
<Restore xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
  <File>\\Gibson\Awesome\AnalysisServices\Awesome_Data\Awesome_Data_20140201030032.abf</File>
  <DatabaseName>Awesome Data New</DatabaseName>
 <DatabaseID>Awesome ID</DatabaseID>
  <AllowOverwrite>true</AllowOverwrite>
</Restore>

Finally, Add that DatabaseID line and Hit F5 to run the restore!

When it's done you should have a newly restored Cube/Database, with the ID you were hoping for!