8.5 Restoring the PostgreSQL Database

Restoring an archived database is performed by using the pg_restore command. Using the pg_restore command, you can restore the backup taken by both pg_dump and AutomaticPostgresMaintenanceConfigureAction.

To restore a backup, use the following command:

pg_restore [connection-option...] [option...] [filename]

For more information on options, see pg_restore.

8.5.1 Restoring the Database Backup Taken Using the ZMAN Command

To restore a backup that was taken using the zman command (zman db), perform the following:

On Linux

  1. Stop the Services by running the following configure action:

    microfocus-zenworks-configure -c Start

    After running the command, under Action, select Stop.

  2. (conditional) If Vertica is enabled in your zone, then stop the following services in ZENworks Appliance, using following command:

    • systemctl stop zenworks-connect.service

    • systemctl stop zenworks-kafka.service

  3. Close the database dangling connections by running the following commands:

    SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid = pg_backend_pid();
  4. Change the user by running the su zenpostgres command.

  5. Set the super user password for pg_restore and dropdb using the following command:

    $ PGPASSWORD=<<set superuser password>>; export PGPASSWORD

  6. Set the library path and BIN path as shown below:

    • LD_LIBRARY_PATH=/opt/microfocus/zenworks/share/pgsql/lib; export LD_LIBRARY_PATH

    • PATH=$PATH:/opt/microfocus/zenworks/share/pgsql/bin; export PATH

  7. Drop the existing database, the database name can be zenworks or audit database.

    docker exec -it zenpostgres dropdb $ dropdb --host=localhost --dbname=<<database_name>> --port=54327 --username=<<superuser_name>> <<database_name>>

    $ dropdb --host=localhost --dbname=<<database_name>> --port=54327 --username=<<superuser_name>> <<database_name>>

  8. Restore the database by running the following command:

    docker exec -it zenpostgres pg_restore $ pg_restore --host=localhost --port=54327 --username=<<superuser_name>> --format=directory --dbname=<<database_name>> -C <<full path to zenDB_pg_dump>>

NOTE:Ensure that the dump directory is accessible from zenpostgres or postgres user.