locked
Using powershell for transaction log backup RRS feed

  • Question

  • Hi,

    I am trying to run powershell for restore sql server from full backup followed by transaction log;

    $server = New-Object ("Microsoft.SqlServer.Management.Smo.Server") "(local)"
    $backupDevice = New-Object("Microsoft.SqlServer.Management.Smo.BackupDeviceItem") ($backupFile, "File")
    $smoRestore = new-object("Microsoft.SqlServer.Management.Smo.Restore")
     
    #restore settings
    $smoRestore.NoRecovery = $true;
    $smoRestore.ReplaceDatabase = $true;
    $smoRestore.Action = "Database"
    $smoRestorePercentCompleteNotification = 10;
    $smoRestore.Devices.Add($backupDevice)
    
    $smoRestore2 = new-object("Microsoft.SqlServer.Management.Smo.Restore")
    $backupDevice2 = New-Object("Microsoft.SqlServer.Management.Smo.BackupDeviceItem") ($Logb, "File")
    
    #restore2 settings
    $smoRestore2.NoRecovery = $false;
    $smoRestore2.ReplaceDatabase = $true;
    $smoRestore2.Action = "log"
    $smoRestorePercentCompleteNotification = 10;
    $smoRestore2.Devices.Add($backupDevice2)
    
    #restore2 database
    $smoRestore2.SqlRestore($server) 

    It fails on $smoRestore2.SqlRestore($server) with below error;

    + $smoRestore2.SqlRestore <<<< ($server)
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : DotNetMethodException

    What could be missing here? Please if you can provide me some hints? Thanks!

    Tuesday, December 12, 2017 5:39 PM

All replies

  • On of your parameters is bad.  Be sure all files and values are correct.

    Two variables are not defined in your code.


    \_(ツ)_/

    Tuesday, December 12, 2017 5:51 PM