简体   繁体   English

PostgreSQL数据库备份

[英]Postgresql Database Backup

I am developing a C# application and could not find any details on backing up the database using C#. 我正在开发C#应用程序,找不到有关使用C#备份数据库的任何详细信息。 I would like to provide the users of the application ability to save a backup of the database and so on 我想为应用程序的用户提供保存数据库备份等的功能

I would really appreciate if someone could provide information on this issue. 如果有人可以提供有关此问题的信息,我将不胜感激。 The specification of the system I am using is: 我使用的系统规格为:

OS: Windows XP Pro/Windows Vista DB: PostgreSQL .Net Connection for C#: Npgsql 操作系统:Windows XP Pro / Windows Vista DB:C#的PostgreSQL .Net连接:Npgsql

I have Followed the way of approach like this as 我遵循了这样的方法

public static Boolean myfile(String content,String path)
{
    Boolean result = false;
    try
    {                
        System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
        info.FileName = path;
        info.Arguments = content;
        info.CreateNoWindow = true;
        info.UseShellExecute = false;
        System.Diagnostics.Process proc = new System.Diagnostics.Process();
        proc.StartInfo = info;
        proc.Start();
        proc.WaitForExit();                
        result = true;

    }
    catch (Exception ex)
    {
       Console.writeline(ex.Message);
    }
    return result;
}

and too i have passed parameters as 我也通过了参数

content:pg_dump --inserts -h x.x.x.x -U xxxx -n public  -w  xxxx > D:\sql\mysample.sql


path:D:\Program Files\PostgreSQL\9.0\bin\PostgreSQL\9.0\bin\

i am getting exception response as 我正在作为异常响应

Access is denied 拒绝访问

Update 1: 更新1:

i too used code like this to get permission as 我也用这样的代码来获得许可

//var permissionSet = new PermissionSet(PermissionState.None);
//var writePermission = new FileIOPermission(FileIOPermissionAccess.AllAccess, dirName);
//permissionSet.AddPermission(writePermission);

it does not help me out. 它没有帮助我。

Access denied suggests a file permission issue. 拒绝访问表明存在文件权限问题。 Maybe your user doesn't have permission to run pg_dump, or there is an issue writing the file output. 也许您的用户没有运行pg_dump的权限,或者在写入文件输出时出现问题。

The first thing to do is to try to run it and just discard the output and see if you get the same error. 要做的第一件事是尝试运行它,只是丢弃输出,看看是否遇到相同的错误。 If you do not, you need to set file permissions (right click the directory, security,set permissions). 如果不这样做,则需要设置文件权限(右键单击目录,安全性,设置权限)。 If you do, you have an issue running pg_dump (try the same with the pg_dump file). 如果这样做,您在运行pg_dump时会遇到问题(请对pg_dump文件尝试相同的操作)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM