Safeguarding your financial data on a Blnk server involves not only local backups but also utilizing cloud storage solutions like Amazon S3 for offsite storage.

This guide provides detailed instructions on setting up backups to Amazon S3, including configuration steps, scheduling, and verification processes.

Prerequisites

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

Configuring Amazon S3 Access

Before setting up the backup process, you need to configure your Blnk server to access your Amazon S3 bucket.

1

Create an IAM user and policy

  1. Log in to your AWS Management Console and navigate to the IAM (Identity and Access Management) service.
  2. Create a new IAM user with programmatic access. This will generate an access key ID and secret access key, which you’ll use to configure the Blnk server.
  3. Attach a policy to the IAM user that grants necessary permissions to write to the S3 bucket. You can use the AmazonS3FullAccess policy or create a custom policy with more restricted access.
2

Configure S3 bucket

  1. Create an S3 bucket in your AWS account if you have not already. Note the bucket name and region.
  2. Set up bucket policies or access control lists (ACLs) as necessary to allow the IAM user to write backups to the bucket.
3

Update Blnk configuration

Modify your blnk.json configuration file to include the AWS access key ID, secret access key, bucket name, and region. This enables the Blnk server to authenticate with AWS S3 and store backups in your bucket.

blnk.json
{
  ...
  "aws_access_key_id": "YOUR_ACCESS_KEY_ID",
  "aws_secret_access_key": "YOUR_SECRET_ACCESS_KEY",
  "s3_bucket_name": "YOUR_BUCKET_NAME",
  "s3_region": "YOUR_BUCKET_REGION",
  ...
}

Automating S3 backups

After configuring access to Amazon S3, the next step is to automate the backup process.

1

Create a backup script

Create a script named backup_to_s3.sh that triggers the Blnk server to back up to S3 using the /backup-s3 route.

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

Ensure to replace http://yourdomain.com:5001 with your actual Blnk server domain and port.

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_to_s3.sh

Best practices for backup storage to Amazon S3

  • Encryption: Enable server-side encryption (SSE) for your S3 bucket to protect your backups at rest.
  • Versioning: Enable versioning for your S3 bucket to keep multiple versions of your backups, providing additional protection against accidental deletion or overwriting.
  • Lifecycle policies: Implement lifecycle policies to automatically transition older backups to more cost-effective storage classes and purge outdated backups.

Restoring from an S3 Backup

To restore your Blnk database from a backup stored in S3:

1

Download the backup file

Use the AWS CLI, S3 console, or an S3 client to download the desired backup file from your S3 bucket.

2

Restore the database

Follow the same steps as local restoration, using the pg_restore command with the path to the downloaded backup file.

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

Verify the restoration

Ensure the Blnk application functions correctly and all data is intact post-restoration.

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.