Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Links Database Forum

» Database Journal Home
» Database Articles
» Database Tutorials
MS SQL
Oracle
DB2
MS Access
MySQL
» RESOURCES
Database Tools
SQL Scripts & Samples
Links
» Database Forum
» Sitemap
Free Newsletters:
DatabaseDaily  
News Via RSS Feed


follow us on Twitter
Database Journal |DBA Support |SQLCourse |SQLCourse2
 

Featured Database Articles

MS SQL

Posted Feb 4, 2009

How to Restore an SSAS database using Windows PowerShell and SQL Server 2008 AMO

By Muthusamy Anantha Kumar aka The MAK



Part 1 of this article series “Microsoft Windows PowerShell and SQL Server 2008 AMO” illustrated how to install Windows PowerShell and connect to an Analysis Service Servername. Part 2 illustrated how to use Windows PowerShell and AMO to get the various Server properties of SQL Server Analysis Service. Part 3 discussed how to use Windows PowerShell and AMO to get database properties of SQL Server Analysis Service and Part 4 illustrated how to create Analysis Service Database using Windows PowerShell and AMO. Part V illustrated how to backup an Analysis Service database using Windows PowerShell and SQL Server 2008 AMO. This article illustrates how to restore an Analysis Service database from a backup file.

In “Backing up Analysis Service database using Windows PowerShell and SQL Server 2008 AMO,” we took a backup of the “Adventure Works DW 2008” database, saving it to a file named “Advent2008_1.abf” that had no password protection. We also backed up the “Adventure Works DW 2008” database to a file “Advent2008_2.abf” that did have password protection. Additionally, we took a backup of the “Adventure Works DW 2008” database, to a file “Advent2008_3.abf” that was password protected but was not compressed.

Now let’s try to restore the database “Adventure Works DW 2008” from the file “Advent2008_3.abf”.

Connect to Analysis Server using Windows PowerShell using SQL Server AMO, as shown below. [Refer Figure 1.1]



[System.Reflection.Assembly]::LoadWithPartialName
	("Microsoft.AnalysisServices") >$NULL
$server = New-Object Microsoft.AnalysisServices.Server
$server.connect("PowerServer3\SQL2008")


Note: PowerServer3 is the hostname and SQL2008 is the Analysis Service instance name.

From part V of this article, we know that the backup method is defined under object database. However, the restore method is defined under object Server. Let’s query all of the options available under server object. This can be achieved by using the get-member cmdlet as shown below. Execute the following cmdlet. [Refer Figure 1.2]

$server | get-member -Type methods

Result

Attach
BeginTransaction
CancelCommand
CancelConnection
CancelSession
Clone
CommitTransaction
ConcatenateCaptureLog
Connect
CopyTo
CreateObjRef
Disconnect
Dispose
Drop
EndXmlaRequest
Equals
Execute
ExecuteCaptureLog
GetConnectionState
GetDependents
GetHashCode
GetLastSchemaUpdate
GetLifetimeService
GetReferences
GetType
GetUpdateOverwrites
InitializeLifetimeService
NotifyTableChange
Reconnect
Refresh
Restore
RollbackTransaction
SendXmlaRequest
StartXmlaRequest
Submit
ToString
Update
UpdateObjects
Validate

results of get-member cmdlet
Figure 1.2

Now let’s see all the options available under the method restore. Execute the following cmdlet as shown below. The command displays the information about the restore method. [Refer Figure 1.3]

$server.restore

information about the restore method
Figure 1.3

From the above cmdlet, we see the following options available for restoring Analysis Service database. Each option has different uses.

System.Void Restore(String file), 

System.Void Restore(String file, String databaseName), 

System.Void Restore(String file, String databaseName, Boolean allowOverwrite), 

System.Void Restore(String file, String databaseName, Boolean allowOverwrite, RestoreLocation[] locations), 

System.Void Restore(String file, String databaseName, Boolean allowOverwrite, 
	RestoreLocation[] locations, RestoreSecurity security),

System.Void Restore(String file, String databaseName, Boolean allowOverwrite, 
 	RestoreLocation[] locations, RestoreSecurity security, String password), 

System.Void Restore(String file, String databaseName, Boolean allowOverwrite, RestoreLocation[] locations, 
	RestoreSecurity security, String password, String dbStorageLocation), 

System.Void Restore(RestoreInfo restoreInfo)

Now let’s restore the database “c:\backup\Advent2008_1.abf” using one of the above listed restore methods, as shown below. [Refer Figure 1.4]

$server.restore("c:\backup\Advent2008_1.abf","Adventure Works 2008 DW",$true)

restore the database
Figure 1.4

Note: We used the following method to restore the database.

System.Void Restore(String file, String databaseName, Boolean allowOverwrite)

If you do not use the $true value option in the restore method, you will get the following error complaining that the database by the name “Adventure Works DW 2008” already exists. [Refer Figure 1.5]

Exception calling "Restore" with "2" argument(s): "Backup and restore errors: The 'Adventure Works 2008 DW' object cann
ot be restored because the object already exists. Set the AllowOverwrite setting to True to overwrite the object.
"
At line:1 char:16
+ $server.restore <<<< ("c:\backup\Advent2008_1.abf","Adventure Works 2008 DW")
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Exception calling
Figure 1.5

Next, let’s restore the database backup file Advent2008_1.abf to a database “Adventure Works test”. [Refer Figure 1.6]

We can use the same restore method to restore the Advent2008_1.abf database as a different database.

$server.restore("c:\backup\Advent2008_1.abf","Adventure Works Test",$true)

Note: Here we used the same method to restore the database. However, we changed the database name from “Adventure Works 2008 DW” to “Adventure Works Test”.

System.Void Restore(String file, String databaseName, Boolean allowOverwrite)

$server.restore(
Figure 1.6

Launch SQL Server Management Studio and log on to Analysis Services, as shown below. [Refer Figure 1.7]

Launch SQL Server Management Studio and log on to Analysis Services
Figure 1.7

Note: PowerServer3 is the hostname and SQL2008 is the Analysis Service instance name.

After refreshing the database folder in SQL Server Management Studio, you see that the database “Adventure Works Test” is available. [Refer Figure 1.8]

the database
Figure 1.8

From Figure 1.8, you can see all of the cubes defined in the database “Adventure Works DW 2008” are now available in “Adventure Works Test”.

Conclusion

Part 6 of this series illustrated how to restore an Analysis Service database from a backup file. The next installment will illustrate how to restore an Analysis Service database file with password protection and more.

» See All Articles by Columnist MAK



MS SQL Archives

Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 




Latest Forum Threads
MS SQL Forum
Topic By Replies Updated
SQL 2005: SSIS: Error using SQL Server credentials poverty 3 August 17th, 07:43 AM
Need help changing table contents nkawtg 1 August 17th, 03:02 AM
SQL Server Memory confifuration bhosalenarayan 2 August 14th, 05:33 AM
SQL Server Primary Key and a Unique Key katty.jonh 2 July 25th, 10:36 AM