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 Variable | Required? | Description |
---|---|---|
PB_BACKUP_ACCESS_KEY_ID | Yes | For Cloudflare, see here. For AWS, see here. |
PB_BACKUP_SECRET_ACCESS_KEY | Yes | You’ll have this once you perform the stuff noted directly above. |
PB_BACKUP_ENDPOINT_URL | Yes | Find this value based on your provider by reading below. |
PB_BACKUP_CRON_SCHEDULE | No | The by cron schedule used to perform backups. |
By default, it’s 0 2 * * * (2AM every morning). | ||
PB_BACKUP_BUCKET_NAME | No | The 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:
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.
You should see output similar to this:
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.