Skip to content

Automating Backups to S3 or R2

The Plausible Community Edition doesn’t automatically back up your data on its own. Fortunately, the Plausible Bootstrapper can automatically set up a cron job to back up your analytics data to a remote S3 (AWS) or R2 (Cloudflare) bucket.

Getting Started

Before running the Bootstrapper on a new machine, you’ll need an R2 or S3 bucket. You can get this from Cloudflare or AWS, respectively.

Environment Variables

When the following variables are exported in your terminal session, the backup process will execute automatically.

Environment VariableRequired?Description
PB_BACKUP_ACCESS_KEY_IDYesFor Cloudflare, see here. For AWS, see here.
PB_BACKUP_SECRET_ACCESS_KEYYesYou’ll have this once you perform the stuff noted directly above.
PB_BACKUP_ENDPOINT_URLYesFind this value based on your provider by reading below.
PB_BACKUP_CRON_SCHEDULENoThe by cron schedule used to perform backups.
By default, it’s 0 2 * * * (2AM every morning).
PB_BACKUP_BUCKET_NAMENoThe name of the bucket data used to store backup data.
It’s “plausible-backups” by default.
By default, it’s 0 2 * * * (2AM every morning).

Once you have these values, export them in your terminal session before executing the Bootstrapper, along with other required environment variables:

Terminal window
export PB_ADMIN_EMAIL=test@example.com
export PB_BASE_URL=https://your_domain_here
# backup-specific variables
export PB_BACKUP_ACCESS_KEY_ID=AKIABLAHBLAHBLAH
export PB_BACKUP_SECRET_ACCESS_KEY=1234blahblahblah
export PB_BACKUP_ENDPOINT_URL=https://s3.us-east-2.amazonaws.com
export PB_BACKUP_BUCKET_NAME=plausible-backups-s3
export PB_BACKUP_CRON_SCHEDULE='0 5 * * *'

Once these are set, you can begin the setup process.

Verifying the Job

To verify the job is set up & active, run the following in your machine’s terminal.

Terminal window
crontab -l

You should see output similar to this:

Terminal window
root@78826265346c:/opt/plausible# crontab -l
0 2 * * * /opt/plausible/backup.sh

Finding Your Endpoint URL

Specifying an endpoint URL is required for setting up a backup job. Find it based on your provider here:

Using AWS

If you’re using an S3 bucket on AWS, use the endpoint based on your region listed here. For example, if you’re on us-east-1, that value would be s3.us-east-1.amazonaws.com.

Using R2

If you’re using an R2 bucket with Cloudflare, your URL endpoint will be https://<ACCOUNT_ID>.r2.cloudflarestorage.com, as indicated here.