private void btnRestore_Click(object sender, EventArgs e)
{
if (clsB.ConectaBanco())
{
//Executo a seguinte função para limpar a base de dados, para poder dar o restore.
clsB.ExecutarSQL("drop schema public cascade; create schema public;");
//E executo o seguinte processo
string Comando = CaminhoPg + @"psql -U postgres -d restore2 -f C:\Users\bruhh\Desktop\Backup\back.backup";
Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = CaminhoPg + @"psql" ;
p.StartInfo.Arguments = @"-U postgres -d restore2 -f C:\Users\bruhh\Desktop\Backup\back.backup";
p.Start();
p.WaitForExit();
p.Close();
MessageBox.Show(Comando);
}
else
MessageBox.Show("Ocorreu um erro ao carregar as configurações do banco de dados! \nvá em Configurações\Banco De Dados");
}
The result of the various command is
C:\Program Files\PostgreSQL\9.4\bin\psql -U postgres -d restore2 -f C:\Users\bruhh\Desktop\Backup\back.backup
The process even executes but all lines appear "invalid command". What would it take to make this code work?
How the process gets when it runs
[EDIT]MethodusedtoperformBackup
publicstringBackupDatabase(stringCaminhoNome){stringserver=clsConfigBanco.SERVERNAME;stringport=clsConfigBanco.PORT;stringuser=clsConfigBanco.USERNAME;stringpassword=clsConfigBanco.PASSWORD;stringdbname=clsConfigBanco.DATABASENAME;stringbackupCommandDir=@"C:\Program Files\PostgreSQL.4\bin";
try
{
Environment.SetEnvironmentVariable("PGPASSWORD", password);
string backupFile = CaminhoNome;
string BackupString = "-ibv -Z3 -f \"" + backupFile + "\" " +
"-Fc -h " + server + " -U " + user + " -p " + port + " " + dbname;
Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = CaminhoPg + "\pg_dump.exe";
p.StartInfo.Arguments = BackupString;
p.Start();
p.WaitForExit();
p.Close();
return backupFile;
}
catch
{
return "";
}
}