从C#Postgres数据库备份/恢复 - CodeProject [英] Postgres database backup/restore from C# - CodeProject
本文介绍了从C#Postgres数据库备份/恢复 - CodeProject的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Postgres Database Backup/Restore From C# - CodeProject
我尝试过:
What I have tried:
private void butBackup_Click(object sender, EventArgs e)
{
try
{
if (textBox1.Text == "-------")
{
MessageBox.Show("Select the location to save");
return;
}
StreamWriter sw = new StreamWriter("DBBackup.bat");
// Do not change lines / spaces b/w words.
StringBuilder strSB = new StringBuilder(strPG_dumpPath);
if (strSB.Length != 0)
{
strSB.Append("pg_dump.exe --host " + strServer + " --port " + strPort +
" --username postgres --format custom --blobs --verbose --file ");
strSB.Append("\"" + textBox1.Text + "\"");
strSB.Append(" \"" + strDatabaseName + "\r\n\r\n");
sw.WriteLine(strSB);
sw.Dispose();
sw.Close();
Process processDB = Process.Start("DBBackup.bat");
do
{//dont perform anything
}
while (!processDB.HasExited);
{
MessageBox.Show(strDatabaseName + " Successfully Backed up at " + textBox1.Text);
}
}
else
{
MessageBox.Show("Please Provide the Location to take Backup!");
}
}
catch (Exception ex)
{ }
}
推荐答案
我认为您的问题是批处理文件的默认路径不是什么你期望,大多数是\ Windows \ System32
。
你不需要创建一个批处理文件,一切都是c可以使用Process.Start()
完成。
我成功地使用了这个备份和恢复,但是找不到常规,也许接下来我再次上班的那一周:)
我还建议使用Path.Combine()
来连接像这样的路径strPG_dumpPath
,带pg_dump.exe
。
I think your problem is that the default path for a batch file is not what you expect, mostly this is\Windows\System32
.
You don't need to create a batch file, everything can be done usingProcess.Start()
.
I used this successfully to backup and restore, can't find the routine though, maybe next week when I'm at work again :)
I also recommend usingPath.Combine()
to concatenate paths likestrPG_dumpPath
withpg_dump.exe
.
这篇关于从C#Postgres数据库备份/恢复 - CodeProject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文