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 using the following commands:
systemctl stop microfocus-zenserver.service
systemctl stop microfocus-zenloader.service
(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.
$ 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:
$ pg_restore --host=localhost --port=54327 --username=<<superuser_name>> --format=directory --dbname=<<database_name>> -C <<full path to zenDB_pg_dump>>
$ 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.
Stop the following services using the Windows Services MSI:
microfocus-zenserver.service
microfocus-zenloader.service
(conditional) If Vertica is enabled in your zone, then stop the following services in ZENworks Appliance:
zenworks-connect.service
zenworks-kafka.service
Close the database dangling connections by running the following commands from PSQL:
SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE pid = pg_backend_pid
Set the super user password for the pg_restore and dropdb commands:
set PGPASSWORD=<<set superuser password>>
Change the command line to the PostgreSQL bin folder path as shown below:
cd /opt/microfocus/zenworks/share/pgsql/bin/
Drop the existing database by running the following command. The database name can be zenworks or audit database.
dropdb --host=localhost --port=54327 --username=<<superuser_name>> <<database_name>>
Restore the database by running the following command:
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.