6.9 Backing-up and Restoring Internal PostgreSQL Database

6.9.1 Backing-up Internal PostgreSQL Database

To take a backup of the internal PostgreSQL database, perform the following steps:

  1. Stop Servicedesk service, by running the following command:

    service servicedesk stop

  2. witch to postgres user, by running the following command:

    sudo -su postgres

  3. Go to the root level (/) or to the /tmp to avoid permission issue warning

    Example: cd /tmp

  4. Take database backup and keep it in /tmp location with file name "servicedesk_db.backup"

    pg_dump --dbname=servicedesk --file=/tmp/servicedesk_db.backup --encoding=UTF8 --blobs --format tar

  5. Start the service desk service, by running the following command:

    service servicedesk start

6.9.2 Restoring the Internal PostgreSQL Database

To restore the internal PostgreSQL database, perform the following steps:

  1. Copy the database backup to the /tmp location

  2. stop Servicedesk service, by running the following command:

    service servicedesk stop

  3. Switch to postgres user, by running the following command:

    sudo -su postgres

  4. Go to the root level (/) or to the /tmp to avoid permission issue warning

    Example: cd /tmp

  5. Drop existing internal database.

    If the drop fails, then the database is being used. Example: servicedesk any other database viewer tool. Ensure that you stop those services)

    dropdb servicedesk

  6. Create empty internal database, by running the following command:

    createdb servicedesk --template=template0 --encoding=UTF8 --owner=sdadmin

  7. Restore database from the backup file, , by running the following command:

    pg_restore /tmp/servicedesk_db.backup --dbname=servicedesk -n public

  8. run vacuum command to optimize, by running the following command:

    vacuumdb -f -z servicedesk

  9. Start the service desk service, by running the following command:

    service servicedesk start