4
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 variable 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 runs but on all lines appears "invalid command". What would be necessary to make this code work?
How the process looks when it is executed
[EDIT] Method used to perform Backup
public string BackupDatabase(string CaminhoNome)
{
string server = clsConfigBanco.SERVERNAME;
string port = clsConfigBanco.PORT;
string user = clsConfigBanco.USERNAME;
string password = clsConfigBanco.PASSWORD;
string dbname = clsConfigBanco.DATABASENAME;
string backupCommandDir = @"C:\Program Files\PostgreSQL\9.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 "";
}
}
shows how your dump is, at least the beginning of it
– Rovann Linhalis
What would this dump be?
– Bruno Silva
Hi? The file generated by 'pg_dump' that would be your backup... In your case, "back."
– Rovann Linhalis
You’re picking up some null and junk values. Very strange, apparently you’re having trouble with this back. but I think it’s the problem, because by pg’s Store it works, follow the link to download the https://1drv.ms/u/sfile! Aronqw2yo1tchi963aaysahjupmasg
– Bruno Silva
There’s something wrong with this dump your... rs like it’s doing it ?
– Rovann Linhalis
I updated the question with the method for performing the backup
– Bruno Silva