Remote Sql Server backups

Welcome Forums General PowerShell Q&A Remote Sql Server backups

This topic contains 1 reply, has 2 voices, and was last updated by

4 years, 8 months ago.

  • Author
  • #14397

    Points: 0
    Rank: Member

    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

    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

  • #14437

    Points: 1,704
    Helping HandTeam Member
    Rank: Community Hero

    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.

The topic ‘Remote Sql Server backups’ is closed to new replies.