PostgreSQL restore/backup
An auto-restoring Postgres server running on Akash, with backups taken on a configurable schedule. Backups are stored on decentralised storage using Filebase.
Ultimately this is a two container setup, one PostgreSQL server and one scheduler container to restore the database on boot, and run a cronjob to back it up.

Usage

  • Setup a Filebase account and bucket (or any S3 compatible storage host).
  • Set the environment variables in the deploy.yml and deploy on Akash
  • Use the URL and port Akash gives you to connect to the Postgres server, with the credentials you provided in the environment variables. For example cluster.ewr1p0.mainnet.akashian.io:31234

Using with an app container

Alternatively add your own app container to the deploy.yml and expose the Postgres 5432 port to your application only for a local server.
For example:
1
services:
2
app:
3
image: myappimage:v1
4
depends_on:
5
- service: postgres
6
cron:
7
image: ghcr.io/ovrclk/akash-postgres-restore:v0.0.4
8
env:
9
- POSTGRES_PASSWORD=password
10
...
11
depends_on:
12
- service: postgres
13
postgres:
14
image: postgres:12.6
15
env:
16
- POSTGRES_PASSWORD=password
17
expose:
18
- port: 5432
19
to:
20
- service: app
21
- service: cron
Copied!

Environment variables

  • POSTGRES_USER=postgres - your Postgres server username
  • POSTGRES_PASSWORD=password - your Postgres server password
  • POSTGRES_HOST=postgres - postgres server host, whatever you named it in deploy.yml
  • POSTGRES_PORT=5432 - postgres port, will be 5432 unless you aliased it in deploy.yml
  • POSTGRES_DATABASE=akash_postgres - name of your database
  • BACKUP_PATH=bucketname/path - bucket and path for your deployments. Make sure directories exist first
  • BACKUP_KEY=key - your Filebase access key
  • BACKUP_SECRET=secret - your Filebase secret
  • BACKUP_PASSPHRASE=secret - a passphrase to encrypt your backups with
  • BACKUP_HOST=https://s3.filebase.com - the S3 backup host, this defaults to Filebase but can be any S3 compatible host
  • BACKUP_SCHEDULE=*/15 * * * * - the cron schedule for backups. Defaults to every 15 minutes
  • BACKUP_RETAIN=7 days - how many days to keep backups for

Development

You can run the application locally using Docker compose.
Copy the .env.sample file to .env and populate
Run docker-compose up to build and run the application
Last modified 5mo ago