Quantcast
Channel: SQL Server Analysis Services forum
Viewing all articles
Browse latest Browse all 14337

Retore database using sql cmd

$
0
0

I have a machine installed with SQL2012 enterprise and default sql instance with analysis services.

The operation is that I need to restore database from a xxxxxx.abf file.(Server is localhost).

Manually, I can open the management studio and choose analysis services then type local host and then restore from the file provided.

I've seen some examples like

@echo off

set backfile=%~dp0

set pathsqlserver2008=%ProgramFiles%\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA
set pathsqlserver2008r2=%ProgramFiles%\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA
set pathsqlserver2012=%ProgramFiles%\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA

set sqlcmdpath="%ProgramFiles%\Microsoft SQL Server\100\Tools\Binn\sqlcmd.exe"
if not exist %sqlcmdpath% (
set sqlcmdpath="%ProgramFiles%\Microsoft SQL Server\110\Tools\Binn\sqlcmd.exe" )


@echo Close all connections to database NLayerAppV2
%sqlcmdpath% -E -S .\ -Q "ALTER DATABASE [DBForTest01] SET OFFLINE WITH ROLLBACK IMMEDIATE"
%sqlcmdpath% -E -S .\ -Q "ALTER DATABASE [DBForTest01] SET ONLINE"

@echo Close all connections to database NLayerAppV2.Tests
%sqlcmdpath% -E -S .\ -Q "ALTER DATABASE [DBForTest02] SET OFFLINE WITH ROLLBACK IMMEDIATE"
%sqlcmdpath% -E -S .\ -Q "ALTER DATABASE [DBForTest02] SET ONLINE"


@echo Get Sql Server Version
%sqlcmdpath% -E -S .\ -Q "SET NOCOUNT ON;select SUBSTRING(CONVERT(varchar(20),SERVERPROPERTY('productversion')),1,4)"  -h-1 -o temp.txt
set /p sqlversion=<temp.txt
@echo %sqlversion%


@echo Restore database DBForTest01
if /i "%sqlversion%"=="10.0" (
%sqlcmdpath% -E -S .\ -Q "RESTORE DATABASE [DBForTest01] FROM  DISK = N'%backfile%\DBForTest01.bak' WITH  FILE = 1,  MOVE N'DBForTest01' TO N'%pathsqlserver2008%\DBForTest01.mdf',  MOVE N'DBForTest01_Log' TO N'%pathsqlserver2008%\DBForTest01_Log.LDF',  NOUNLOAD,  REPLACE,  STATS = 10")

 if /i "%sqlversion%"=="10.5" (
%sqlcmdpath% -E -S .\ -Q "RESTORE DATABASE [DBForTest01] FROM  DISK = N'%backfile%\DBForTest01.bak' WITH  FILE = 1,  MOVE N'DBForTest01' TO N'%pathsqlserver2008r2%\DBForTest01.mdf',  MOVE N'DBForTest01_Log' TO N'%pathsqlserver2008r2%\DBForTest01_Log.LDF',  NOUNLOAD,  REPLACE,  STATS = 10")

 if /i "%sqlversion%"=="11.0" (
%sqlcmdpath% -E -S .\ -Q "RESTORE DATABASE [DBForTest01] FROM  DISK = N'%backfile%\DBForTest01.bak' WITH  FILE = 1,  MOVE N'DBForTest01' TO N'%pathsqlserver2012%\DBForTest01.mdf',  MOVE N'DBForTest01_Log' TO N'%pathsqlserver2012%\DBForTest01_Log.LDF',  NOUNLOAD,  REPLACE,  STATS = 10")

Q:

A.

What does "set backfile=%~dp0" means? Is %~dp0 some location that recognized path by SQL server?

B.

%sqlcmdpath% -E -S .\ -Q "RESTORE DATABASE [DBForTest01] FROM  DISK = N'%backfile%\DBForTest01.bak' WITH  FILE = 1,  MOVE N'DBForTest01' TO N'%pathsqlserver2012%\DBForTest01.mdf',  MOVE N'DBForTest01_Log' TO N'%pathsqlserver2012%\DBForTest01_Log.LDF',  NOUNLOAD,  REPLACE,  STATS = 10")

If I paste the file (xxxxxx.abf) to MSSQLSERVER\OLAP\DATA, should this command be like this

%sqlcmdpath% -E -S .\ -Q "RESTORE DATABASE [XXXXXX] FROM  DISK = N'%backfile%\XXXXXX.abf' WITH  FILE = 1,  MOVE N'XXXXXX' TO N'%pathsqlserver2012%\XXXXXX.mdf',  MOVE N'XXXXXX_Log' TO N'%pathsqlserver2012%\XXXXXX_Log.LDF',  NOUNLOAD,  REPLACE,  STATS = 10")

And what does "NOUNLOAD,REPLACE, STATS =10" mean ?

C.

How should I type these lines so that the server type is using analysis services?

Thanks in advance.




Viewing all articles
Browse latest Browse all 14337

Trending Articles