Remote Sql Server backups

Tagged: 

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 3 years, 2 months ago.

  • Author
    Posts
  • #14397
    Profile photo of Gregor Suttie
    Gregor Suttie
    Participant

    I have a script which looks like the following:-

    $machine = $computerName
    $server = New-Object Microsoft.SqlServer.Management.Smo.Server("$machine")

    Write-Host "server = $($server)"

    $backup = New-Object Microsoft.SqlServer.Management.Smo.Backup
    $backup.Database = $databaseName

    $date = Get-Date
    $date = $date -replace "/", "-"
    $date = $date -replace ":", "-"
    $date = $date -replace " ", "_"

    #$file = $backupFolderDBName + "\" + $databaseName + "_" + $date + ".bak"
    $file = "c:\downloads\backup\test_1.bak"

    $backup.Devices.AddDevice($file, [Microsoft.SqlServer.Management.Smo.DeviceType]::File)
    $backup.Action = [Microsoft.SqlServer.Management.Smo.BackupActionType]::Database
    $backup.SqlBackup($server)

    We have a test environment, staging and production, on the test and staging environment SQL Server runs as Local System account – I can remote onto both these servers and backup all my databases as required. On Production SQL Server runs as a specified account, when my script hits the last line to do the actual backup I get the following error:-

    SqlBackup" with "1" argument(s): "Backup failed for Server

    Is this the double hop issue, if I log onto the production server and run my script on the box itself it works just fine.

    Thanks for any advice
    Greg

  • #14437
    Profile photo of Don Jones
    Don Jones
    Keymaster

    So long as you're not asking the remoting session to access non-local resources, then no, it probably isn't a double-hop problem. But it sounds as if you may be asking the session to access non-local resources, since running the script when logged in on the console works.

You must be logged in to reply to this topic.