Restore Single Database from Backup Files Which Are Taken by Pg_Dumpall

 Normally, you can't restore a single database from a cluster backup that are taken via pg_dumpall.In order to achieve that, you can follow the steps below:

1- Create a script that greps specific database portion of the dump:

  #!/bin/bash

    [ $# -lt 2 ] && { echo "Usage: $0 <postgresql dump> <dbname>"; exit 1; }

    sed  "/connect.*$2/,\$!d" $1 | sed "/PostgreSQL database dump complete/,\$d"
2- Extract the portion  via example command below:
sh onedbscript.sh full_dump.dmp MY_DATABASE > onlyonedatabase.dmp
3- You may restore and test if it worked if you want:
psql -p <portnumber> -d MY_DATABASE < onlyonedatabase.dmp

Comments

Popular posts from this blog

Oracle Database Upgrade With OPatch Tool (RHEL/Centos/OEL)

POSTGRESQL UPGRADE WITH PG_UPGRADE UTILITY IN RHEL/CENTOS/OEL

Backup Recovery Scenarios