a small tool for backing up postgres databases to backblaze b2
Note: This project is in early development, and versioning is a little different. Read this for more details.
Why should you care?
Are you running a database on a linux box? What if that box suddenly is destroyed? Back up your databases so that in the event of a catastrophe, all is well. Backblaze B2 is the lowest cost long term storage backup service on the market, and the first 10gb are free, so you will pay little-to-nothing for your peace of mind.
npm install pg-backup -g
Note: Postgresql must also be installed in order for pg-backup to work
In order to use the CLI, you first must configure it with your backblaze b2 API keys. To do this, run:
$ pg-backup --account-id xxx --application-key xxx --bucket-id xxx
You can get the account id and application key from the b2 dashboard. You'll also need to create a new bucket for your database backups. Once the bucket has been created, it will show you the bucket id.
You can change your configuration details at any time. Once you have successfully authenticated, you can start backing up your databases. Test it out by backing up a database one time, manually, as such:
$ pg-backup --dbname database-name
If you'd like to have the database backed up at regular intervals, you can use the
--schedule option. For example:
$ pg-backup --dbname database-name --schedule daily
You can have databases backed up
monthly. Note that
pg-backup will simply create a cron script to run these backups, so you must have crontab active and working in order to use the schedule option.
If you wish to use
pg-backup through node.js, it exports a class that can be used to easily control your backups. First, you need to initialize the class with your backblaze credentials, as such:
const PgBackup =const backup =accountId: 'xxx'applicationKey: 'xxx'bucketId: 'xxx'
Now you can quickly back up a single database with the
run instance method, which returns a promise:
Since we depend on B2 in order for this to work, you need a B2 account in order to run the tests. In order to add your b2 account details, run
cp test/.env.sample test/.env, then fill in
test/.env with your account details. Make sure that you make a new bucket for testing specifically.