6.3 Moving the Data from an Embedded PostgreSQL to an External PostgreSQL

Moving the data from an embedded PostgreSQL server to an external PostgreSQL server is a two step process:

6.3.1 Step 1: Backup the Database on the Embedded Primary Server

  1. Before executing the following steps, ensure that you have reviewed the information documented in the section Important Commands and Locations.

  2. Stop the ZENworks Services on all the Primary Servers by running the following configure action:

    novell-zenworks-configure -c Start

    After running the command, under Action, select Stop.

  3. On the Primary Server on which the Embedded Database is installed, Start the Novell ZENworks Embedded Datastore service using the following steps:

    On Windows: Press the Win + R keys on the keyboard to open the Run window. Type services. msc and then hit Enter.

    Start the Novell ZENworks Embedded Datastore – PostgreSQL service.

    On Linux: Run the following command to start the Novell ZENworks Embedded Datastore – PostgreSQL service.

    • On SLES 12 and later: systemctl start zenpostgresql.service

    • On SLES 11: /etc/init.d/zenpostgresql start

  4. Login to the Primary Server that has the database role.

  5. Initiate the backup by setting the following variables:

    • PGPORT: <existing source DB port configured>

      By default, ZENworks uses 54327

    • PGDATA: <embedded_database_location>

    • PGUSER: <existing super user for ZENworks postgres DB> The default user for ZENworks is zenpostgres.

    • PGDATABASE: <existing database name> ZENworks default is postgres

    • PGPASSWORD: <password for the above super user PGUSER>

    Example 6-1 Example for Windows Primary Server

    Set the following environment variables:

    • Set the PATH for PostgreSQL installation.

    • Set the PATH for PostgreSQL bin folder.

    Open the command prompt and set the following variables based on the existing configuration.

    • SET PGPORT=54327

    • SET PGDATA=%ZENWORKS_HOME%\database\pgsql\data

    • SET PGUSER=<super user retrieved from zman dgcs>

    • SET PGDATABASE=postgres

    • SET PGPASSWORD=<password retrieved from zman dgcs>;

  6. Run the following commands to back up both the databases (ZENworks and Audit):

    • On Windows:

      • pg_dumpall.exe > "<path to sql file>"

        Example: pg_dumpall.exe > c:\postgres_dump.sql

  7. On the Primary Server on which the Embedded Database is installed (source database), Stop the Novell ZENworks Embedded Datastore service using the following steps:

    On Windows: Press the Win + R keys on the keyboard to open the Run window. Type services. msc and then hit Enter.

    Stop the Novell ZENworks Embedded Datastore – PostgreSQL service.

    On Linux: Run the following command to start the Novell ZENworks Embedded Datastore – PostgreSQL service.

    • On SLES 12: systemctl stop zenpostgresql.service

6.3.2 Step 2: Restore the Database on an External Server

Perform the following steps on an external server on which you want to move the PostgreSQL database. After installing PostgreSQL on an external server, ensure that the PostgreSQL database service is running.

To restore the database on an external database server, perform the following steps:

  1. Set the following environment variables:

    • PGPORT: <target DB port>

    • PGUSER: <target super user for postgres DB>

    • PGDATABASE: <target initial connection database name> default is postgres

    • PGPASSWORD: <password for the above super user i.e. PGUSER>

      Example 6-2 Example for Windows Primary Server

      Set the following environment variables:

      • Set the path for PostgreSQL installation.

      • Set the path for PostgreSQL bin folder.

      Open the command prompt and set the following variables based on the existing configuration.

      • SET PGPORT=54327

      • SET PGUSER=<PostgreSQL super user>

      • SET PGDATABASE=postgres

      • SET PGPASSWORD=<Postgres super user password>

      Example 6-3 Example for Linux Primary Server:

      Open the terminal and set the following variables based on the existing configuration.

      • export LD_LIBRARY_PATH=<postgres installation path>/lib;

      • export PATH=$PATH:<postgres installation path>/bin;

      • export PGPORT=<Port on which PostgreSQL is configured>;

      • export PGUSER=<Postgres super user>;

      • export PGDATABASE=postgres;

      • export PGPASSWORD=<PostgreSQL super user password>;

  2. Login as PostgreSQL super user and manually create the database using the following query for the databases that should be restored:

    create database <DB name> with template=template0 encoding='UTF8';

    For example:

    • ZENworks Database: create database zenworks with template=template0 encoding='UTF8';

    • Audit Database: create database zenworksaudit with template=template0 encoding='UTF8';

  3. Copy the postgres_dump.sql file that was created in Step 1: Backup the Database on the Embedded Primary Server to the target device.

  4. Restore the database from the backup taken in Step 1: Backup the Database on the Embedded Primary Server, by running the following commands:

    • On Windows: In the Command prompt, run the following commands:

      • cd <postgres installation path>\bin

      • psql.exe -v ON_ERROR_STOP=0 -f c:\postgres_dump.sql -o c:\postgres_dump_log.txt -L c:\postgres_dump_log.log > c:\postgres_dump_log.err 2>&1

    • On Linux: In the Terminal, run the following commands as PostgreSQL user:

      • cd <postgres installation path>/bin

      • ./psql -v ON_ERROR_STOP=0 -f /tmp/postgres_dump.sql -o /tmp/postgres_dump _log.txt -L /tmp/postgres_dump_log.log > /tmp/postgres_dump_log.err 2>&1

  5. After Restoring the database, log into the ZENworks database, and run the below query to delete the database role for the device that has the embedded PostgreSQL database installed by running the following query on the external database server:

    delete from zZenServerRoles where Roles = 'Database';

    commit;

  6. Update the following changes in zdm.xml and zenaudit.xml for all the Primary Servers in the zone:

    • Delete the <entry key="Embedded">true</entry>.

    • Update the value of the Port key with the port on which the external PostgreSQL database is configured.

      <entry key="Port"><PORT-of-target-DB-device></entry>

  7. Update the server key value in the zdm.xml and zenaudit.xml files as shown below:

    • In the target database server, add the loopback IP address.

      <entry key="Server"><target_database_server-IP></entry>

    • In all the other Primary Server, add the IP of the target database server.

      <entry key="Server"><target_database_server-IP></entry>

  8. In the new database server, run the following configure actions: microfocus-zenworks-configure -c GenerateOSPProperties

  9. Run microfocus-zenworks-configure -c GenerateContentDatasourceConfigureAction on all the content servers.

  10. After updating the changes, restart all the ZENworks services by running the novell-zenworks-configure -c Start configure action.

  11. Ensure that the Novell ZENworks Embedded Datastore service is disabled and not running on the Primary Server that hosted the Embedded PostgreSQL database.

  12. The ZENworks Server now points to new database.

    Ensure that you can successfully log into ZCC. After logging into ZCC, go to the Diagnostics page and in the ZENworks Databases panel, verify the Host IP addresses and also verify that the Audit database is connected.

IMPORTANT:Before migrating the database, if you had configured the Vertica database in your zone, then after migration, ensure that you re-create the Kafka connectors in the zone, to resume the syncing of data from the new database to Vertica. To re-create the connectors, you need to run the command zman server-role-kafka-recreate-connectors -f on one of the servers in which Kafka is installed. While executing this command, ensure that the source database is up and running. After the Kafka connectors are created successfully, you can then disable the source database. For more information, see the Vertica Reference Guide.