IF NOT Exist "D:\ETL\APP.bak" GOTO End
copy "D:\ETL\APP.bak" "C:\App_restore\" /y
::SET VARIABLES
set DBNAME=NAMEOFDATABASEBEINGRESTORED
set DBDIRECTORY=C:\Program Files\Microsoft SQL Server\MSSQL\Data
TITLE Restoring Student_Data_Mart Database
::PUT DATABASE IN SINGLE USER MODE TO ALLOW RESTORE
osql -E -d master -Q "alter database App_Business_DB set single_user with rollback immediate"
::RESTORE DATABASE
osql -E -d master -Q "restore database App_Business_DB from disk='C:\App_restore\APP.bak' WITH replace,Move 'App_Business_Profile' TO 'C:\SQL_DATA\APPSDB\App_Business_Profile.mdf', MOVE 'App_Business_Profile_Log' TO 'C:\SQL_DATA\APPSDB\App_Business_Profile_2.ldf'"
::GRANT PERMISSION TO ASPNET USER
osql -E -d App_Business_DB -Q "sp_grantdbaccess 'business\svcappbussql'"
osql -E -d App_Business_DB -Q "sp_addrolemember 'db_owner', 'business\svcappbussql'"
::RESTORE TO MULTI USER
osql -E -d master -Q "alter database App_Business_DB set multi_user"
del "C:\App_restore\APP.bak"
del "D:\ETL\APP.bak"
:End
ECHO Finished
|