Restore Analysis Services database using Windows PowerShell and SQL Server 2008 AMO – Database Journal

Restore Analysis Services database using Windows PowerShell and SQL Server 2008 AMO – Database Journal

(“Microsoft.AnalysisServices”) >$NULL
$server = New-Object Microsoft.AnalysisServices.Server
$server.connect(“PowerServer3SQL2008”)
Note:
PowerServer3 is the hostname and SQL2008 is the Analysis Service instance name.
We now know the different options available in the restore method. You can
see the value information from the restore method. [Refer Figure 1.2]

$server.restore

Click for larger image
You can see the value information from the restore method.

Figure 1.2
From the
above cmdlet’s output, we see the following options are available for restoring
the Analysis Service database. Each option has different uses.
The above
cmdlet basically used the method shown below.


System.Void Restore(RestoreInfo restoreInfo)

All the
available restore methods are listed below.


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)

We need one more library for restoring the database since we protected the database backup with a password. So let’s execute the following cmdlets as shown below. [Refer Figure 1.3]

$security= New-Object Microsoft.AnalysisServices.RestoreSecurity
$security.value__ = 1

Now let’s restore the database “c:backupAdvent2008_2.abf” using one of the above listed restore methods. [Refer Figure 1.4]


$server.restore(“c:backupAdvent2008_2.abf”,”Adventure Works 2008 DW”, $true,$NULL,$Security,”ABC123″)

restore the database

Figure 1.4
The above
command restored the “Adventure Works 2008 DW” database from the “C:BackupAdvent2008_2.abf”
file. In the above example, we used the following method to restore it.


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

We could
restore the same database file with a different database name–say “Adventure
Works 2008 -2” using the same method. [Refer Figure
1.5]

[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.AnalysisServices”) >$NULL
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.AnalysisServices.Security”) >$NULL

$server = New-Object Microsoft.AnalysisServices.Server
$location= New-Object Microsoft.AnalysisServices.RestoreLocation
$security= New-Object Microsoft.AnalysisServices.RestoreSecurity
$server.connect(“PowerServer3SQL2008”)
$security.value__ = 1
$server.restore(“c:backupAdvent2008_2.abf”,”Adventure Works 2008 -2 “, $true,$NULL,$Security,”ABC123”)

restore the same database file with a different database name

Figure 1.5
Launch
SQL Server Management Studio to see that the database has been restored with
the new name. [Refer Figure 1.6]
Launch SQL Server Management Studio

Figure 1.6
If we want
to restore the database backup file “Advent2008_2.abf” and move the database
storage location to a different folder rather than the default folder when
restoring, then we can use the method shown below.


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

Let’s
restore the database backup file “Advent2008_2.abf” as “Adventure Works 2008 -3” using the above method. Here we are going to change the
Database location to E:Data. [Refer Figure 1.7]

 [System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.AnalysisServices”) >$NULL
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.AnalysisServices.Security”) >$NULL
$server = New-Object Microsoft.AnalysisServices.Server
$location= New-Object Microsoft.AnalysisServices.RestoreLocation
$security= New-Object Microsoft.AnalysisServices.RestoreSecurity
$server.connect(“PowerServer3SQL2008”)
$security.value__ = 1
$server.restore(“c:backupAdvent2008_2.abf”,”Adventure Works 2008 -3″, $true,$NULL,$Security,”ABC123″,”E:Data”)

change the Database location

Figure 1.7
After restoring,
you see the database “Adventure Works 2008 -3” appear in SQL Server Management Studio. [Refer Figure
1.8.]
Notice
that the Data files are restored to a new Database Storage location E:dataAdventure
Works 2008 -3.3.db folder. [Refer Figure 1.8 and 1.9]

Figure 1.8
Notice that the Data files are restored to a new Database Storage location

Figure 1.9
Part 7 of
this article series has illustrated how to restore an Analysis Service Database
from a database backup file with password protection. It also illustrated how
to change the default database storage location to a new database storage location
when restoring.
»


See All Articles by Columnist
MAK



Subscribe to Cloud Insider for top news, trends & analysis
DatabaseJournal.com publishes relevant, up-to-date and pragmatic articles on the use of database hardware and management tools and serves as a forum for professional knowledge about proprietary, open source and cloud-based databases--foundational technology for all IT systems. We publish insightful articles about new products, best practices and trends; readers help each other out on various database questions and problems. Database management systems (DBMS) and database security processes are also key areas of focus at DatabaseJournal.com.
Advertise with TechnologyAdvice on Database Journal and our other IT-focused platforms.
Property of TechnologyAdvice.
© 2022 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.

source