copy-sqldatabase - REQ for "-onlyrestore" switch. #661

Open
mbourgon opened this Issue Feb 6, 2017 · 0 comments

Projects

None yet

2 participants

@mbourgon
mbourgon commented Feb 6, 2017

Is this a feature OR bug:

feature

System Details

  • Operating system name and version:
  • Output from $PSVersionTable:
Name                           Value                                                                                           
----                           -----                                                                                           
PSVersion                      3.0                                                                                             
WSManStackVersion              3.0                                                                                             
SerializationVersion           1.1.0.1                                                                                         
CLRVersion                     4.0.30319.42000                                                                                 
BuildVersion                   6.2.9200.16481                                                                                  
PSCompatibleVersions           {1.0, 2.0, 3.0}                                                                                 
PSRemotingProtocolVersion      2.2                                                                                             

  • Output of dbatools version:
0.8.702                       (should be today's dev branch, unless I'm doing it wrong)                                                                                                 
  • SQL Server version for source/target
    2012 / 2016

Steps to Reproduce

copy-sqldatabase -source db-01 -destination db-12 -database myreports -backuprestore -networkshare \db-12\t$\sql_migrations -withreplace -verbose

I was trying to do a -backuprestore. It failed because Intellisense hopped into the database while it was doing the backup, so it spent the several minutes making the backup, but then died during the restore. I would like a -restoreonly option, where it would scan the -networkshare folder for an existing backup and use that rather than take a new backup. It would also allow me to use my already-taken nightly backups, rather than make a fresh one.

Action Results

2/6/2017 1:43:21 PM
C:\temp\dbatools\dbatools-development\functions\Copy-SqlDatabase.ps1
At C:\temp\dbatools\dbatools-development\functions\Copy-SqlDatabase.ps1:457 char:5

  •             $restore.sqlrestore($server)
    
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    

System.Management.Automation.MethodInvocationException: Exception calling "SqlRestore" with "1" argument(s): "Restore failed for Server 'mem-pr-db-12'. " ---> Microsoft.SqlServer.Management.Smo.FailedOperationException: Restore failed for Server 'db-12'. ---> Microsoft.SqlServer.Management.Smo.SmoException: System.Data.SqlClient.SqlError: Exclusive access could not be obtained because the database is in use.

Expected Results

Using the -restoreonly flag would have allowed me to reuse the backups from S:\sql_migrations, rather than take a new one.

Attached Logs or any exception errors

  • Use of Start-Transcript can help collection of console output and exceptions
  • Certain commands will generate an exception log that you can find in following directory: dir $env:USERPROFILE\Documents\dbatools-exceptions.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment