Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. postgresql backup and restore
Forum Updated to NodeBB v4.3 + New Features

postgresql backup and restore

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PabloArg
    wrote on 22 Feb 2017, 22:23 last edited by
    #1

    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

    1 Reply Last reply
    0
    • P Offline
      P Offline
      PabloArg
      wrote on 22 Feb 2017, 23:10 last edited by
      #2

      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

      J 1 Reply Last reply 23 Feb 2017, 05:40
      0
      • P PabloArg
        22 Feb 2017, 23:10

        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

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 23 Feb 2017, 05:40 last edited by jsulm
        #3

        @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.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • P Offline
          P Offline
          PabloArg
          wrote on 24 Feb 2017, 02:32 last edited by
          #4

          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

          1 Reply Last reply
          0

          1/4

          22 Feb 2017, 22:23

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved