Ensuring the safety and integrity of your financial data on a Blnk server is crucial. This enhanced guide covers the process of backing up your PostgreSQL database, including setup instructions, verification, storage best practices, and restoration steps.

Before you start

Before initiating your first backup, ensure your Blnk server environment is correctly configured. This includes setting up the backup directory with appropriate permissions, ensuring your Blnk server has access to this directory, and updating the Blnk configuration file to recognize the backup directory.

Here are the prerequisites:

  • Docker 20.10.11 or later
  • Compose 1.29.2 or later
  • Basic understanding of cron jobs (for Linux/macOS) or Task Scheduler (for Windows)
  • Familiarity with command-line interfaces and shell scripting

Configuring the backup directory

1

Create a backup directory

Choose a secure location on your server to store the backup files. For example, /var/backups/blnk.

bash
mkdir -p /var/backups/blnk
2

Set permissions

Adjust the directory permissions to ensure that the Blnk server can write to this directory.

bash
chown youruser:yourgroup /var/backups/blnk
chmod 700 /var/backups/blnk

Replace youruser:yourgroup with the user and group that your Blnk server runs as. This step is crucial for preventing unauthorized access to your backup files.

3

Update the Blnk configuration file

Modify your blnk.json configuration file to include the path to the backup directory. This tells the Blnk server where to save the backup files.

Open your blnk.json file in a text editor and add the backup_dir key with the path to your backup directory:

blnk.json
{
  ...
  "backup_dir": "/var/backups/blnk",
  ...
}

Save the changes to your configuration file. This step ensures that when the Blnk server initiates a backup, it correctly locates the directory to store the backup files.

Automating backups

Automating the backup process ensures your data is regularly backed up without manual intervention.

1

Create a backup script

Create a script named backup.sh that triggers the Blnk server to back up to disk using the /backup route.

backup.sh
#!/bin/bash
curl -X POST http://yourdomain.com:5001/backup
2

Schedule the backup with Cron

Use cron (Linux/macOS) or Task Scheduler (Windows) to schedule your backup script. For example, to run the backup daily at 2 AM:

cron
0 2 * * * /path/to/backup_blnk.sh

Best practices for backup storage to disk

  • Off-site Storage: Regularly copy your backups to an off-site location or cloud storage to protect against local disasters.
  • Encryption: Encrypt your backup files to protect sensitive data from unauthorized access.
  • Retention Policy: Implement a retention policy to manage the lifecycle of your backups, ensuring that you keep only what’s necessary and avoid unnecessary storage costs.

Restoring from a Backup

In the event of data loss or corruption, having a reliable backup is crucial. Here’s how to restore your Blnk database from a backup file:

1

Locate your backup file

Identify the most recent or appropriate backup file for your restoration needs.

2

Restore the database

Use the PostgreSQL pg_restore command or a similar tool provided by Blnk to restore your database from the backup file.

bash
pg_restore -d yourdatabase /path/to/yourbackupfile
3

Verify the restoration

Ensure that the restoration process was successful and that your Blnk application is functioning correctly.

Need help?

We are very happy to help you make the most of Blnk, regardless of whether it is your first time or you are switching from another tool.

To ask questions or discuss issues, please join our Discord community.

Get access to Blnk Cloud.

Manage your Blnk Ledger and explore advanced features (access control & collaboration, anomaly detection, secure storage & file management, etc.) in one dashboard.