Restoring SQL DB to another SQL Instance

Hello. I try automate restoring SQL DB for test environment.
I get existed script from Technet Gallery and adapted him for my conditions.
Look it
Param(
[string]$DPMServer ="dpmserver",
[string]$ProtectionGroupName = "GroupName",
[string]$SourceServerName = "SourceServer",
[string]$DestinationServerName = "DestServer",
[string]$DestinationInstanceName = "DestServer\InstanceName",
[string]$SQLDatabaseName = "DBName",
[string]$DestinationPath = "E:\Data\")
Import-Module DataProtectionManager
$conn = Connect-DPMServer $DPMServer
if ($conn) {
$ProtectionGroupSQLObj = Get-ProtectionGroup $DPMServer | Where-Object { $_.FriendlyName -eq $ProtectionGroupName}
$DataSourceSQLObj = Get-DataSource -ProtectionGroup $ProtectionGroupSQLObj | Where-Object { $_.Name -eq $SQLDatabaseName -and $_.Instance -eq $SourceServerName}
if ($DataSourceSQLObj -ne $null) {
$SQLDatabases = [Microsoft.Internal.EnterpriseStorage.Dls.UI.ObjectModel.SQL.SQLDataSource]$DataSourceSQLObj;
$RecoveryPointsSQLObj = Get-Recoverypoint -DataSource $SQLDatabases | Where-Object { $_.HasFastRecoveryMarker -eq "Fast" -and $_.IsRecoverable -and $_.Location -eq "Disk"} | Sort-Object BackupTime -Desc;
If ($RecoveryPointsSQLObj.Count) #Check More Than 1 RP Is Returned
$RecoveryPointToRestore = $RecoveryPointsSQLObj[0]; #Get The Latest RP (1st In List)
Else #If Only 1 RP Is Returned
$RecoveryPointToRestore = $RecoveryPointsSQLObj;
$length = $RecoveryPointToRestore.PhysicalPath.Length
$AlternativeDatabaseObj = New-Object -TypeName Microsoft.Internal.EnterpriseStorage.Dls.UI.ObjectModel.SQL.AlternateDatabaseDetailsType
$LocationMapping = New-Object Microsoft.Internal.EnterpriseStorage.Dls.UI.ObjectModel.SQL.FileLocationMapping[] $length
$AlternativeDatabaseObj.LocationMapping = $LocationMapping
$i = 0
While($i -lt $length) #Perform The While Loop While $i Is Less Than The Number Of Files To Restore ($length). Add The Crrent File Names And Locations For Each File To Be Restored
$AlternativeDatabaseObj.LocationMapping[$i] = New-Object -TypeName Microsoft.Internal.EnterpriseStorage.Dls.UI.ObjectModel.SQL.FileLocationMapping; #Create The Object
$AlternativeDatabaseObj.LocationMapping[$i].FileName = $RecoveryPointToRestore.FileSpecifications[$i].FileSpecification; #Set File Name For Files
$AlternativeDatabaseObj.LocationMapping[$i].SourceLocation = [Microsoft.Internal.EnterpriseStorage.Dls.UI.ObjectModel.OMCommon.PathHelper]::GetParentDirectory($RecoveryPointToRestore.PhysicalPath[$i]); #Set Source Location (Path) For Files
If ($AlternativeDatabaseObj.LocationMapping[$i].FileName.ToLower().EndsWith(".ldf")) #If LDF File Set Destination Location As $DestinationLDFPath
$AlternativeDatabaseObj.LocationMapping[$i].DestinationLocation = $DestinationPath
Else #If MDF File Set Destination Location As $DestinationMDFPath
$AlternativeDatabaseObj.LocationMapping[$i].DestinationLocation = $DestinationPath
$i++; #Increment Counter (Move Onto Next File)
$AlternativeDatabaseObj.InstanceName = $DestinationInstanceName; #Set Destination Server Name. If Restoring To Named Instance Include The Instance Name
$AlternativeDatabaseObj.DatabaseName = $SQLDatabaseName; #Set Destination DB Name
$ROP = New-RecoveryOption -TargetServer $DestinationServerName -SQL -RecoveryLocation OriginalServer -RecoveryType Recover -AlternateDatabaseDetails $AlternativeDatabaseObj -Verbose
$RestoreJob = Restore-DPMRecoverableItem -RecoverableItem $RecoveryPointToRestore -RecoveryOption $ROP -Verbose
$Wait = 2; #Initial Wait Time
While ($RestoreJob -ne $null -and $RestoreJob.HasCompleted -eq $false)
Start-Sleep -Seconds $Wait;
$Wait = 20;
$RestoreJob
The problem is that the
script only recovers
files, but
not the DB.
When I recover this DB from DPM Console, the DB is attached to SQL Server, but don't when I run my script. Application Logs and SQL Server Logs empty.
Somebody can
tell me what my problem
is?

Hi,
Here is the steps to manually backup and restore SQL database:
https://technet.microsoft.com/en-us/library/jj244601.aspx#BKMK_Secondary
For the script related topic you post to this forum:
https://social.technet.microsoft.com/Forums/scriptcenter/en-US/home?forum=ITCG
Please remember to mark the replies as answers if they help and un-mark them if they provide no help. If you have feedback for TechNet Support, contact [email protected]

Similar Messages

  • Moving the DPM 2012 SQL Database to another SQL Server

    I have 2 DPM Servers running and I would like to move those SQL Dbs onto another SQL Server. I know during the install you can select whether or not you want to install SQL or use another instance, but I dont want to re-install the whole thing and start
    over. Is there any easy way to do this?

    Hi,
    in my opinion, you can stop with this Walkthrough after step 6, dont think that you Need to do a sync or consistency check.
    Seidl Michael | http://www.techguy.at | twitter.com/techguyat |
    facebook.com/techguyat |
    youtube.com/techguyat

  • Data transfer from one sql server to another sql server in 2005

    Hi,
    Im trying to transfer only one table data from one server database  to another server   database table.both are in 2005 .Can anyone help?

    Hi,
    Im trying to transfer only one table data from one server database  to another server   database table.both are in 2005 .Can anyone help?
    If you are not using express you can use Import export wizard to mode data its very easy below link will help.In link destination is excel but you can select destination as your SQL Server
    http://www.mssqltips.com/sqlservertutorial/202/simple-way-to-export-data-from-sql-server/
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers

  • Moving Physical SQL Cluster into Virtual SQL Cluster based on Hyper-V Failover

    Hello All............I have a SQL Cluster based on Physical Hardware that has Three-3 instances as well. I have setup a Hyper-V Failover Cluster (2012 R2) and have built Virtual/Guest SQL Cluster (2012 R2) upon it.  Now, I intend to move
    the instances/databases from Physical SQL Cluster to Virtual SQL Cluster.
    1.  Is this supported?  If so, I would appreciate any guidance on it?
    2.  Is P2V of SQL Cluster supported in Hyper-V Failover Cluster based on Windows Server 2012 R2?

    Hi Sir,
    Please refer to the following blog regarding moving SCCVM SQL database to another SQL server:
    http://blogs.technet.com/b/configurationmgr/archive/2013/04/02/how-to-move-the-configmgr-2012-site-database-to-a-new-sql-server.aspx
    It is quoted from the  similar thread :
    https://social.technet.microsoft.com/Forums/en-US/a1558842-cdf5-4e5f-8f10-d660e96eae1b/migration-sql-for-sccm-2012?forum=configmanagermigration
    But it seems that is a migration of system center production , I would suggest you to post the question to system center forum :
    https://social.technet.microsoft.com/Forums/en-US/home?forum=configmanagermigration%2Coperationsmanagergeneral&filter=alltypes&sort=lastpostdesc
    Best Regards,
    Elton Ji
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Migrate SharePoint's SQL Server (physical) to another SQL Server (virtual server)

    Infrastructure team is migrating domain\SQLSERVER db to new ‘XYZ’ Location.  Also they are moving these DBs to virtual server. Currently these are physical DB servers.
    I am trying to keep the server names as same ‘SQLSERVER ‘, but IP address may change. Does it have any impact on MOSS environment and what configuration changes need to be done, if needed???
    Note: -  i am using alias  for my share point 2010 server . 
    SERVER INFO
    2 WEB SERVER , 1 APPS SERVER
    NINTEX Workflow Database without Sql "Alias"
    No any Customization only 2 site colleciton with Nintex workflow.

    You can move all content databases to another SQL server, but moving Configuration DB will have impact on the farm. You can make it work using SQL Alias created on SP server using cliconfg.exe utility but some of the services will break on your farm. As
    far as I know It is not recommended to move config db from one sql server to another.
    You can check below link for referrence on moving databases from one sql to another sql:
    http://technet.microsoft.com/en-us/library/cc512725(v=office.12).aspx
    http://blogs.msdn.com/b/shaden/archive/2007/07/05/moving-the-sharepoint-databases-to-a-new-sql-server-instance.aspx
    Please ensure that you mark a question as Answered once you receive a satisfactory response.

  • Connect to another SQL server from SAP

    Hi All,
    I want to connect SAP to another SQL server. Basically each day I need to take data from 2 tables in SAP tables to another sql server. I want this to be automated via a program in SAP.
    Please suggest me some methods to achieve this.
    I have searched the web and found that this is possiable, some transactions such as DBCO was mentioned, but it was not much helpful.
    Thanks a lot.
    Regards,
    Pankaj

    Moderator message - Cross post locked
    Rob

  • Why is my Package just stopping when going from one Execute SQL Task to another Execute SQL Task

    I have one flow constraint going for my one Execute SQL Task to another Execute SQL Task. It's executing #1 and successfully and just stops there rather than continuing on to Execute SQL Task #2. Why would it just stop? My constraint is NOT conditional...just
    a straight ole flow constraint.
    Any help is greatly appreciated and Thanks in Advance for your help.
    PSULionRP

    Hi PSULionRP,
    First make sure the color of the Precedence Constraint is green (Success) or blue (Completion) other than red (Failure). Then, make sure the Execute SQL Task is not disabled (right click the executable, and “Disable” option is available in the right-click
    menu). 
    Regards,
    Mike Yin
    TechNet Community Support

  • How do I set up Azure Sql Server to have multiple instances?

    Hi all;
    We are setting up a new SAAS application on Azure and while we have used Azure before, not at this level of multiple apps, etc.
    We plan to have both a web app and a cloud app in both a US and EU data center. They need to hit a common database because requests will go to the closest data center via traffic manager and a lot of the data works off of the customer table. And a customer
    (company) can have users in both the U.S. and E.U.
    Is there a way to set up Azure Sql Server so it has instances in both data centers, and Azure keeps them synchronized? If I understand sharding right, that is not what we need as someone hitting either data center could be requesting any of the data in the
    DB.
    thanks - dave
    What we did for the last 6 months -
    Made the world's coolest reporting & docgen system even more amazing

    Hi,
    As far as I am aware, when you set the webapp/cloudapp to connect to a database you will have to specify the connection string in the app. The app will hit the database which is mentioned in the  connection string you have specified. So it is not automatic
    or Traffic manager. You have full control over it as you can tell your app to connect whichever database you want.The database could be located in any region, however the you have to keep latency in mind as the app in US Datacenter could be calling the Database
    in EU, if that is  they way it is setup.
    You can have separate databases in each region and use Azure Data Sync
    to have the database synchronized, however please keep in mind that Azure Data Sync is in Preview.
    Regards,
    Mekh.

  • Another SQL Developer bug - End of file in comment

    I found another SQL Developer bug in version 3.0.0.4.
    If I try to compile some package from file (so I open file with package body in SQL Developer and assign it to some connection) with this kind of comment: /* comment */ behind end of package, I get this error
    I got Error(1250,28): PLS-00111: end-of-file in commentFunny is, that when the package is compiled directly from the database - it works.
    When I try to compile the package from file with this kind of comment --comment behind the end of package, it also works...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Hi, I think I finally got it. This looks like an ugly fat bug :)
    First, we are not using the .sql extensions. For package specification - we use .pks. For package body - we use .pkb.
    Create this script:
    CREATE OR REPLACE PACKAGE TEST_xxx AS
    PROCEDURE TEST_PROCEDURE;
    END TEST_xxx; /*0123456789*/Now save this as e.g. "TEST.pks" file. Open this file in SQL Developer and compile it. You will get the "Error(3,27): PLS-00111: end-of-file in comment".
    Now look at the result in the database -> Open the package specification from the database and you see this:
    create or replace
    PACKAGE TEST_xxx AS
    PROCEDURE TEST_PROCEDURE;
    END TEST_xxx; /*0123456789*The last slash is missing...
    Now go back to the file with the package specification and delete one letter from the comment. Compile it again... it works now.
    It looks like the length of this kind of comment is limited to 9 characters.
    The limitation is there only when:
    1) Compiling from file with different extension than .sql !!! If you rename the file to "TEST.sql", SQL Developer opens it as a script file and runs it as a script, so there is no problem with it.
    2) It has to be this kind of comment: /* */. One line comments are not limited.

  • How to restore the Password backup in sql server 2005

    How to restore the Password backup in sql server 2005

    Hello,
    THANKS............ BUT
    I executed this query 
    RESTORE DATABASE new_data1
    FROM DISK = 'd:\UK_DETAILS.bak'
    with password ='selfinity123'
    WITH MOVE 'UK_DETAILS.bak' TO 'D:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\new_data1.mdf',
    MOVE 'UK_DETAILS.bak' TO 'D:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\new_data1.ldf'
    I got the error 
    Msg 319, Level 15, State 1, Line 4
    Incorrect syntax near the keyword 'with'. If this statement is a common table expression or an xmlnamespaces clause, the previous statement must be terminated with a semicolon.

  • JDBC - MS SQL Server 2005 with multible instances

    I want to get data from a Microsoft SQL Server via JDBC. We have such a scenario and till now it works fine. Now we have a second instance at the sql server and we want to connect to this instance. I've found the following MSD article:
    http://msdn2.microsoft.com/en-us/library/ms378428.aspx
    <b>SQL Server 2000 and SQL Server 2005 allow for the installation of multiple database instances per server. Each instance is identified by a specific name. To connect to a named instance of SQL Server, you can either specify the port number of the named instance (preferred), or you can specify the instance name as a JDBC URL property or a datasource property. If no instance name or port number property is specified, a connection to the default instance is created. See the following examples:
    To use a port number, do the following:
    jdbc:sqlserver://localhost:1433;integratedSecurity=true;<more properties as required>;
    To use a JDBC URL property, do the following:
    jdbc:sqlserver://localhost;instanceName=instance1;integratedSecurity=true;<more properties as required>;</b>
    Because the named instance has no explicit port  I've tried to use the second one but this doesn't work. I've tried all possible combinations of these parameters but either I get an error or my adapter connects to the first instance
    Any idea how I can connect to the second named instance?

    We have also a SQL server 2000 instance at the same server. Yesterday I have spoken with the sql server admin and he told me that he has disconnect the sql server 2000 databases whatever this means. :-D
    Now all works fine. Thank you for your help
    BTW I use the following connection string:
    jdbc:sqlserver://my_db_server;instanceName=my_instance_name;DatabaseName=my_db_name

  • I am trying connect to a SQL instance for our CRM program and I am receiving To Connect to this Server you must use SQL Management Studio or SQL Server Management

    I am trying connect to a SQL instance for our CRM program and I am receiving To Connect to this Server you must use SQL Management Studio or SQL Server Management 
    This is a Brand new Server 2012 that is running our CRM product and it is trying to connect to a Server 2008 R2 server with SQL Server 2008 R2 SP2 instance (10.50.4000)
    I have seen this in the past where it needed the 2005 backwards compatibility components installed but those are not supported on 2012 server and this is not a 2005 SQL instance.
    I am trying to install the Shared Management Objects for SQL Server 2008 but it tells me I need to install the CLR types, which I did install. But it continues to tell me to install the CLR types.
    Has anyone ran into any issues like this? (this happens trying to connect to multiple SQL Servers from this new 2012 Server)
    Thanks!
    -Max

    Hello,
    Which version and edition of the SQL Server instance did you installed on the new server machine?  If you install SQL Server 2012 Express edition, you can try to install SQL Server Management Studio 2012 from
    this link.
    You can connect to SQL Server 2008 R2 or earily verions with SSMS 2012.
    What's more, Microsoft SQL Server 2008 Management Objects Collection requires Microsoft Core XML Services (MSXML) 6.0, Microsoft SQL Server Native Client, and Microsoft SQL Server System CLR Types. You can try to download and install
    SQL Serve 2008 Feature Pack
    which contains packages above.
    Regards,
    Fanny Liu
    Fanny Liu
    TechNet Community Support

  • SQL Server Analysis Services (PowerPivot) instance returned the following error:

    SQL Server Analysis Services (PowerPivot) instance returned the following error: Error Code: 3241607174 Description: A connection corresponding to the embedded PowerPivot data was not found in the
    Excel workbook, file 'C:\Program Files\Microsoft SQL Server\MSAS10_50.POWERPIVOT\OLAP\Backup\Sandboxes\PowerPivotServiceApplication1\ReadOnlyExclusive-1096b00b-c487-46f9-afea-f717148863a8-Test_Sheet.xlsx'
    Hi Have Installed power pivot to and exsistinf farm standalone farm.
    What Should be the connection in the Excel fiile?
    Thanks
    Ravi
    Ravi

    Hi,
    According to your post, my understanding is that  you got an error with SQL Server Analysis Services.
    Did you have installed PowerPivot for Excel on a client machine and modeled a database as part of this workbook?
    The refresh in question is about refreshing the embedded Analysis Services database with data retrieved from the backend sources (defined when the database was originally modeled) and resaving the updated workbook. It should not be confused
    with Excel / Excel Services options to refresh the data connections in the workbook. That option is about refreshing data stored in Excel’s caches. With regards to PowerPivot, that would be refreshing from the embedded database, not the backend data from which
    the database was sourced. In summary, this feature will not work against a workbook which does not have an embedded database because there is no database to refresh. This is by design and should not be interpreted as indicating that there is something wrong
    with your system.
    More information:
    http://powerpivotgeek.com/2010/02/07/a-connection-corresponding-to-the-embedded-powerpivot-data-was-not-found-in-the-excel-workbook/
    There are some similar articles for your reference.
    http://technet.microsoft.com/en-us/library/ee210712(v=sql.105).aspx
    http://support.microsoft.com/kb/2761246
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/a324436c-9901-494e-9f9b-314399d65ccb/data-refresh-dont-work-for-serverhealthxlsx
    For the error “The data connection uses Windows Authentication and user credentials could not be delegated. The following connections failed to refresh”.
    There are multiple causes for this error message. The common factor behind all of them is that Excel Services cannot get a valid Windows user identity from a claims token in SharePoint.
    For more information:
    http://technet.microsoft.com/en-us/library/ff487975.aspx
    http://mmman.itgroove.net/2013/03/the-data-connection-uses-windows-authentication-and-user-credentials-could-not-be-delegated/
    Thanks & Regards,
    Jason
    Jason Guo
    TechNet Community Support

  • What is the recommended static port range for SQL Server 2008 to SQL Server 2014 named instance?

    I want to assign a static port to SQL Server 2008 to SQL Server 2014 named instance.   Should the port be greater than 49151?  The following links give contradicting information:
    https://msdn.microsoft.com/en-us/library/ms177440(v=sql.105).aspx
    Avoid numbers greater than 49151 which Windows might select for other purposes.
    https://technet.microsoft.com/en-us/library/ms345327(v=sql.100).aspx
    Port numbers should be assigned from numbers 49152 through 65535
    Thanks..

    I would still pick a port number below the ephemeral list (dynamic port usage [41952-65535]) as it'll reduce the chances of having a port collision when SQL Server starts up.
    Also, I'd stick to lower numbers if possible (<25,000) as some firewalls skew higher port numbers to be more malicious (if heuristics are used).
    -Sean
    The views, opinions, and posts do not reflect those of my company and are solely my own. No warranty, service, or results are expressed or implied.

  • Restore MySQL database file into SQL server

    Hi experts,
    I have a MySQL Server backup file. How can I restore it to SQL Server?
    Or what is the way around getting the database into SQL Server?
    ebro

    Hi experts,
    I have a MySQL Server backup file. How can I restore it to SQL Server?
    Or what is the way around getting the database into SQL Server?
    ebro
    You cannot restore MySQL backup file on SQL Server.
    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it.
    My TechNet Wiki Articles

Maybe you are looking for

  • Module pool help needed

    Please use a more informative subject in future hi Experts In my module pool program i having a list box in a modeled dialog box . if the list box is left empty it will give an error message .after pressing the enter buttton the list box gets disable

  • Hard drive crash...want to restore play counts from ipod.

    My hard drive crashed and obviously I lost all of my iTunes library stuff.  I have all of my song files on an external hard drive so that is not the issue.  What I want is to restore my library including play counts and all of that.  My ipod touch is

  • Is domain installation mandatory?

    Hello Guys, Is Domain installation of an SAP system mandatory for it to connect to an Active directory? Thanks and Regards, Ankit Mishra

  • Catalog SC error

    Experts, We are on SRM7/ECC6 (Ext classic) When we are creating a shopping cart from one of the vendor catalogs, we are getting following errors 1. Error occured calling META_BAPI_DISPATCH (I don't get this error while shopping otherwise, but only wh

  • EA4500 - Filter Guest Network Access

    Is there a way to filter guest network to restrict what services they can access? Support won't email me back.