diff --git a/src/Corsinvest.ProxmoxVE.NodeProtect.Api/Application.cs b/src/Corsinvest.ProxmoxVE.NodeProtect.Api/Application.cs index 7c922e7..6650e4d 100644 --- a/src/Corsinvest.ProxmoxVE.NodeProtect.Api/Application.cs +++ b/src/Corsinvest.ProxmoxVE.NodeProtect.Api/Application.cs @@ -72,43 +72,39 @@ public static void Backup(string hostsAndPort, foreach (var (host, port) in ClientHelper.GetHostsAndPorts(hostsAndPort, 22, true, null)) { // Execute a (SHELL) Command for download - using (var sshClient = new SshClient(host, port, username, password)) - { - //create tar - sshClient.Connect(); - - var cmdCreateTarGz = $"tar -cvzPf {fileNameTarGz} {string.Join(" ", pathsToBackup)}"; - var retCmd = sshClient.CreateCommand(cmdCreateTarGz).Execute(); - if (debug) - { - @out.WriteLine($"Create file tar.gz: {cmdCreateTarGz}"); - @out.WriteLine($"Result command: {retCmd}"); - } - - var fileToSave = Path.Combine(pathSave, $"{host}{FILE_NAME}"); - - // download - using (var sftp = new SftpClient(host, port, username, password)) - using (var stream = File.OpenWrite(fileToSave)) - { - sftp.Connect(); - if (debug) { @out.WriteLine($"Download file tar.gz: {fileNameTarGz} to {fileToSave}"); } - sftp.DownloadFile(fileNameTarGz, stream); - sftp.Disconnect(); - } - - //delete tar - var cmdRmTarGz = $"rm {fileNameTarGz}"; - retCmd = sshClient.CreateCommand(cmdRmTarGz).Execute(); - if (debug) - { - @out.WriteLine($"Delete tar.gz: {cmdRmTarGz}"); - @out.WriteLine($"Result command: {retCmd}"); - } - sshClient.Disconnect(); - - @out.WriteLine($"Create config: {fileToSave}"); - } + using var sshClient = new SshClient(host, port, username, password); + //create tar + sshClient.Connect(); + + var cmdCreateTarGz = $"tar -cvzPf {fileNameTarGz} {string.Join(" ", pathsToBackup)}"; + var retCmd = sshClient.CreateCommand(cmdCreateTarGz).Execute(); + if (debug) + { + @out.WriteLine($"Create file tar.gz: {cmdCreateTarGz}"); + @out.WriteLine($"Result command: {retCmd}"); + } + + var fileToSave = Path.Combine(pathSave, $"{host}{FILE_NAME}"); + + // download + using var sftp = new SftpClient(host, port, username, password); + using var stream = File.OpenWrite(fileToSave); + sftp.Connect(); + if (debug) { @out.WriteLine($"Download file tar.gz: {fileNameTarGz} to {fileToSave}"); } + sftp.DownloadFile(fileNameTarGz, stream); + sftp.Disconnect(); + + //delete tar + var cmdRmTarGz = $"rm {fileNameTarGz}"; + retCmd = sshClient.CreateCommand(cmdRmTarGz).Execute(); + if (debug) + { + @out.WriteLine($"Delete tar.gz: {cmdRmTarGz}"); + @out.WriteLine($"Result command: {retCmd}"); + } + sshClient.Disconnect(); + + @out.WriteLine($"Create config: {fileToSave}"); } //keep @@ -154,20 +150,18 @@ public static void UploadToNode(string hostsAndPort, var fileName = FileNameLinuxTarGz(DirectoryToDate(fileTarGz)); //upload - using (var sftp = new SftpClient(host, port, username, password)) - using (var stream = File.OpenRead(fileTarGz)) - { - sftp.Connect(); - - if (debug) - { - @out.WriteLine($"Host: {host}:{port}"); - @out.WriteLine($"File upload: {fileName}"); - } - - sftp.UploadFile(stream, fileName); - sftp.Disconnect(); - } + using var sftp = new SftpClient(host, port, username, password); + using var stream = File.OpenRead(fileTarGz); + sftp.Connect(); + + if (debug) + { + @out.WriteLine($"Host: {host}:{port}"); + @out.WriteLine($"File upload: {fileName}"); + } + + sftp.UploadFile(stream, fileName); + sftp.Disconnect(); } } } \ No newline at end of file diff --git a/src/Corsinvest.ProxmoxVE.NodeProtect.Api/Corsinvest.ProxmoxVE.NodeProtect.Api.csproj b/src/Corsinvest.ProxmoxVE.NodeProtect.Api/Corsinvest.ProxmoxVE.NodeProtect.Api.csproj index 570bacd..a4e8e8e 100644 --- a/src/Corsinvest.ProxmoxVE.NodeProtect.Api/Corsinvest.ProxmoxVE.NodeProtect.Api.csproj +++ b/src/Corsinvest.ProxmoxVE.NodeProtect.Api/Corsinvest.ProxmoxVE.NodeProtect.Api.csproj @@ -1,9 +1,9 @@ - netstandard2.0 + netstandard2.1 true - 1.0.0 + 1.2.0 Corsinvest Srl Daniele Corsini Corsinvest Srl @@ -29,7 +29,7 @@ - + diff --git a/src/Corsinvest.ProxmoxVE.NodeProtect/Corsinvest.ProxmoxVE.NodeProtect.csproj b/src/Corsinvest.ProxmoxVE.NodeProtect/Corsinvest.ProxmoxVE.NodeProtect.csproj index e757938..f4a08a0 100644 --- a/src/Corsinvest.ProxmoxVE.NodeProtect/Corsinvest.ProxmoxVE.NodeProtect.csproj +++ b/src/Corsinvest.ProxmoxVE.NodeProtect/Corsinvest.ProxmoxVE.NodeProtect.csproj @@ -1,7 +1,7 @@ Exe - 1.0.0 + 1.1.0 netcoreapp3.1 cv4pve-node-protect Corsinvest Srl @@ -20,9 +20,9 @@ - + - + diff --git a/src/Corsinvest.ProxmoxVE.NodeProtect/build.ps1 b/src/Corsinvest.ProxmoxVE.NodeProtect/build.ps1 index 0373ad4..3d99db8 100644 --- a/src/Corsinvest.ProxmoxVE.NodeProtect/build.ps1 +++ b/src/Corsinvest.ProxmoxVE.NodeProtect/build.ps1 @@ -1,4 +1,4 @@ -# This file is part of the cv4pve-autosnap https://github.com/Corsinvest/cv4pve-pepper, +# This file is part of the cv4pve-node-protect https://github.com/Corsinvest/cv4pve-node-protect, # # This source file is available under two different licenses: # - GNU General Public License version 3 (GPLv3)