different:powershell_ssh_scp
Это старая версия документа!
SCP/SSH Powershell password
- | download
Import-Module PowershellGet Set-ExecutionPolicy -ExecutionPolicy RemoteSigned #Yes Install-Module Posh-SSH #Yes
- | download
Import-Module Posh-SSH $servers = @() $servers += @{ name = 'adc01' ip = '192.168.124.11' } #$cred = Get-Credential -Credential nsroot #$cred.Password | ConvertFrom-SecureString | Set-Content ./nsroot.txt $nsUser = "nsroot" $encryptedPass = Get-Content ./nsroot.txt | ConvertTo-SecureString $cred = New-Object System.Management.Automation.PsCredential($nsUser, $encryptedPass) $backupStorePath = "./" $backup_level = "basic", "full" $doFullBackup = $true #or $false function get_backup { param ( $backupName, $destinationPath = "./" ) $backup_file_path = "/var/ns_sys_backup/$backupName.tgz" Write-Host($backup_file_path) $result = Get-SCPItem ` -ComputerName $server.ip ` -Credential $cred ` -Path $backup_file_path ` -PathType File ` -Destination $destinationPath return $result } function create_backup { param ( $server, $doFullBackup = $True ) $backup_name_pattern = "adc_" + $server.name + "_" + $(get-date -format "yyyy_MM_dd") Write-Host($server.name,$backup_name_pattern,$backup_level[$doFullBackup]) $sshCommand = "create system backup " + $backup_name_pattern +" -level " + $backup_level[$doFullBackup] #Write-Host($sshCommand) $sshSession = New-SSHSession -ComputerName $server.ip -Credential $cred -AcceptKey $result = Invoke-SSHCommand -Command $sshCommand -SSHSession $sshSession if ($result.ExitStatus -eq 0) { $result = get_backup -backupName $backup_name_pattern -destinationPath $backupStorePath } else { Write-Host($result.Host, $result.Output) } Remove-SSHSession -SessionId $sshSession.SessionId } foreach ($server in $servers) { create_backup -server $server -doFullBackup $doFullBackup }
different/powershell_ssh_scp.1724058151.txt.gz · Последнее изменение: 2024/12/21 19:00 (внешнее изменение)