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
Last published date
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
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 System | Location |
|---|---|
| Microsoft Windows | C:\Program Files\WebHelpDesk\ |
| Linux or Virtual Appliance | /usr/local/webhelpdesk/ |
| MacOS | /Library/WebHelpDesk/ |
Back up the PostgreSQL database
Windows Server
- Open a command prompt.
- In the window, execute:
cd C:\Progra~1\WebHelpDesk
- 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
- Enter corresponding password if prompted. [whd - default for PostgreSQL 9].
\Progra~1\WebHelpDesk\ with the name whd.pgdump.backupLinux or Virtual Appliance
You can download the virtual appliance from the Customer Portal.
- Download and start PuTTY or another SSHv2 client
- Connect to the Linux server.
If you are connecting to a virtual appliance, connect as the useradmin. - In Linux, switch to
rootuser or any user withsudoprivileges.
In the Virtual Appliance, entersudo su. - Execute:
cd /usr/local/webhelpdesk/
- 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]
/usr/local/webhelpdesk/ with the name whd.pgdump.backupMacOS
- Open the Applications > Utilities > Terminal.
- In the terminal window, execute:
cd /Library/WebHelpDesk/
- 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]
/Library/WebHelpDesk/ with the name whd.pgdump.backupRestore the PostgreSQL database
Windows Server
- Open a command prompt.
- In the window, execute:
cd C:\Progra~1\WebHelpDesk
- 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
- Connect to the Linux server.
If you are connecting to a virtual appliance, connect as the useradmin. - Connect to the Linux server.
If you are connecting to a virtual appliance, connect as the useradmin. - In Linux, switch to
rootuser or any user withsudoprivileges.
In the Virtual Appliance,entersudo su. - Execute:
cd /usr/local/webhelpdesk/
- 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. - 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
- Open the Applications > Utilities > Terminal.
- Execute:
cd /Library/WebHelpDesk/
- 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. - 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