Manual Log Shipping on SQL server 2014

This topic contains 5 replies, has 2 voices, and was last updated by Profile photo of Tecina S. Tecina S. 2 months, 2 weeks ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #46563
    Profile photo of Tecina S.
    Tecina S.
    Participant

    Hello Don,

    I'm working on a project that will manually failover and failback our soon to be deployed Log Shipping solution for SQL server 2014.
    I've already figured out what he'll do and write 90% of the code that i'll present as our permanent solution.
    Yet, i'd like to have your feedbacks on the way i'm writing this. See, this will be THE solution used for my company, and as a new hired it's my way in the company for a more permanent position. So i'm betting all in this :-).

    So my code here : is the function that i came up with to do the things i want. All seemed to be running fine until i had to add a functionnality ( line 51 -55 ).
    It'll always return an error saying that the path (specified in the variable) cannot be null or empty. Which make senses.
    running the selected code from ISE runs the way i want, which got me puzzled.

    Thus i'd like to get a little of your time asking this :
    1- Am I doing this wrong? Is the way i approach it not the way i should?
    2- Is the code structure easy to understand?

    Thanks a ton for your site. I've learned powershell from your books and site for 1 month now and i'm really excited over it :-)).

    Regards,

    #46572
    Profile photo of Tecina S.
    Tecina S.
    Participant

    For clarity purposes, below is the error message i get when running the code:

    Copy-Item : Cannot bind argument to parameter 'Path' because it is null.
    At c:\scriptslib\Failover.ps1:56 char:11
    + Copy-Item $rlatesttrn $DRbicdir2 -ErrorAction Stop
    +           ~~~~~~~~~~~
        + CategoryInfo          : InvalidData: (:) [Copy-Item], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.CopyItemCommand

    Thanks.

    #46577
    Profile photo of random commandline
    random commandline
    Participant

    Rename-Item does not output a path. Use Join-Path to create a new path for the renamed file. This should resolve your error for lines 53 – 55. Use verb-noun syntax for your function name (ex: Set-Failover)

    ($latesttrn = Get-ChildItem $LSiddir -Filter *.trn | sort LastWriteTime | select -Last 1)
    Rename-Item $latesttrn.FullName user_$id.trn -ErrorAction Stop
    $newpath = join-path -Path $latesttrn.DirectoryName -ChildPath "user_$id.trn"
    Copy-Item $newpath $DRiddir2 -ErrorAction Stop
    
    #46679
    Profile photo of Tecina S.
    Tecina S.
    Participant

    Hello random commandline,
    The join-path command was a good idea thanks for the heads-up!
    But i have a different problem now: instead of copying the file to the directory mentioned in the copy-item command, the file was copied on the root C:\ drive causing the remaining actions to failed.
    Can you see any reason why it does that? I'm kinda short on idea here.

    #46730
    Profile photo of random commandline
    random commandline
    Participant

    Verify your '-Destination' and add '-WhatIf' at the end of your Copy-Item cmdlet. What destination is displayed during the '-WhatIf' test?

    #46759
    Profile photo of Tecina S.
    Tecina S.
    Participant

    Again, thanks. The destination variable name didn't match the one in the command.
    Your advises were spot on! Thanks.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.