C# – Backup Postgresql DB

Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;

p.StartInfo.CreateNoWindow = false;
p.Start();

String command = "";

//備份位置
String outputPath = @"C:\";
if (!Directory.Exists(outputPath))
{
	Directory.CreateDirectory(outputPath);
}

command = @"cd C:\Bitnami\postgresql\bin";
p.StandardInput.WriteLine(command);

command = @"pg_dump -U " + "DB帳號" + " -d " + "DB密碼 + " -f " + outputPath + "檔名.sql";
//執行備份
p.StandardInput.WriteLine(command);

開始在上面輸入您的搜索詞,然後按回車進行搜索。按ESC取消。

返回頂部