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. How to generate PostgreSQL backup with QProcess, from the Qt app
Forum Updated to NodeBB v4.3 + New Features

How to generate PostgreSQL backup with QProcess, from the Qt app

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 388 Views
  • 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.
  • lincolnL Offline
    lincolnL Offline
    lincoln
    wrote on last edited by lincoln
    #1

    Hi guys, I have the following code. My problem is the following: When I click on my button, I get the message, the backup was generated, but when reviewing the generated file, it is empty. And the other thing is how I pass the server password in the arguments, because I have another postgreSQL instance that has a login password, I would appreciate any suggestions.

    void Widget::on_pushButton_6_clicked()
    {
      QProcess* process=new QProcess(this);
      QString prog("C:/Program Files/PostgreSQL/13/bin/pg_dump.exe");
      QStringList params;
    
      params<<"-U"<<"postgres"<<"-v"<<"-Fc"<<"-f"<<"D:/base.backup"<<"monitoreo_db";
      bool res=process->startDetached(prog,params);
      if(!res){
        QMessageBox::critical(this,qApp->applicationName(),"Failed to execute command.\n");
        return;
      }
      QMessageBox::information(this,qApp->applicationName(),"backup was created successfully.\n"+
                                                                QString::number(process->exitStatus()));
    }
    

    Solitary wolf

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by ChrisW67
      #2

      You are starting the process detached from yours. QProcess::startDetached() does not wait for the process to or finish and it report success if it managed to tell Windows to start the pg_dump process without an immediate error. So, you may be looking too soon for the resulting backup file(s), or it could be failing after launch and your process will never hear about it.

      It's also possible that the forward slashes to the target file should be native slashes.

      For the password you may be able to use "--no-password" and a .pgpass file; perhaps written to a temporary file by your code and identified to the process in the PGPASSFILE environment variable.

      lincolnL 1 Reply Last reply
      1
      • C ChrisW67

        You are starting the process detached from yours. QProcess::startDetached() does not wait for the process to or finish and it report success if it managed to tell Windows to start the pg_dump process without an immediate error. So, you may be looking too soon for the resulting backup file(s), or it could be failing after launch and your process will never hear about it.

        It's also possible that the forward slashes to the target file should be native slashes.

        For the password you may be able to use "--no-password" and a .pgpass file; perhaps written to a temporary file by your code and identified to the process in the PGPASSFILE environment variable.

        lincolnL Offline
        lincolnL Offline
        lincoln
        wrote on last edited by
        #3

        @ChrisW67
        Thanks for your answer, as you said change '/' to '\' and in that case if it worked, I generate the backup correctly, the only thing that left me with doubts was with the password, so what I did was remove the password to the postgres user, and with that fix my problem.
        thanks anyway for your reply.

        Solitary wolf

        1 Reply Last reply
        0

        • Login

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