OpenResty Edge Database Backup

1. Preamble

We use PostgreSQL as the database for Edge. We usually refer to the database used by Edge Admin as Edge Admin DB. The Edge Admin DB stores all the configuration information of the application, and once the database is corrupted, it cannot be restored, so it is better to make regular backups of the Edge Admin DB.

2. Download the Script

We provide a script that supports backing up Edge Admin DB to a specified local directory, and also supports synchronizing backup files to a remote machine.

Login to the Edge Admin DB machine and execute the following command to download the script to the current directory.

curl -O

3. Execute the Script Manually

The script usage is as follows.

    sudo bash [backup_dir] [backup_count] [remote_user?]@[remote_host?]:[remote_port?] [remote_dir?]

    backup_dir         the local directory for database backup files
    backup_count       number of backup files to keep, old backups will be cleaned up automatically
    remote_host        the ssh host of the remote machine used for rsync synchronization backups (optional)
    remote_user        the ssh user of the remote machine (optional)
    remote_port        the ssh port of the remote machine (optional)
    remote_dir         the remote directory for database backup files (optional)

    sudo bash /local/db_backup 10
    sudo bash /local/db_backup 10 /remote/db_backup
    sudo bash /local/db_backup 10 /remote/db_backup
    sudo bash /local/db_backup 10 root@ /remote/db_backup

There are several points to note.

  • The script execution should be done as much as possible when the business is not busy and the execution time is related to the data volume.
  • The backup_dir needs to be on a different disk than the Edge Admin DB, otherwise, when the disk where the database is located is corrupted, the backup file will be corrupted as well.
  • The backup_count needs to be adjusted according to the disk capacity, when the count limit is exceeded, the oldest backup file will be cleaned after each backup.
  • We strongly recommend configuring remote_host to synchronize backup files to another machine as well.

After successful execution of the script, the final output will be:

> Edge Admin database backup successfully!

4. Configure crontab

After executing the script manually and verifying its success, we can configure the backup to be performed regularly via crontab.

Here we provide an example of a daily scheduled configuration.

0 1 * * * sudo bash /path/to/  /local/db_backup 10 /remote/db_backup >> /tmp/backup.log 2>&1

The output of the scheduled backup script is in /tmp/backup.log, you can check /tmp/backup.log or check the file in the backup directory to confirm that the task was executed successfully.