I am currently backing up the entire database using pg_dump:
<?php include_once("../db.php"); $password = getPGPassword(); $user = getPGUser(); $db = getPGDb(); putenv("PGPASSWORD=" . $password); $dumpcmd = array("pg_dump", "-i", "-U", escapeshellarg($user), "-F", "c", "-b", "-v", "-f", escapeshellarg('/var/www/backups/backup-'.time().'.sql'), escapeshellarg($db)); exec( join(' ', $dumpcmd), $cmdout, $cmdresult ); putenv("PGPASSWORD"); ?>
I know that I can use psql to restore the entire database, but is there a way that I can selectively restore part of the table using a query? The simplest thing I can think of is creating a temporary database with psql, reading rows from the desired table, removing conflicting rows based on the primary serial key, and pasting into the table.
Is there a better way to do this? I need a full sql query.
source share