Инструменты пользователя

Инструменты сайта


different:powershell_ssh_scp

Различия

Показаны различия между двумя версиями страницы.

Ссылка на это сравнение

Предыдущая версия справа и слеваПредыдущая версия
Следующая версия
Предыдущая версия
different:powershell_ssh_scp [2024/08/19 14:28] rootdifferent:powershell_ssh_scp [2024/12/21 19:00] (текущий) – внешнее изменение 127.0.0.1
Строка 1: Строка 1:
 ====== SCP/SSH Powershell password ====== ====== SCP/SSH Powershell password ======
 +====== Установить модуль Posh-SSH ======
 <code=powershell> <code=powershell>
 Import-Module PowershellGet Import-Module PowershellGet
Строка 6: Строка 7:
 </code> </code>
  
 +====== Скрипт бэкапа ======
 <code=powershell> <code=powershell>
 Import-Module Posh-SSH Import-Module Posh-SSH
Строка 49: Строка 50:
     $sshCommand = "rm system backup " + $backupName +".tgz"     $sshCommand = "rm system backup " + $backupName +".tgz"
     Write-Host($sshCommand)     Write-Host($sshCommand)
-    $sshSession = New-SSHSession -ComputerName $server.ip -Credential $cred -AcceptKey+    $sshSession = New-SSHSession -ComputerName $server.ip -Credential $cred -AcceptKey -Force
     $result = Invoke-SSHCommand -Command $sshCommand -SSHSession $sshSession     $result = Invoke-SSHCommand -Command $sshCommand -SSHSession $sshSession
     if ($result.ExitStatus -eq 0) {     if ($result.ExitStatus -eq 0) {
Строка 87: Строка 88:
     )     )
    
-    $backup_name_pattern = $server.name + "_" + $(get-date -format "yyyy_MM_dd")+    $backup_name_pattern = $server.name+ "_" + $backup_level[$doFullBackup]  + "_" + $(get-date -format "yyyy_MM_dd")
     Write-Host($server.name,$backup_name_pattern,$backup_level[$doFullBackup], $erase)     Write-Host($server.name,$backup_name_pattern,$backup_level[$doFullBackup], $erase)
-    $sshCommand = "create system backup " + $backup_name_pattern +" -level " + $backup_level[$doFullBackup] +    $sshCommands = @() 
-    #Write-Host($sshCommand)+    $sshCommands += "set HA node -haSync DISABLED -haProp DISABLED" #0 
 +    $sshCommands += "save ns config" #1 
 +    $sshCommands += "create system backup " + $backup_name_pattern +" -level " + $backup_level[$doFullBackup] #2 
 +    $sshCommands += "set HA node -haSync ENABLED -haProp ENABLED" #3 
 +    $sshCommands += "save ns config" #4
     $sshSession = New-SSHSession -ComputerName $server.ip -Credential $cred -AcceptKey     $sshSession = New-SSHSession -ComputerName $server.ip -Credential $cred -AcceptKey
-    $result = Invoke-SSHCommand -Command $sshCommand -SSHSession $sshSession+    Invoke-SSHCommand -Command $sshCommands[0] -SSHSession $sshSession 
 +    Invoke-SSHCommand -Command $sshCommands[1] -SSHSession $sshSession 
 +    $result = Invoke-SSHCommand -Command $sshCommands[2] -SSHSession $sshSession
     if ($result.ExitStatus -eq 0) {     if ($result.ExitStatus -eq 0) {
         $result = get_backup -server $server -backupName $backup_name_pattern -destinationPath $backupStorePath -erase $erase         $result = get_backup -server $server -backupName $backup_name_pattern -destinationPath $backupStorePath -erase $erase
Строка 99: Строка 106:
         Write-Host($result.Host, $result.Output)         Write-Host($result.Host, $result.Output)
     }     }
 +    Invoke-SSHCommand -Command $sshCommands[3] -SSHSession $sshSession -
 +    Invoke-SSHCommand -Command $sshCommands[4] -SSHSession $sshSession
     Remove-SSHSession -SessionId $sshSession.SessionId     Remove-SSHSession -SessionId $sshSession.SessionId
 } }
different/powershell_ssh_scp.1724066907.txt.gz · Последнее изменение: 2024/12/21 19:00 (внешнее изменение)