How to Back Up to Object Storage (S3-Compatible)

S3-compatible object storage provides durable, cost-effective off-site backup storage — separate from your VPS provider's infrastructure entirely, satisfying the "off-site" requirement of the 3-2-1 backup rule.

Why Use Object Storage for Backups

  • Genuinely off-site, independent of your VPS provider
  • Highly durable, designed for long-term data retention
  • Pay only for storage used, typically inexpensive for backup-sized data volumes
  • Accessible via a standard, widely-supported API (S3-compatible)

Prerequisites

  • An account with an S3-compatible object storage provider
  • A bucket created for backups
  • Access key and secret key credentials

Step 1 — Install the AWS CLI (Works with Any S3-Compatible Provider)

sudo apt install awscli -y

Step 2 — Configure Credentials

aws configure --profile backup

Enter your access key, secret key, and region when prompted. For non-AWS S3-compatible providers, you'll specify a custom endpoint in each command.

Step 3 — Test the Connection

aws s3 ls --profile backup --endpoint-url https://YOUR_PROVIDER_ENDPOINT

Step 4 — Upload a Backup File Manually (Test)

aws s3 cp backup.sql.gz s3://your-backup-bucket/ --profile backup --endpoint-url https://YOUR_PROVIDER_ENDPOINT

Step 5 — Automate the Full Backup-and-Upload Process

sudo nano /usr/local/bin/backup-to-s3.sh
#!/bin/bash
TIMESTAMP=$(date +%F)
BACKUP_DIR="/var/backups"
FILENAME="db-backup-$TIMESTAMP.sql.gz"

mysqldump -u root --all-databases | gzip > "$BACKUP_DIR/$FILENAME"

aws s3 cp "$BACKUP_DIR/$FILENAME" \
  s3://your-backup-bucket/ \
  --profile backup \
  --endpoint-url https://YOUR_PROVIDER_ENDPOINT

find "$BACKUP_DIR" -type f -mtime +7 -delete
sudo chmod +x /usr/local/bin/backup-to-s3.sh

Step 6 — Schedule It

sudo crontab -e
0 2 * * * /usr/local/bin/backup-to-s3.sh >> /var/log/s3-backup.log 2>&1

Setting Up Lifecycle Rules for Automatic Cleanup

Most S3-compatible providers support bucket lifecycle policies that automatically delete objects older than a set number of days — configure this in your provider's console to handle retention without needing custom cleanup scripts on the remote end.

Restoring from Object Storage

aws s3 cp s3://your-backup-bucket/db-backup-2026-08-01.sql.gz . \
  --profile backup \
  --endpoint-url https://YOUR_PROVIDER_ENDPOINT

gunzip -c db-backup-2026-08-01.sql.gz | mysql -u root -p

Encrypting Backups Before Upload (Recommended for Sensitive Data)

gpg --symmetric --cipher-algo AES256 backup.sql.gz

Upload the resulting .gpg file instead of the plain backup, keeping the decryption passphrase stored securely and separately.

Common Errors

"Access Denied" — verify the access key has write permissions on the specific bucket.

Upload fails silently in cron — ensure the script uses absolute paths and redirects output to a log file for debugging, as covered in How to Schedule Tasks with Cron on a Linux VPS.

Best Practices

  • Encrypt sensitive backups before uploading
  • Set bucket lifecycle rules for automatic retention management
  • Test restoring from object storage periodically, not just the upload step

Related Articles

  • Backup Strategy 101: The 3-2-1 Rule Explained
  • How to Set Up Automated VPS Backups (rsync, cron & Off-Site Storage)
  • How to Test and Verify Your Backups Actually Work
  • s3 backup, object storage, offsite backup, aws cli backup
  • 0 Корисниците го најдоа ова како корисно
Дали Ви помогна овој одговор?

Понудени резултати

Backup Strategy 101: The 3-2-1 Rule Explained

Before diving into specific backup tools, it's worth understanding the industry-standard...

How to Test and Verify Your Backups Actually Work

A backup that has never been restored is not a verified backup — it's an assumption. This...

How to Create a Disaster Recovery Plan for Your VPS

A disaster recovery (DR) plan is a documented, tested procedure for restoring service after a...

How to Use VPS Provider Snapshots Effectively

Most VPS providers offer a snapshot feature — a point-in-time image of your entire server....

How to Back Up and Restore WordPress Completely

WordPress backups need to cover two distinct pieces: the database (posts, settings, users) and...