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

Invoke-DbaDbLogShipping - Fix issues with Restore*Folder #8157

Merged
merged 2 commits into from
Feb 20, 2022

Conversation

andreasjordan
Copy link
Contributor

Type of Change

  • Bug fix (non-breaking change, fixes # )
  • New feature (non-breaking change, adds functionality, fixes # )
  • Breaking change (effects multiple commands or functionality, fixes # )
  • Ran manual Pester test and has passed (.\tests\manual.pester.ps1)
  • Adding code coverage to existing functionality
  • Pester test is included
  • If new file reference added for test, has is been added to github.com/dataplat/appveyor-lab ?
  • Unit test is included
  • Documentation
  • Build system

Was reported on slack by Abhi.

I don't know what the idea of the per-database-subfolder was - but as it never worked, I removed it.
@sanderstad Do you have time to have a look?

@andreasjordan
Copy link
Contributor Author

Message from Slack:

Hi All.I am trying to setup Logshipping for DB1 to the same server ( as DB1_Copy). But the new DB is getting restored to default DATA & LOG directory(to F drive, instead of N drive).Am I missing a parameter? Could you please help?

#Data & LOG location of DB1 : M drive
#Data & LOG location of DB1_Copy : N drive
# Instance Data & Log default location : F drive

# Configure Log Shipping 

$invokeDbaLogShippingSplat = @{   
SourceSqlInstance = 'sqlserver'    
DestinationSqlInstance = 'sqlserver'    
Database = 'DB1'  
SecondaryDatabaseSuffix = '_Copy'    
RestoreDataFolder='N:\Data\'     
RestoreLogFolder='N:\Log\'     
GenerateFullBackup=$true    
CompressBackup = $true
BackupNetworkPath = '\\sqlserver\share2'
BackupLocalPath = 'M:\share'
BackupScheduleFrequencySubdayType = 'Minutes'
BackupScheduleFrequencySubdayInterval = 5   
CopyDestinationFolder = 'M:\share'
CopyScheduleFrequencySubdayType = 'Minutes'
CopyScheduleFrequencySubdayInterval = 5
RestoreScheduleFrequencySubdayType = 'Minutes'
RestoreScheduleFrequencySubdayInterval = 5
NoRecovery = $true    
Force = $true
}
Invoke-DbaDbLogShipping @invokeDbaLogShippingSplat

@sanderstad
Copy link
Contributor

The idea of the subfolder was to make sure that when the database had the same file names, you could still restore it on the same server.

@Abhilash1987
Copy link

Hi Andreas..I tested it but getting a different error now. I am able to see the PreLogShipping backup file in the share I specified

PrimaryInstance : sqlserver
SecondaryInstance : sqlserver
PrimaryDatabase : Abhi
SecondaryDatabase : Abhi_Copy
Result : Failed
Comment : Something went wrong generating the full backup

@sanderstad
Copy link
Contributor

What do you get when you run

$error[0] | fl -force

@andreasjordan
Copy link
Contributor Author

Thanks Sander for stepping in.

@Abhilash1987
Copy link

Please find the o/p of $error[0] | fl -force

Exception : System.Management.Automation.CommandNotFoundException: The term 'Write-Message' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
at System.Management.Automation.CommandDiscovery.LookupCommandInfo(String commandName, CommandTypes commandTypes, SearchResolutionOptions
searchResolutionOptions, CommandOrigin commandOrigin, ExecutionContext context)
at System.Management.Automation.CommandDiscovery.LookupCommandProcessor(String commandName, CommandOrigin commandOrigin, Nullable1 useLocalScope) at System.Management.Automation.ExecutionContext.CreateCommand(String command, Boolean dotSource) at System.Management.Automation.PipelineOps.AddCommand(PipelineProcessor pipe, CommandParameterInternal[] commandElements, CommandBaseAst commandBaseAst, CommandRedirection[] redirections, ExecutionContext context) at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext) at System.Management.Automation.Interpreter.ActionCallInstruction6.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
TargetObject : Write-Message
CategoryInfo : ObjectNotFound: (Write-Message:String) [], CommandNotFoundException
FullyQualifiedErrorId : CommandNotFoundException
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at Invoke-DbaDbLogShipping, : line 1683
at , : line 23
PipelineIterationInfo : {}
PSMessageDetails :

@sanderstad
Copy link
Contributor

Well that error does not make much sense because that command is being used throughout the command and other commands as well.

Can you run the command for initialing the log shipping with -Verbose so we can see what the command does in the background?

@Abhilash1987
Copy link

Thanks Sander, I could execute the script successfully but DB still gets created on the default location. Please find the logs attached.
logshipping_PS.txt

@andreasjordan
Copy link
Contributor Author

I just pushed a new commit to the branch which added some more verbose messages. This way we can prove that the new code path is executed.

@andreasjordan
Copy link
Contributor Author

But your verbose output is missing "Testing database restore" which tells me that you don't run this branch here.
You could try to find the code for Invoke-DbaDbLogShipping inside of the allcomands.ps1 and replace it by the code from this branch. Otherwise you need to make sure to import with the full path like Import-Module C:\GitHub\dbatools\dbatools.psm1.

@potatoqualitee
Copy link
Member

will merge upon agreement and approval

@Abhilash1987
Copy link

Hi Andreas, Thanks for providing the detailed steps. I tested the new code & it worked perfectly :-) Thanks again for the quick fix & help.

@potatoqualitee
Copy link
Member

Hey all -- does @Abhilash1987's comment mean this is good and can be merged?

@andreasjordan
Copy link
Contributor Author

I think so.

@potatoqualitee potatoqualitee merged commit 77da44c into development Feb 20, 2022
@potatoqualitee potatoqualitee deleted the InvokeDbaDbLogShipping_fix_RestoreFolder branch February 20, 2022 12:17
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

4 participants