在本地文件C#中转换停靠的邮政
嗨,我试图将Postgres DB倒在Docker中。我在PowerShell上使用的脚本是:
docker exec -t timescaledb pg_dumpall -c -u postgres> .. \ dump_timescales \ dump_prova.sql
它可以按预期工作。我无法弄清楚如何在C#中运行它。 我尝试了以下操作:
internal static bool dumpTdb(DateTime time)
{
try
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "powershell.exe";
startInfo.Arguments = $"/C docker exec -t timescaledb pg_dumpall -c -U postgres > ..\\dump_timescales\\dump_prova_{time}.sql";
process.StartInfo = startInfo;
process.Start();
}
catch (Exception)
{
return false;
}
return true;
}
没有错误,但是没有丢弃文件。 我想念什么? 从C#倾倒DB的最佳做法是哪种?
其他信息:我从触发Azure函数的时间开始运行此功能。
Hi I am trying to dump a postgres db in a docker. The script I use on powershell is :
docker exec -t timescaledb pg_dumpall -c -U postgres > ..\dump_timescales\dump_prova.sql
It work as expected. I am not able to figure it out how to run it in c#.
I tried the following:
internal static bool dumpTdb(DateTime time)
{
try
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "powershell.exe";
startInfo.Arguments = quot;/C docker exec -t timescaledb pg_dumpall -c -U postgres > ..\\dump_timescales\\dump_prova_{time}.sql";
process.StartInfo = startInfo;
process.Start();
}
catch (Exception)
{
return false;
}
return true;
}
I get no error however no file is dumped.
What am I missing?
Which is the best practice to dump a db from c#?
Additional info: I am running this function from a Time Triggered Azure function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
process.start
- 顾名思义 - start 一个过程。如果您在调用DUMPTDB
后退出程序,则包括您的转储程序在内的所有子进程都将被杀死。调用
process.waitforexit()
等待转储这样完成process.Start
- as the name implies - starts a process. If you exit your program after callingdumpTdb
, then all child processes, including your dump process, will be killed.Call
process.WaitForExit()
to wait for the dump to finish like this