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

Add a OutFileMapping switch and output to Get-DbaDatabaseFile #3080

Closed
Stuart-Moore opened this issue Jan 16, 2018 · 17 comments · Fixed by #7578
Closed

Add a OutFileMapping switch and output to Get-DbaDatabaseFile #3080

Stuart-Moore opened this issue Jan 16, 2018 · 17 comments · Fixed by #7578
Assignees
Labels

Comments

@Stuart-Moore
Copy link
Contributor

Feature Request

Problem to solve

Add an easy way to build the FileMapping Hashtable for Restore-DbaDatabase from an existing database

For example:
$FileMapping = Get-DbaDatabaseFile -SqlInstance Instance1 -Database db1 -OutFileMapping

Would return $FileMapping of type Hashtable like this:

$FileMapping = @{
"Datafile1"  = "c:\data\datafile1.mdf";
"Datafile2" = "d:\ArchiveData\File2.mdf";
"LogFile1" = "e:\LogFiles\Log1.ldf"}
@ChrisTuckerNM
Copy link
Collaborator

Would liek to pick up this issue, any objections?

@potatoqualitee
Copy link
Member

please do 👍

@ChrisTuckerNM
Copy link
Collaborator

that was odd. lol

@ChrisTuckerNM
Copy link
Collaborator

Questions:

  1. Should the command be called with multiple SqlInstance values, what would the behavior be?
  2. Does select-object @{Name="name"; Expression={$.LogicalName}},@{Name="value"; Expression={$.PhysicalName}} cover the requirement?

@Stuart-Moore
Copy link
Contributor Author

Morning,
1- Good question. Personal preference would be for a custom object along the lines of:
[PSCustomObject]@{
ComputerName
InstanceName
Database
MappingHash
}

Whilst this usecase doesn't really support multiple dbs (Restore won't use hash for moves atm if more than 1 db is specified, though that's not a breaker, so it could be implement post this) this one would be consistent with dbatools practice, and make it easy for the user to extract the ones they need with a pipe through Where-Object

Or we could just refuse multiple instances with this switch.........

2 - I don't think so. The Restore command is expecting a hashtable for all the files in a db whereas that would just provide the table for 1 file so the user would still need to concatenate them themselves

This option is really going to be adding another output option. The current code spits out an object per file, whereas this would be an object per database, so probably branch at L175, group by databasename and then looping through that.

@niphlod
Copy link
Contributor

niphlod commented Jul 20, 2018

I don't think is good to change result format via a single switch.
Instead of changing behaviour and result format at this point I'd go for splitting an internal function that fetches the info per database (and can be reused by restore-dbadatabase) and is used within get-dbadatabasefile to give the same result as it is now.

@Stuart-Moore
Copy link
Contributor Author

Stuart-Moore commented Jul 20, 2018 via email

@niphlod
Copy link
Contributor

niphlod commented Jul 20, 2018

I don't expect much user would need it as it's really easy to build that up starting from get-dbadatabasefile straight. Get-DbaDatabaseFileMap as internal sounds good.

@Stuart-Moore
Copy link
Contributor Author

Yeah, I vaguely remember that was the gist of the slack conversation.
Get-This | Select-This | Format-That
but was seen as too tricky by the other party.

Maybe just add examples to the CBH for restore-dbadatabase under the Filemapping parameter help and Get-DbaDatabaseFile in the example sections?

@ChrisTuckerNM
Copy link
Collaborator

I'm advocating an example in CBH too.

@ChrisTuckerNM ChrisTuckerNM removed their assignment Jul 23, 2018
@ChrisTuckerNM
Copy link
Collaborator

Taking myself off this till we understand what..

@andreasjordan
Copy link
Contributor

Interesting feature.

We only need info returned from Get-DbaDatabase:

$db = Get-DbaDatabase -SqlInstance SRV1B -Database AdventureWorks
$fileMap = @{}
foreach ($file in $db.FileGroups.Files) {
    $fileMap[$file.Name] = $file.FileName
}
foreach ($file in $db.LogFiles) {
    $fileMap[$file.Name] = $file.FileName 
}
[PSCustomObject]@{ 
    ComputerName = $db.ComputerName
    InstanceName = $db.InstanceName
    SqlInstance  = $db.SqlInstance
    Database     = $db.Name
    FileMap      = $fileMap
}

Do we agree on Get-DbaDbFileMap as the name of the new command?

@andreasjordan andreasjordan self-assigned this May 20, 2021
@andreasjordan andreasjordan added this to To do in AndreasJordan May 20, 2021
@andreasjordan andreasjordan moved this from To do to New Command in AndreasJordan May 20, 2021
@potatoqualitee
Copy link
Member

Good command name, but does Get-DbaDbFile not fit the bill?

image

@andreasjordan
Copy link
Contributor

We need that hash that is returned in FileMap.

@potatoqualitee
Copy link
Member

oh ah! sorry, I skipped to the bottom. k, sounds good!

@andreasjordan
Copy link
Contributor

@potatoqualitee : As you are creating a lot of new commands at the moment: Can you take my code (#3080 (comment)) and create the command around it?

I would think we only need parameters -SqlInstance, -SqlCredential and -Database, maybe allow piped input from Get-DbaDatabase as well.

@potatoqualitee
Copy link
Member

I can indeed 👍🏼

AndreasJordan automation moved this from New Command to Done Jul 18, 2021
@andreasjordan andreasjordan removed this from Done in AndreasJordan Jul 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants