c# winform 实现对postgresql数据库的自动备份还原功能
来源:互联网 发布:淘宝风干牛肉干可靠吗? 编辑:程序博客网 时间:2024/05/19 12:16
public static void StartCmd(String workingDirectory, String command)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.WorkingDirectory = workingDirectory;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine(command);
p.StandardInput.WriteLine("exit");
p.Close();
}
//构建执行的命令
StringBuilder sbcommand = new StringBuilder();
sbcommand.AppendFormat("pg_dump.exe -h localhost -p 5556 -U pgs -Fc -b -v -f\"{0}\" tj", @path);
String command = sbcommand.ToString();
//获取pg_dump.exe所在路径
String appDirecroty = @"C:\Program Files\pgsql\bin";
StartCmd(appDirecroty, command);
string backtime = time.ToString("yyyy年MM月dd日HH点mm分ss秒");
string sql = "insert into backup(version,date,path)values('1.0.7','" + backtime + "','" + path2 + "')";
MainFrmClient mfClient = new MainFrmClient();
mfClient.ExecSql(sql);
DataBind();
MessageBox.Show("恭喜,备份成功!");
//数据库还原
OpenFileDialog file = new OpenFileDialog();
file.Title = "打开文件";
file.Filter = "备份文件(*.backup)|";
file.InitialDirectory = "D:\\backup\\"; //默认路径
file.Multiselect = false;
if (file.ShowDialog() == DialogResult.OK)
{
//构建执行的命令
StringBuilder sbcommand = new StringBuilder();
sbcommand.AppendFormat("pg_restore.exe -h localhost -p 5556 -U pgs -d test -v \"{0}\"", file.FileName);
String command = sbcommand.ToString();
//获取pg_dump.exe所在路径
String appDirecroty = @"C:\Program Files\pgsql\bin";
StartCmd(appDirecroty, command);
MessageBox.Show("恭喜,还原成功!");
}
//对postgresql数据库内某一模式备份命令:
//h:主机IP,p:端口, U:用户名,f:备份文件存储位置,
sbcommand.AppendFormat("pg_dump.exe -h localhost -p 5556 -U pgs -Fc -v -f \"{0}\" --schema \"{1}\" tjtz", path, schemaName);
String command = sbcommand.ToString();
还原该模式数据时同上还原:
sbcommand.AppendFormat("pg_restore.exe -h localhost -p 5556 -U pgs -d test -v \"{0}\"", file.FileName);
博客来自:http://blog.csdn.net/swarb/article/details/6935485
- c# winform 实现对postgresql数据库的自动备份还原功能
- c# winform 实现对postgresql数据库的自动备份还原功能
- C#实现数据库的备份与还原
- C#实现数据库的备份与还原
- 数据库备份与还原的C#实现
- C#实现数据库的备份和还原
- Postgresql的dump数据库备份与还原
- postgresql数据库的备份和还原
- postgresql 数据库的备份与还原
- C# Tip -- C#实现MySQL数据库的备份和还原
- pg_rman 实现对postgresql数据库的备份,恢复与管理
- postgresql数据库备份与还原
- C#实现SQLSERVER2000数据库备份还原的两种方法
- C#数据库备份及还原的实现代码
- 程序实现postgresql备份还原
- C#备份还原数据库
- PostgreSQL的备份与还原
- C# 版的数据库备份、还原、初始化
- 将IP以整型的形式存储到数据库中
- shell递归遍历目录
- HLG 1400 汽车比赛
- Yii——图片附件的上传、编辑及删除【同样适用于其它类型附件】
- win7 下的telnet不是内部或外部命令也不是可运行的程序或批处理
- c# winform 实现对postgresql数据库的自动备份还原功能
- QT的定时器事件中遇见的一个误区
- iOS 中json解析数据出现中文乱码的问题
- 全球身份ID
- 恭喜我漂亮的小宝贝
- 程序员最该看的30本书 --------国外编辑推荐
- leetcode Swap Nodes in Pairs java实现
- CListBox的AddString 排序问题
- 纵横交错地考查C++功底 [2]