Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

postgresql backup and restore



  • I have some problem trying to restore a backup made with pg_dump (it´s a postgres command).
    When I restore the backup using the postgresql command from console works fine:
    psql "dbname=myDB host=localhost user=myUsr password=Mypwd" < myBackup

    So I tried to implement the same function in QT via QProcess without success.
    MyProcess.setNativeArguments(""dbname=myDB host=localhost user=myUsr password=Mypwd" < myBackup")
    MyProcess.setProgram("psql");

    Somebody has some example how to do it correctly.

    Many thanks
    Pablo



  • Hi all,

    Well I found the solution searching in Internet and I found this link:
    https://www.codeproject.com/Articles/360472/Postgres-Database-Backup-Restore-From-Csharp

    Looks that psql for some reason cannot be launch inside of Qt, so I created a bat file that contains the psql command and their parameters. Then I call that bat file from QProcess and Finally works fine!!!

    Anyway I will keep open this ticket for a while if somebody has a better solution.

    Pablo


  • Qt Champions 2019

    @PabloArg Processes started using QProcess do NOT run inside your Qt app!
    The problem is that you pass the parameter wrongly: you should not pass all parameters as one string.
    You should read QProcess documentation, there are examples:

    QObject *parent;
    ...
    QString program = "./path/to/Qt/examples/widgets/analogclock";
    QStringList arguments;
    arguments << "-style" << "fusion";
    
    QProcess *myProcess = new QProcess(parent);
    myProcess->start(program, arguments);
    

    So, each parameter is put as string in a string list.

    You should connect http://doc.qt.io/qt-5/qprocess.html#errorOccurred to a slot and print the error.



  • Hi jsulm,

    I tried as you said as well, but doesn´t work. Anyway according to QProcess is possible to use Native parameters where your parameters you can put as string and QT will recognize each parameters by spaces between them. I am usign for long time without problem.

    I will close this ticket because looks that this is a problem with psql. And the only solution is create a bat file, and run the bat in QProcess.

    Many thanks to everybody as I said before if you guys found better idea to do this let me know


Log in to reply