我正在备份和还原到系统。
对于使用以下代码制作Backup im:
textInformacao.Text = "";
Environment.SetEnvironmentVariable("PGPASSWORD", ConfiguracaoSistema.Password);
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = @Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\backup\\pg_dump.exe";
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = false;
psi.CreateNoWindow = true;
psi.Arguments = string.Format(@"-h {0} -p {1} -U {2} -F c -b -v -f {3} {4}", caminhoServidor, ConfiguracaoSistema.Port, ConfiguracaoSistema.UserName, arquivoSaida, ConfiguracaoSistema.NomeDataBase);
psi.UseShellExecute = false;
p = Process.Start(psi);
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardOutput = true;
p.EnableRaisingEvents = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.OutputDataReceived += new DataReceivedEventHandler((s, e) => { Dispatcher.BeginInvoke(new Action(() => { textInformacao.Text += e.Data + "\r\n"; textInformacao.ScrollToEnd(); })); });
p.ErrorDataReceived += new DataReceivedEventHandler((s, e) => { Dispatcher.BeginInvoke(new Action(() => { textInformacao.Text += e.Data + "\r\n"; textInformacao.ScrollToEnd(); })); });
p.Exited += (sender, e) => { Dispatcher.BeginInvoke(new Action(() => { textInformacao.Text += "Processo Finalizado!"; })); };
p.Start();
p.BeginOutputReadLine();
p.BeginErrorReadLine();
如果我得到此文件并打开pgAdmin,则一切正常,数据库将恢复。
使用以下代码进行即时还原:
textInformacao.Text = "";
Environment.SetEnvironmentVariable("PGPASSWORD", ConfiguracaoSistema.Password);
string caminhoArquivo = @Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\testesigep_vs.backup";
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = @Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\backup\\pg_restore.exe";
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = false;
psi.CreateNoWindow = true;
psi.Arguments = string.Format(@"-h {0} -p {1} -U {2} -c -d {3} -v {4}", caminhoServidor, ConfiguracaoSistema.Port, ConfiguracaoSistema.UserName, ConfiguracaoSistema.NomeDataBase, caminhoArquivo);
psi.UseShellExecute = false;
p = Process.Start(psi);
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardOutput = true;
p.EnableRaisingEvents = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.OutputDataReceived += new DataReceivedEventHandler((s, e) => { Dispatcher.BeginInvoke(new Action(() => { textInformacao.Text += e.Data + "\r\n"; textInformacao.ScrollToEnd(); })); });
p.ErrorDataReceived += new DataReceivedEventHandler((s, e) => { Dispatcher.BeginInvoke(new Action(() => { textInformacao.Text += e.Data + "\r\n"; textInformacao.ScrollToEnd(); })); });
p.Exited += (sender, e) => { Dispatcher.BeginInvoke(new Action(() => { textInformacao.Text += "Processo Finalizado!"; })); };
p.Start();
p.BeginOutputReadLine();
p.BeginErrorReadLine();
运行此代码时,我遇到一个“大问题”,所有行都是重复的。 看起来我的数据库已恢复:
外观图片,外观ID列具有两个相同的值。
如何解决此问题? 为什么在PgAdmin Restore中没有问题,而在c#中出现此问题?
EDIT ::::::::::::::::::::::::::::::::::::::::::::::::: :::::: 开始还原
pg_restore:连接到数据库以进行还原 pg_restore:删除数据库sigep_vs pg_restore:[存档(db)]处理目录时出错: pg_restore:[归档器(db)]来自TOC条目2949的错误; 1262 158041数据库sigep_vs sigep pg_restore:[存档(db)]无法执行查询:错误:无法删除当前打开的数据库 命令是:DROP DATABASE sigep_vs;
pg_restore:创建数据库“ sigep_vs” pg_restore:[存档(db)]无法执行查询:错误:数据库“ sigep_vs”已存在 命令是:CREATE DATABASE sigep_vs WITH TEMPLATE = template0 ENCODING ='UTF8'LC_COLLATE ='C'LC_CTYPE ='C';
Environment.SetEnvironmentVariable("PGPASSWORD", ConfiguracaoSistema.Password);
string caminhoArquivo = @Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\testesigep_vs.backup";
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = @Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\backup\\pg_restore.exe";
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = false;
psi.CreateNoWindow = true;
psi.Arguments = string.Format(@"-h {0} -p {1} -U {2} -d {3} -v {4}", caminhoServidor, ConfiguracaoSistema.Port, ConfiguracaoSistema.UserName, ConfiguracaoSistema.NomeDataBase, caminhoArquivo);
psi.UseShellExecute = false;
p = new Process { StartInfo = psi };
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardOutput = true;
p.EnableRaisingEvents = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.OutputDataReceived += new DataReceivedEventHandler((s, e) => { Dispatcher.BeginInvoke(new Action(() => { textInformacao.Text += e.Data + "\r\n"; textInformacao.ScrollToEnd(); })); });
p.ErrorDataReceived += new DataReceivedEventHandler((s, e) => { Dispatcher.BeginInvoke(new Action(() => { textInformacao.Text += e.Data + "\r\n"; textInformacao.ScrollToEnd(); })); });
p.Exited += (sender, e) => { Dispatcher.BeginInvoke(new Action(() => { textInformacao.Text += "Processo Finalizado!"; })); };
p.Start();
p.BeginOutputReadLine();
p.BeginErrorReadLine();
答案 0 :(得分:0)
现在,正在工作:
Environment.SetEnvironmentVariable("PGPASSWORD", ConfiguracaoSistema.Password);
string caminhoArquivo = @Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\testesigep_vs.backup";
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = @Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\backup\\pg_restore.exe";
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = false;
psi.CreateNoWindow = true;
psi.Arguments = string.Format(@"-h {0} -p {1} -U {2} -d {3} -v {4}", caminhoServidor, ConfiguracaoSistema.Port, ConfiguracaoSistema.UserName, ConfiguracaoSistema.NomeDataBase, caminhoArquivo);
psi.UseShellExecute = false;
p = new Process { StartInfo = psi };
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardOutput = true;
p.EnableRaisingEvents = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.OutputDataReceived += new DataReceivedEventHandler((s, e) => { Dispatcher.BeginInvoke(new Action(() => { textInformacao.Text += e.Data + "\r\n"; textInformacao.ScrollToEnd(); })); });
p.ErrorDataReceived += new DataReceivedEventHandler((s, e) => { Dispatcher.BeginInvoke(new Action(() => { textInformacao.Text += e.Data + "\r\n"; textInformacao.ScrollToEnd(); })); });
p.Exited += (sender, e) => { Dispatcher.BeginInvoke(new Action(() => { textInformacao.Text += "Processo Finalizado!"; })); };
p.Start();
p.BeginOutputReadLine();
p.BeginErrorReadLine();`