Tools

Back up and restore the PostgreSQL database using the command line in Web Help Desk (WHD)

This article describes how to back up and restore the embedded PostgreSQL database using the command line.

First published date

10/18/2018 5:44 PM

Last published date

1/30/2025 5:23 PM

Overview

The following information provides the steps on how back up and restore the embedded PostgreSQL database using the command line. There are times that a GUI would not be available and a backup and restoration of the database can only be done via a command line. This information is for PostgreSQL database only.

Product section

Web Help Desk

Resolution

Make sure that the Web Help Desk service is stopped while working on the database.

The following table lists the paths to the Web Help Desk home directory.

Operating SystemLocation
Microsoft WindowsC:\Program Files\WebHelpDesk\
Linux or Virtual Appliance/usr/local/webhelpdesk/
MacOS/Library/WebHelpDesk/

Back up the PostgreSQL database

Windows Server

  1. Open a command prompt.
  2. In the window, execute:
    cd C:\Progra~1\WebHelpDesk
  3. Back up the database. Execute:
    PostgreSQL 9: pgsql9\bin\pg_dump -Fc -v -h 127.0.0.1 -p 20293 -U whd [database_name] > whd_pgdump.backup
    PostgreSQL 13: pgsql13\bin\pg_dump -Fc -v -h 127.0.0.1 -p 20293 -U [username] [database_name] > whd_pgdump.backup
  4. Enter corresponding password if prompted. [whd - default for PostgreSQL 9]. 
A backup file will be created in \Progra~1\WebHelpDesk\ with the name whd.pgdump.backup

Linux or Virtual Appliance

You can download the virtual appliance from the Customer Portal

  1. Download and start PuTTY or another SSHv2 client
  2. Connect to the Linux server.
    If you are connecting to a virtual appliance, connect as the user admin
  3. In Linux, switch to root user or any user with sudo privileges.
    In the Virtual Appliance, enter sudo su.
  4. Execute:
    cd /usr/local/webhelpdesk/
  5. Back up the database. Execute:
    PostgreSQL 9: pgsql9/bin/pg_dump -Fc -v -h 127.0.0.1 -p 20293 -U whd whd > whd_pgdump.backup
    PostgreSQL 13: pgsql13/bin/pg_dump -Fc -v -h 127.0.0.1 -p 20293 -U [username] [database_name] > whd_pgdump.backup
    Enter corresponding password if prompted. [whd - default for PostgreSQL 9]
A backup file will be created in /usr/local/webhelpdesk/ with the name whd.pgdump.backup

MacOS

  1. Open the Applications > Utilities > Terminal.
  2. In the terminal window, execute:
    cd /Library/WebHelpDesk/
  3. Back up the database.
    Execute:
    PostgreSQL 9: pgsql9\bin\pg_dump -Fc -v -h 127.0.0.1 -p 20293 -U whd whd > whd_pgdump.backup
    PostgreSQL 13: pgsql13\bin\pg_dump -Fc -v -h 127.0.0.1 -p 20293 -U [username] [database_name] > whd_pgdump.backup
    Enter corresponding password if prompted. [whd - default for PostgreSQL 9]
A backup file will be created in /Library/WebHelpDesk/ with the name whd.pgdump.backup

Restore the PostgreSQL database

Windows Server

  1. Open a command prompt.
  2. In the window, execute:
    cd C:\Progra~1\WebHelpDesk
  3. Restore the database.
    Execute:
    PostgreSQL 9: pgsql9\bin\pg_restore -Fc -v -h 127.0.0.1 -p 20293 -U [username] -d [database_name] path_to_whd_pgdump.backup
    PostgreSQL 13: pgsql13\bin\pg_restore -Fc -v -h 127.0.0.1 -p 20293 -U [username] -d [database_name] path_to_whd_pgdump.backup
    Note: Default username is whd.  When prompted for the password, enter corresponding password for corresponding username.

Linux or Virtual Appliance

  1. Connect to the Linux server.
    If you are connecting to a virtual appliance, connect as the user admin.
  2. Connect to the Linux server.
    If you are connecting to a virtual appliance, connect as the user admin
  3. In Linux, switch to root user or any user with sudo privileges.
    In the Virtual Appliance,enter sudo su.
  4. Execute:
    cd /usr/local/webhelpdesk/
  5. Restore the database. Execute:
    PostgreSQL 9: pgsql9/bin/pg_restore -Fc -v -h 127.0.0.1 -p 20293 -U [username] -d [database_name] path_to_whd_pgdump.backup
    PostgreSQL 13: pgsql13/bin/pg_restore -Fc -v -h 127.0.0.1 -p 20293 -U [username] -d [database_name] path_to_whd_pgdump.backup
    Note: Default username is whd.  When prompted for the password, enter corresponding password for corresponding username.
  6. Alternatively, if the data already exists in the database, run the --clean command to drop all existing data and replace with the data from the backup. 
    PostgreSQL 9: pgsql9/bin/pg_restore --clean -v -h 127.0.0.1 -p 20293 -U [username] -d [database_name] path_to_whd_pgdump.backup
    PostgreSQL 13: pgsql13/bin/pg_restore --clean  -v -h 127.0.0.1 -p 20293 -U [username] -d [database_name] path_to_whd_pgdump.backup

MacOS

  1. Open the Applications > Utilities > Terminal.
  2. Execute:
    cd /Library/WebHelpDesk/
  3. Restore the database. Execute:
    PostgreSQL 9: pgsql9/bin/pg_restore -Fc -v -h 127.0.0.1 -p 20293 -U [username] -d [database_name] path_to_whd_pgdump.backup 
    PostgreSQL 13: pgsql13/bin/pg_restore -Fc -v -h 127.0.0.1 -p 20293 -U [username] -d [database_name] path_to_whd_pgdump.backup
    Note: Default username is whd.  When prompted for the password, enter corresponding password for corresponding username.
  4. Alternatively, if the data already exists in the database, run the --clean command to drop all existing data and replace with the data from the backup. 
    PostgreSQL 9: pgsql9/bin/pg_restore --clean -v -h 127.0.0.1 -p 20293 -U [username] -d [database_name] path_to_whd_pgdump.backup
    PostgreSQL 13: pgsql13/bin/pg_restore --clean -v -h 127.0.0.1 -p 20293 -U [username] -d [database_name] path_to_whd_pgdump.backup