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.
To restore a backup that was taken using the zman command (zman db), perform the following:
Stop the Services by running the following configure action:
microfocus-zenworks-configure -c Start
After running the command, under Action, select Stop.
(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
Close the database dangling connections by running the following commands:
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid = pg_backend_pid();
Change the user by running the su zenpostgres command.
Set the super user password for pg_restore and dropdb using the following command:
$ PGPASSWORD=<<set superuser password>>; export PGPASSWORD
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
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>>
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.