Salutare,caut o solutie de securizare backup Postgres cu parola,pana acum arhivez rezultatul din pg_dump si apoi il sterg,am gasit pe net ca s-ar putea trimite direct in arhivator rezultatul pg_dump fara salvare pe disc,la fel si parola arhivei sa fie citita direct in environment variables
multumesc pt orice sugestie
C#
string pgDumpPath, outFile, host, port, database, user, password, dumpCommand, batFilePath, zipPth, outPath, tmpPath;
pgDumpPath = @"d:\_dev_\postgres\pgsql\bin\pg_dump.exe";
host = "127.0.0.1";
port = "5432";
database = "postgres";
user = "postgres";
password = "mypass";
dumpCommand = pgDumpPath + " -h " + host + " -p " + port + " -d " + database + " -U " + user;
tmpPath = Path.GetTempPath();
batFilePath = tmpPath + Guid.NewGuid().ToString() + ".cmd";
outFile = @"\postgres_" + DateTime.Now.ToString("yyyy") + "_" + DateTime.Now.ToString("MM") + "_" +
DateTime.Now.ToString("dd") + "_" + DateTime.Now.ToString("hh") + DateTime.Now.ToString("mm") +
DateTime.Now.ToString("ss");
outPath = @"d:\";
zipPth = @"c:\Program Files\7-Zip\7z.exe";
string tmpfile = "\"" + tmpPath + outFile + ".sql\"";
Environment.SetEnvironmentVariable("PGPASSWORD", password);
try
{
File.WriteAllText(batFilePath,
"@echo off " + "\n" +
dumpCommand + " > " + tmpfile + "\n" + "\"" +
zipPth + "\"" + " a \"" + outPath + outFile + ".zip\" -p" + password + " " +tmpfile +
" &DEL " + tmpfile +
" &DEL \"" + batFilePath + "\"",
Encoding.ASCII);
if (File.Exists(tmpfile))
File.Delete(tmpfile);
var oInfo = new ProcessStartInfo(batFilePath)
{
UseShellExecute = false,
CreateNoWindow = true
};
using (var proc = Process.Start(oInfo))
{
proc.WaitForExit();
proc.Close();
}
}
finally
{
if (File.Exists(batFilePath))
File.Delete(batFilePath);
}
}