Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial commit of Move-DbaDatabaseFile (renamed from Move-SqlDatabaseFile) #250

Closed
wants to merge 13 commits into from

Conversation

ClaudioESSilva
Copy link
Collaborator

No description provided.

@ClaudioESSilva ClaudioESSilva changed the title Ready for QA Ready for QA Move-DbaDatabaseFile Oct 8, 2016
@ClaudioESSilva
Copy link
Collaborator Author

In order to resolve this conflict can you please remove the Move-SqlDatabaseFile from development branch?
Thanks!

@potatoqualitee
Copy link
Member

Move-SqlDatabaseFile has been removed per your request, @ClaudioESSilva

@dansqldba dansqldba changed the title Ready for QA Move-DbaDatabaseFile initial commit of Move-DbaDatabaseFile (renamed from Move-SqlDatabaseFile) Oct 10, 2016
@dansqldba dansqldba modified the milestone: October 2016 Release Oct 10, 2016
@potatoqualitee
Copy link
Member

potatoqualitee commented Oct 19, 2016

@ConstantineK do you have an environment where you can test this for @ClaudioESSilva? If so, do you have time this week?

Here is the QA Checklist

  • Working/useful help content, including link to command on dbatools web site
  • All examples work as advertised
  • Does not contain template content
  • Does not contain excessive/unnecessary amounts of comments
  • Works remotely
  • Works locally
  • Works on lower versions or throws error specifying version not supported
  • Works with named instances
  • Works with clustered instances
  • Handles offline/read only databases
  • Supports multiple servers (at the command line or piped from Get-SqlRegisteredServerName)
  • No un-handled errors which stop the command working with multiple servers

@ConstantineK ConstantineK self-assigned this Oct 21, 2016
@ConstantineK
Copy link
Contributor

Just going through the documentation and doing some spelling and grammar checks, and had a note/question:

I think the comment on InputFile may be incorrect.
"This must be specified when using -ExportDatabaseStructure switch."
When I look at the code, I see it is used by the MoveFromCSV switch (and MoveFromCSV) mentions it.

When I look at https://github.com/sqlcollaborative/dbatools/pull/250/files#diff-c7029173690c770eeb46aa4e8c21f664R775 I dont see any dependency on -ExportDatabaseStructure.

Ran through the comments and documentation, changed a bunch of grammar and phrasing to shorten and hopefully simplify some of the explanations. Altered -InputFile fundamentally because I think the explanation may have been copy pasted and not changed. Changed capitalization and period use to be more consistent.
@ClaudioESSilva
Copy link
Collaborator Author

@ConstantineK you're right.
For -InputFile should be "-MoveFromCSV" instead of "-ExportDatabaseStructure".

@ConstantineK
Copy link
Contributor

Test results:
Assume we dont care about ShouldProcess attribute issues
Assume we dont care sabout unapproved verbs in internal functions
If we assume sql 2000, the examples fail

Just a quick question/note: by default, are we saying that not supporting 2000 is a blocker? Just seeing a few issues whenever I run these example commands on a 2000 box I get errors.

  • Example 1 fails on all versions
    Get database file inventory
    Exception calling "ExecuteWithResults" with "1" argument(s): "An exception occurred while executing a 
    Transact-SQL statement or batch."
    At C:\Users\ck\Desktop\dbatools\functions\Move-DbaDatabaseFile.ps1:179 char:4
    +             $dbfiletable = $server.ConnectionContext.ExecuteWithResul ...
    +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : ExecutionFailureException

    Cannot index into a null array.
    At C:\Users\ck\Desktop\dbatools\functions\Move-DbaDatabaseFile.ps1:180 char:4
    +             $ftfiletable = $dbfiletable.Tables[0].Clone()
    +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : NullArray

    Cannot index into a null array.
    At C:\Users\ck\Desktop\dbatools\functions\Move-DbaDatabaseFile.ps1:181 char:4
    +             $dbfiletable.Tables[0].TableName = "data"
    +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : NullArray

    You cannot call a method on a null-valued expression.
    At C:\Users\ck\Desktop\dbatools\functions\Move-DbaDatabaseFile.ps1:201 char:4
    +             $null = $dbfiletable.Tables.Add($ftfiletable)
    +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull

    Resolving NetBIOS name
    SourceNetBios: sql2000
    You cannot call a method on a null-valued expression.
    At C:\Users\ck\Desktop\dbatools\functions\Move-DbaDatabaseFile.ps1:741 char:8
    +                 $files = $filestructure.Tables.Select($where)
    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull

    No files were selected!
    At C:\Users\ck\Desktop\dbatools\functions\Move-DbaDatabaseFile.ps1:821 char:17
    +                 throw "No files were selected!"
    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : OperationStopped: (No files were selected!:String) [], RuntimeException
        + FullyQualifiedErrorId : No files were selected!
  • Example 2 fails on seemingly SQL 2000 only
    Get database file inventory
    Exception calling "ExecuteWithResults" with "1" argument(s): "An exception occurred while executing a 
    Transact-SQL statement or batch."
    At C:\Users\ck\Desktop\dbatools\functions\Move-DbaDatabaseFile.ps1:179 char:4
    +             $dbfiletable = $server.ConnectionContext.ExecuteWithResul ...
    +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : ExecutionFailureException

    Cannot index into a null array.
    At C:\Users\ck\Desktop\dbatools\functions\Move-DbaDatabaseFile.ps1:180 char:4
    +             $ftfiletable = $dbfiletable.Tables[0].Clone()
    +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : NullArray

    Cannot index into a null array.
    At C:\Users\ck\Desktop\dbatools\functions\Move-DbaDatabaseFile.ps1:181 char:4
    +             $dbfiletable.Tables[0].TableName = "data"
    +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : NullArray

    You cannot call a method on a null-valued expression.
    At C:\Users\ck\Desktop\dbatools\functions\Move-DbaDatabaseFile.ps1:201 char:4
    +             $null = $dbfiletable.Tables.Add($ftfiletable)
    +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull

    Resolving NetBIOS name
    SourceNetBios: sql2000
    You cannot call a method on a null-valued expression.
    At C:\Users\ck\Desktop\dbatools\functions\Move-DbaDatabaseFile.ps1:741 char:8
    +                 $files = $filestructure.Tables.Select($where)
    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull

    No files were selected!
    At C:\Users\ck\Desktop\dbatools\functions\Move-DbaDatabaseFile.ps1:821 char:17
    +                 throw "No files were selected!"
    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : OperationStopped: (No files were selected!:String) [], RuntimeException
        + FullyQualifiedErrorId : No files were selected!
  • Example 3 fails on SQL 2014, clustered, did no further tests as a pattern formed
    Move-DbaDatabaseFile -SqlServer sqlcluster -Databases sqlcluster -FileType DATA
    Get database file inventory
    Resolving NetBIOS name
    SourceNetBios: sqla
    Will move all files of type 'ROWS'
    Show-SqlServerFileSystem : A parameter cannot be found that matches parameter name 'Whatif'.
    At C:\Users\ck\Desktop\dbatools\functions\Move-DbaDatabaseFile.ps1:796 char:113
    + ... ystem -SqlServer $server -SqlCredential $SqlCredential -Whatif:$false
    +                                                            ~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Show-SqlServerFileSystem], ParameterBindingExcept 
    ion
        + FullyQualifiedErrorId : NamedParameterNotFound,Show-SqlServerFileSystem

    No path was chosen.
    At C:\Users\ck\Desktop\dbatools\functions\Move-DbaDatabaseFile.ps1:800 char:25
    +                         throw "No path was chosen."
    +                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : OperationStopped: (No path was chosen.:String) [], RuntimeException
        + FullyQualifiedErrorId : No path was chosen.
    Move-DbaDatabaseFile -SqlServer sqlucluster -Databases sqlucluster -CheckFileHash
    You cannot call a method on a null-valued expression.
    At C:\Users\ck\Desktop\dbatools\functions\Move-DbaDatabaseFile.ps1:160 char:4
    +             $null = $allparams.Add("Databases", $dbparams.Databases)
    +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull

    Move-DbaDatabaseFile : A parameter cannot be found that matches parameter name 'Databases'.
    At line:1 char:45
    + Move-DbaDatabaseFile -SqlServer sqlucluster -Databases sqlucluster -C ...
    +                                             ~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Move-DbaDatabaseFile], ParameterBindingException
        + FullyQualifiedErrorId : NamedParameterNotFound,Move-DbaDatabaseFile

@ClaudioESSilva
Copy link
Collaborator Author

@ConstantineK can you confirm that you are using last commit (yesterday)?
Yesterday I have found that I renamed an old version of the script (regarding the code), so I have commit a new one (https://github.com/sqlcollaborative/dbatools/pull/250/commits).
And I didn't warn you. 😞

@potatoqualitee potatoqualitee modified the milestones: December 2016 Release, October 2016 Release, November 2016 Release Oct 24, 2016
@potatoqualitee
Copy link
Member

Moved to November release cycle as it requires special, time consuming attention and loving.

@dansqldba dansqldba modified the milestones: antsinmyeyesjohnson, December 2016 Release Nov 22, 2016
@potatoqualitee potatoqualitee added this to the twentyfiveschmeckles milestone Dec 13, 2016
@potatoqualitee potatoqualitee removed this from the schleem milestone Dec 13, 2016
Chrissy LeMaire and others added 6 commits December 19, 2016 11:41
Correction of 2 bugs related with SQL2000.
- error in query. was mention an alias that does not exists
- there is a bug where filename returned from SQL 2000 comes with NULL
plus SPACE characters. Here we get rid of them.

- DbccCheckDb
- Changed from NoDbccCheckDb to DbccCheckDB. When dealing with some big
databases you may not want to run this command right away. This way you
can choose when use it
- sysaltfiles name and filename columns are nchar datatypes. Changed the
query to remove them.
This would imply moving code from Copy-SqlDatabase to internal folder.
Also some of that code need to be rewrite.
This would need too much testing including the Copy-SqlDatabase command.
Too risky.
@potatoqualitee
Copy link
Member

Should this PR be removed and resubmitted later? It hasn't moved in quite some time and I never know what to do with it but hope ;)

@ConstantineK
Copy link
Contributor

Claudio had asked the question and I had answered it in slack, sorry about that. As far as I know the same issues I had reported were present.

@ClaudioESSilva
Copy link
Collaborator Author

@ConstantineK I have made few changes since your review. The principal issue was with sql 2000 that we decide to not support.
Did you retry it after my last commit?
If you can, please give it a try. Thanks
CC @ctrlbold

@ConstantineK
Copy link
Contributor

I will be trying this today and get back to you, thanks @ClaudioESSilva!

@potatoqualitee
Copy link
Member

I had an issue with snapshots. We need to either fix or ignore snapshots with warning.

PS C:\github\dbatools> Move-DbaDatabaseFile -SqlServer sql2005 -Databases db4_snapshot
Get database file inventory
Resolving NetBIOS name
SourceNetBios: sql2005
Robocopy exists locally.
We will check access to the specified paths.
Access to file paths finished.
We will check space requirements
Drive 'C:\' has sufficient free space (7468.24 MB) for all files to be copied (Space needed: 2.19 MB)'
Space requirements checked!
You are running this command locally.
We will use robocopy with UNC paths as copy method.
We will set database 'db4_snapshot' Offline!
Set database 'db4_snapshot' Offline!
Exception calling "ExecuteNonQuery" with "1" argument(s): "An exception occurred while executing a Transact-SQL
statement or batch."
At C:\github\dbatools\functions\Move-DbaDatabaseFile.ps1:206 char:17
+ ...             $server.ConnectionContext.ExecuteNonQuery("ALTER DATABASE ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ExecutionFailureException

Cannot set database 'db4_snapshot' in OFFLINE status.
At C:\github\dbatools\functions\Move-DbaDatabaseFile.ps1:221 char:21
+ ...             throw "Cannot set database '$database' in OFFLINE status. ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Cannot set data...OFFLINE status.:String) [], RuntimeException
    + FullyQualifiedErrorId : Cannot set database 'db4_snapshot' in OFFLINE status.

@potatoqualitee
Copy link
Member

I also had some other issues. Do you have time to work on this today? I was surprised to see that I could not specify a destination path -- I had to interact with GUI, which I'd like to fix. Or did I miss something?

PS C:\github\dbatools> Move-DbaDatabaseFile -SqlServer sql2005 -Databases dumpsterfire4 -CheckFileHash -DbccCheckDb -FileType DATA -DeleteSourceFiles
Get database file inventory
Resolving NetBIOS name
SourceNetBios: sql2005
Will move all files of type 'ROWS'
Robocopy exists locally.
We will check access to the specified paths.
Access to file paths finished.
We will check space requirements
Drive 'C:\' has sufficient free space (7465.38 MB) for all files to be copied (Space needed: 2.19 MB)'
Space requirements checked!
You are running this command locally.
We will use robocopy with UNC paths as copy method.
We will set database 'dumpsterfire4' Offline!
Set database 'dumpsterfire4' Offline!
Database set OFFLINE successfull! Actual state: 'Offline, AutoClosed'

 Log File : C:\WINDOWS\temp\20170128010726Robocopy.log

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows
-------------------------------------------------------------------------------

  Started : Saturday, January 28, 2017 1:07:26 PM
   Source : \\sql2005\C$\temp\
     Dest : \\sql2005\C$\temp\

    Files : dumpsterfire4.mdf

  Options : /BYTES /NC /NDL /TEE /DCOPY:DA /COPY:DATS /R:10 /W:3

------------------------------------------------------------------------------


------------------------------------------------------------------------------

               Total    Copied   Skipped  Mismatch    FAILED    Extras
    Dirs :         1         0         1         0         0         0
   Files :         1         0         1         0         0         0
   Bytes :   2293760         0   2293760         0         0         0
   Times :   0:00:00   0:00:00                       0:00:00   0:00:00
   Ended : Saturday, January 28, 2017 1:07:26 PM

Waiting for file 'dumpsterfire4.mdf' copy to complete...
Total elapsed time for copying 'dumpsterfire4.mdf' with robocopy: 00:00:00.3892451
Comparing file hash. This could take a while please wait.
.
File '\\sql2005\C$\temp\dumpsterfire4.mdf' deleted
Change file path for logical file 'dumpsterfire4' to 'C:\temp\dumpsterfire4.mdf'
File path changed with success.
Copy done! Lets bring database 'dumpsterfire4' Online!
WARNING: Exception calling "ExecuteNonQuery" with "1" argument(s): "An exception occurred while executing a Transact-SQL statement or batch."
Database 'dumpsterfire4' online!
The switch -DeleteSourceFiles was specified. Deleting source files.
WARNING: File \\sql2005\C$\temp\dumpsterfire4.mdf does not exists! No file copied!
Total Elapsed time: 00:00:01.7763798
PS C:\github\dbatools> $Error[0] | FL * -force
PSMessageDetails      :
Exception             : System.Management.Automation.MethodInvocationException: Exception calling "ExecuteNonQuery" with "1" argument(s): "An exception occurred while executing a Transact-SQL statement
                        or batch." ---> Microsoft.SqlServer.Management.Common.ExecutionFailureException: An exception occurred while executing a Transact-SQL statement or batch. --->
                        System.Data.SqlClient.SqlException: Unable to open the physical file "C:\temp\dumpsterfire4.mdf". Operating system error 2: "2(The system cannot find the file specified.)".
                        Database 'dumpsterfire4' cannot be opened due to inaccessible files or insufficient memory or disk space.  See the SQL Server errorlog for details.
                        ALTER DATABASE statement failed.
                           at Microsoft.SqlServer.Management.Common.ConnectionManager.ExecuteTSql(ExecuteTSqlAction action, Object execObject, DataSet fillDataSet, Boolean catchException)
                           at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType, Boolean retry)
                           --- End of inner exception stack trace ---
                           at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType, Boolean retry)
                           at CallSite.Target(Closure , CallSite , Object , String )
                           --- End of inner exception stack trace ---
                           at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
                           at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
                           at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
                           at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
TargetObject          :
CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
FullyQualifiedErrorId : ExecutionFailureException
ErrorDetails          :
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at Set-SqlDatabaseOnline, C:\github\dbatools\functions\Move-DbaDatabaseFile.ps1: line 240
                        at Move-DbaDatabaseFile<Process>, C:\github\dbatools\functions\Move-DbaDatabaseFile.ps1: line 1381
                        at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}

@potatoqualitee
Copy link
Member

@ClaudioESSilva I'd like to include this one in v1 -- any chance we can aim for the feb 14 release?

Was not returning the hash but the full object. The comparation was
failing when it should return OK
@ConstantineK
Copy link
Contributor

Looks like I got an error, I did put the destination file path in the csv

C:> Move-DbaDatabaseFile -MoveFromCSV -InputFile C:\temp\files.csv -Sqlserver sql2005
Get database file inventory
Resolving NetBIOS name
SourceNetBios: sql2005
Robocopy exists locally.
We will check access to the specified paths.
Access to file paths finished.
We will check space requirements
Drive 'C:\' has sufficient free space (7410.83 MB) for all files to be copied (Space needed: 1.2 MB)'
Space requirements checked!
You are running this command locally.
We will use robocopy with UNC paths as copy method.
We will set database '' Offline!
Set database '' Offline!
Move-DbaDatabaseFile : Exception calling "ExecuteNonQuery" with "1" argument(s): "An exception occurred while executing a Transact-SQL statement or batch."
At line:1 char:1
+ Move-DbaDatabaseFile -MoveFromCSV -InputFile C:\temp\files.csv -Sqlse ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Move-DbaDatabaseFile], MethodInvocationException
    + FullyQualifiedErrorId : ExecutionFailureException,Move-DbaDatabaseFile
"DestinationFolderPath","dbname","name","FileType","Filename","sizeKB"
"C:\temp\","dumpsterfire4","dumpsterfire4","ROWS","C:\temp\dumpsterfire4.mdf","200.00"
"C:\temp\","dumpsterfire4","dumpsterfire4_log","LOG","C:\temp\dumpsterfire4_log.ldf","1024.00"

@ClaudioESSilva
Copy link
Collaborator Author

Issue addressed @ConstantineK
Thanks!

@potatoqualitee
Copy link
Member

We will attack this as a team closer to 1.0. Closing PR but have backups of code.

@potatoqualitee potatoqualitee deleted the NewCommand_Move-SqlDatabaseFile branch March 1, 2017 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants