Longhorn provides automated snapshots and backups of persistent volumes to S3-compatible storage (MinIO). This guide explains how to set up, configure, and use this functionality.
Backup behavior:
- Snapshots: Taken hourly for all volumes (configurable with
longhorn:snapshotCron
) - Incremental Backups: Run daily at 00:15 (configurable with
longhorn:backupCron
) - If a volume has no changes since the last backup, no data is transferred
Please refer to the official MinIO installation documentation for detailed instructions on setting up MinIO: [https://min.io/docs/minio/user-guide/install.html]
Make sure MinIO is installed and functioning before enabling backups. See MinIO installation instructions for details.
Now let's create an S3 Bucket for Longhorn backups:
- Access the MinIO web interface at
https://minio.<tsnet>.ts.net/
- Create a new bucket named
backup-longhorn
(or your preferred name) - Create new access keys with the following policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "GrantLonghornBackupstoreAccess0",
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:ListBucket",
"s3:DeleteObject"
],
"Resource": ["arn:aws:s3:::backup-longhorn", "arn:aws:s3:::backup-longhorn/*"]
}
]
}
Add the S3 access keys to Pulumi config:
# Store S3 credentials securely
pulumi config set longhorn:backupAccessKeyId <key_id> --secret
pulumi config set longhorn:backupAccessKeySecret <key_value> --secret
# (Optional) Customize S3 bucket name/path
pulumi config set longhorn:backupTarget s3://backup-longhorn@lab/
You can configure which volumes to back up through two main approaches:
Enable automatic backups for all volumes in the cluster, with the ability to exclude specific volumes:
# Enable backup functionality
pulumi config set longhorn:backupEnabled true
# Back up all volumes by default
pulumi config set longhorn:backupAllVolumes true
# Optional: Exclude specific volumes from backup
pulumi config set <app>:backupVolume false
pulumi up
Only back up volumes that are explicitly configured for backup:
# Enable backup functionality
pulumi config set longhorn:backupEnabled true
# Don't back up volumes by default (this is the default setting)
pulumi config set longhorn:backupAllVolumes false
# Enable backup for specific application volumes
pulumi config set <app>:backupVolume true
pulumi up
The backup setting precedence is:
- App-specific setting (
<app>:backupVolume
) if specified - Global setting (
longhorn:backupAllVolumes
) if no app-specific setting exists
There are two ways to restore volumes from backups:
You can directly restore from a backup by providing the S3 URL in your application configuration:
pulumi config set <app>:fromBackup "s3://backup-longhorn@lab/?backup=backup-12345&volume=my-volume"
Notes:
- The S3 URL must be copied exactly from the Longhorn UI's backup page
- Navigate to Backup → select backup → Copy URL
- Volumes are provisioned dynamically with system-generated names
For more control over the process and to get meaningful volume names:
- Restore the volume through the Longhorn UI first
- Use the
fromVolume
parameter to attach the existing volume:
# First, restore volume through Longhorn UI and note its name
pulumi config set <app>:fromVolume "my-restored-volume"
This approach gives you better volume naming and allows you to verify the restore before attaching it to your application.