Back Up and Restore Internal Database

Greenrelease 4.2.5 and higher
apip42
Greenrelease 4.2.5 and higher
API Portal
 provides an out-of-the-box PostgreSQL internal database and a script to perform backup and restore of your database. We recommend that you regularly back up the database for safeguarding. 
Currently, only the data inside the PostgreSQL database (service name ‘portaldb’) is backed up and restored by this feature.
The backup occurs on a source API Portal while the restore occurs on a target API Portal. The source and target can be the same API Portal.
We recommend the following steps:
  • Set up a CRON job to schedule regular backups
  • RSYNC the backup directory to a remote storage location
This article contains the following information:
Prerequisites
To back up and restore
API Portal
, you need the following privileges and files:
  • Root permission to run
    API Portal
     command
    Note:
    Non-root users must run
    API Portal
     commands that are prepended with sudo. 
  • db-backup.sh
  • db-restore.sh
The backup and restore script files are available in the
util
directory.
Back Up the Database
This section describes how to back up the database.
Follow these steps:
  1. SSH into the system that is running
    API Portal
    .
  2. Change the working directory to
    <installation_dir>/util.
  3. Execute the db-backup.sh script using the following command:
    ./db-backup.sh
    Once executed, the
    postgres_backup-<YYYY-mm-DD-HH-MM-SS>.sql
    is created in the 
    <installation_dir>/backup
    directory.
    CA recommends that the
    <installation_dir>/backup
    directory is backed up to a remote location.
Restore the Database
This section describes how to restore the database to a previously backed up version.
 
Follow these steps:
  1. SSH into the system that is running
    API Portal
    .
  2. Change the working directory to
    <installation_dir>/util.
  3. Execute the db-restore.sh script using the following command:
    ./db-restore.sh ../backup/postgres_backup-2018-02-23-10-51-28.sql
  4. Wait for the restore to complete.
  5. Restart the Portal services by running the following command:
    ./portal.sh