Remote Setup
import { Tabs, TabItem } from ‘@astrojs/starlight/components’;
This guide covers setting up different remote storage backends for pgbranch.
Remote Management Commands
Section titled “Remote Management Commands”# Add a new remotepgbranch remote add <name> <url>
# List configured remotespgbranch remote list
# Remove a remotepgbranch remote remove <name>
# Set default remotepgbranch remote set-default <name>
# List branches on a remotepgbranch remote ls-remoteStorage Backend Setup
Section titled “Storage Backend Setup”AWS S3
Section titled “AWS S3”Prerequisites
Section titled “Prerequisites”- AWS account with S3 access
- IAM user with S3 permissions
- Access Key ID and Secret Access Key
Required IAM Permissions
Section titled “Required IAM Permissions”{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:GetObject", "s3:PutObject", "s3:DeleteObject", "s3:ListBucket" ], "Resource": [ "arn:aws:s3:::your-bucket-name", "arn:aws:s3:::your-bucket-name/*" ] } ]}Add Remote
Section titled “Add Remote”pgbranch remote add origin s3://your-bucket-name/pgbranchYou’ll be prompted for:
- AWS Access Key ID
- AWS Secret Access Key
- AWS Region (e.g.,
us-east-1)
Configuration
Section titled “Configuration”The remote is stored in .pgbranch/config.json:
{ "remotes": { "origin": { "name": "origin", "type": "s3", "url": "s3://your-bucket-name/pgbranch", "options": { "region": "us-east-1", "accessKeyId": "[encrypted]", "secretAccessKey": "[encrypted]" } } }, "defaultRemote": "origin"}MinIO (Self-Hosted S3)
Section titled “MinIO (Self-Hosted S3)”MinIO provides S3-compatible storage you can self-host.
Prerequisites
Section titled “Prerequisites”- MinIO server running
- Access credentials
Add Remote
Section titled “Add Remote”pgbranch remote add minio s3://bucket-name/pgbranchWhen prompted, provide:
- Access Key
- Secret Key
- Endpoint URL (e.g.,
http://localhost:9000)
Example with Custom Endpoint
Section titled “Example with Custom Endpoint”pgbranch remote add minio s3://pgbranch-bucket/snapshots# Access Key: minioadmin# Secret Key: minioadmin# Endpoint: http://minio.local:9000Docker MinIO Setup
Section titled “Docker MinIO Setup”Quick MinIO setup for testing:
docker run -d \ --name minio \ -p 9000:9000 \ -p 9001:9001 \ -e MINIO_ROOT_USER=minioadmin \ -e MINIO_ROOT_PASSWORD=minioadmin \ minio/minio server /data --console-address ":9001"Then create a bucket via the MinIO console at http://localhost:9001.
Cloudflare R2
Section titled “Cloudflare R2”R2 offers S3-compatible storage with no egress fees.
Prerequisites
Section titled “Prerequisites”- Cloudflare account
- R2 subscription enabled
- R2 bucket created
- API token with R2 permissions
Add Remote
Section titled “Add Remote”pgbranch remote add r2 r2://account-id/bucket-name/prefixYou’ll be prompted for:
- Access Key ID (R2 token)
- Secret Access Key
- Account ID (from Cloudflare dashboard)
Getting R2 Credentials
Section titled “Getting R2 Credentials”- Go to Cloudflare Dashboard → R2
- Click “Manage R2 API Tokens”
- Create a token with “Object Read & Write” permissions
- Copy the Access Key ID and Secret Access Key
Example
Section titled “Example”pgbranch remote add r2 r2://abc123def456/pgbranch-snapshots/dev# Access Key ID: [your-r2-access-key]# Secret Access Key: [your-r2-secret-key]Local Filesystem
Section titled “Local Filesystem”Use a local or network-mounted directory for storage.
Add Remote
Section titled “Add Remote”# Absolute pathpgbranch remote add local /path/to/storage
# File URL formatpgbranch remote add local file:///path/to/storageNo credentials are required for filesystem storage.
Use Cases
Section titled “Use Cases”- Network shares: Mount a NAS or network drive
- Local backup: Store on a different disk
- Testing: Try remotes without cloud setup
Example with NAS
Section titled “Example with NAS”# Mount NAS firstmount -t nfs nas.local:/shared /mnt/nas
# Add as remotepgbranch remote add nas /mnt/nas/pgbranch-snapshotsPermissions
Section titled “Permissions”Ensure the directory is writable:
mkdir -p /path/to/storagechmod 755 /path/to/storageManaging Remotes
Section titled “Managing Remotes”List Remotes
Section titled “List Remotes”pgbranch remote listOutput:
origin (default) Type: s3 URL: s3://my-bucket/pgbranch
backup Type: filesystem URL: /backups/pgbranchSet Default Remote
Section titled “Set Default Remote”pgbranch remote set-default backupThe default remote is used when you don’t specify --remote:
pgbranch push main # Uses default remotepgbranch push main -r origin # Uses 'origin' remoteRemove a Remote
Section titled “Remove a Remote”pgbranch remote remove backupThis only removes the configuration; branches already pushed remain in storage.
List Remote Branches
Section titled “List Remote Branches”# List branches on default remotepgbranch remote ls-remote
# List branches on specific remotepgbranch remote ls-remote -r originOutput:
main Pushed: 2024-01-15 10:30:00 Size: 45 MB Description: Initial schema with seed data
feature-auth Pushed: 2024-01-16 14:22:00 Size: 48 MBSkip Credentials Prompt
Section titled “Skip Credentials Prompt”For automation or when using environment variables:
pgbranch remote add origin s3://bucket/prefix --no-credentialsThen set credentials via environment variables:
AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYAWS_REGION
Multiple Remotes
Section titled “Multiple Remotes”You can configure multiple remotes for different purposes:
# Team shared storagepgbranch remote add team s3://team-bucket/pgbranch
# Personal backuppgbranch remote add personal r2://account/personal-bucket/pgbranch
# Local fast accesspgbranch remote add local /mnt/fast-ssd/pgbranch
# Set team as defaultpgbranch remote set-default teamPush to specific remotes:
pgbranch push main -r teampgbranch push main -r personalTroubleshooting
Section titled “Troubleshooting”Connection Refused
Section titled “Connection Refused”Error: could not connect to remote: connection refused- Check the endpoint URL
- Verify network connectivity
- For MinIO, ensure the server is running
Access Denied
Section titled “Access Denied”Error: access denied to bucket- Verify credentials are correct
- Check IAM permissions (S3)
- Ensure bucket exists
Invalid Credentials
Section titled “Invalid Credentials”Error: invalid credentials- Re-add the remote with correct credentials
- Check for typos in access keys
- Verify the credentials haven’t been rotated