DEV Community

zerox80
zerox80

Posted on

S3-Storage-OpenCloud

Expanding OpenCloud Storage with S3 (Hetzner Example)

OpenCloud’s decomposed storage layout is fast and reliable on a single VPS, but SSDs eventually fill up. The good news: you can keep your existing server, users, and metadata, and offload only the blob data to an S3-compatible object store such as Hetzner’s Object Storage. This article walks through the entire process-from planning and prerequisites to migration, verification, and rollback-and includes multiple concrete examples so you can adapt the steps to your own environment.

Scope: I focus on the opencloud-compose repository here.


1. Understand the Architecture You Are About to Change

Before touching production data, it helps to know how OpenCloud stores files internally:

  • Metadata (directory structure, .mpk metadata files, symlinks, et cetera) lives in the local filesystem under storage/users. That portion remains on your VPS even after switching to S3.
  • Blobs (actual binary file content) are written to a blobstore interface. The default driver decomposed writes them to disk alongside metadata. The decomposeds3 driver keeps metadata locally but streams blobs to an S3 bucket.
  • Service switching is controlled by the environment variable STORAGE_USERS_DRIVER. Only one blobstore driver is active per storage-users instance.

Therefore, moving to S3 means migrating only the blob portion. Users, spaces, shares, and app configuration stay untouched.

Example: On a server where /var/lib/opencloud is mounted on a 200 GB SSD, metadata might consume 10 GB while blobs consume 180 GB. By switching to S3, the SSD only needs to host the 10 GB of metadata plus some growth, while the bucket scales independently.


2. Prerequisites and Pre-Flight Checklist

  1. Existing OpenCloud deployment created with docker compose from this repo.
  2. Hetzner Cloud project (or another S3-compatible provider) with Object Storage enabled.
  3. Command-line access to the host that runs Docker.
  4. Backups: create a snapshot or copy of /var/lib/opencloud. You should be able to roll back if anything misbehaves.

Example Pre-flight Script:

# Stop any cron jobs or user logins that may write data
sudo systemctl stop opencloud-cron.service || true

# Create a quick tarball of metadata only (fast and small)
tar -czf /root/opencloud-metadata-backup.tgz \
  /var/lib/opencloud/storage/users --exclude 'blobs'
Enter fullscreen mode Exit fullscreen mode

3. Prepare the Hetzner Bucket

3.1 Create the bucket in the Hetzner console

  1. Sign in to the Hetzner Cloud Console and pick your project.
  2. Navigate to Storage Boxes & Buckets → Buckets → Create Bucket.
  3. Choose the region closest to your VPS (for example fsn1 for Falkenstein). Hetzner derives the endpoint from this choice, e.g. https://fsn1.my-project.s3.hetzner.cloud.
  4. Give the bucket a globally unique name such as opencloud-production and note it down for the .env file.
  5. (Optional) Enable bucket versioning right away if you want point-in-time recovery. You can toggle it later in the bucket settings tab.

3.2 Create minimally privileged credentials

  1. Open Storage Boxes & Buckets → Access Keys → Create Access Key.
  2. Name the key opencloud-prod (or similar) and restrict its scope to the bucket you just created.
  3. Download the access key ID and secret exactly once and store them in your password manager or a secure vault such as pass, HashiCorp Vault, or 1Password.
  4. Avoid reusing the root project keys; every environment (prod, staging, dev) should have its own pair so you can revoke compromised credentials quickly.

3.3 Harden the bucket

  1. Network restrictions: if your OpenCloud host has a static IP, add an IP condition to the bucket policy so only that address can talk to the API.
  2. Read/write separation: if you expose the bucket to other services (for example backups), create separate keys with read-only permissions.
  3. Lifecycle rules: configure automatic transitions or deletion of incomplete multipart uploads to keep costs predictable (Bucket → Lifecycle Policies → Add Rule).
  4. Server-side encryption: toggle SSE in the bucket settings if you want Hetzner to encrypt objects at rest. When enabled, set DECOMPOSEDS3_SERVER_SIDE_ENCRYPTION=SSE-S3 in .env.
  5. Monitoring: enable the built-in usage alerts (Project → Usage) so you get notified when traffic or storage surpasses a defined threshold.

Example Bucket Policy Snippet (JSON) restricting access to a single server IP:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {"AWS": ["*"]},
      "Action": "s3:*",
      "Resource": [
        "arn:hetzner:s3:::opencloud-production",
        "arn:hetzner:s3:::opencloud-production/*"
      ],
      "Condition": {
        "IpAddress": {"aws:SourceIp": "203.0.113.10/32"}
      }
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Adjust the ARN and source IP to match your environment.

Tip: If your VPS is behind a dynamic IP, skip the IP restriction and instead rotate the access key periodically. You can script rotation with mc admin user svcacct or Hetzner’s API and update the .env file via Ansible.


4. Wire S3 Settings into Docker Compose

  1. Inside opencloud-compose, copy .env.example (or the new .env.s3.example from this repo) to .env if you have not already: cp .env.s3.example .env. The dedicated .env.s3.example contains sane defaults for Traefik, the decomposeds3 overlay, and placeholders for Hetzner credentials so you can get started faster without editing the longer official template.
  2. Append the S3 variables:
   DECOMPOSEDS3_ENDPOINT=https://fsn1.your-project.s3.hetzner.cloud
   DECOMPOSEDS3_REGION=fsn1
   DECOMPOSEDS3_BUCKET=opencloud-production
   DECOMPOSEDS3_ACCESS_KEY=hetzner-access-key
   DECOMPOSEDS3_SECRET_KEY=hetzner-secret-key
   DECOMPOSEDS3_EVENTS_NUM_CONSUMERS=5
   STORAGE_USERS_DECOMPOSEDS3_MAX_CONCURRENCY=64
   DECOMPOSEDS3_PUT_OBJECT_NUM_THREADS=8
   DECOMPOSEDS3_PUT_OBJECT_PART_SIZE=134217728
   DECOMPOSEDS3_PUT_OBJECT_DISABLE_MULTIPART=false
   DECOMPOSEDS3_PUT_OBJECT_SEND_CONTENT_MD5=true
Enter fullscreen mode Exit fullscreen mode
  1. Include the storage overlay:

    • Option A: add storage/decomposeds3.yml to COMPOSE_FILE in .env, e.g.
     COMPOSE_FILE=docker-compose.yml:storage/decomposeds3.yml:traefik/opencloud.yml
    
  • Option B: pass -f storage/decomposeds3.yml every time you run docker compose.

The overlay changes STORAGE_USERS_DRIVER to decomposeds3, keeps system data on disk, and forwards the DECOMPOSEDS3_* values into the container.

Example: To test the overlay without touching production, you can run docker compose --env-file .env.example -f docker-compose.yml -f storage/decomposeds3.yml config | grep STORAGE_USERS_DRIVER and confirm the driver is decomposeds3.


5. Switch OpenCloud to S3

  1. Ensure .env contains the DECOMPOSEDS3_* entries (plus the tuning values from section 4.1) and the overlay is active.
  2. Restart the stack:
   docker compose down
   docker compose up -d
Enter fullscreen mode Exit fullscreen mode
  1. Tail logs:
   docker compose logs -f opencloud | grep -i storage-users
Enter fullscreen mode Exit fullscreen mode

You should see messages confirming that the service connects to the S3 endpoint.

Common Log Example:

time="2025-11-15T12:00:12Z" level=info msg="connected to s3" bucket=opencloud-production driver=decomposeds3
Enter fullscreen mode Exit fullscreen mode

If you see authentication errors, double-check the keys, endpoint URL, and region.


6. Performance and Cost Considerations

  • Latency: Uploading to S3 introduces network latency. Benchmark uploads of large files after the switch. If speeds drop noticeably, tweak STORAGE_USERS_DECOMPOSEDS3_PUT_OBJECT_NUM_THREADS and …PART_SIZE.
  • Costs: Hetzner bills per GB stored and per GB transferred out of the region. Calculate monthly cost by multiplying average stored size by the storage price, and add expected egress.
  • Caching: Because metadata remains on SSD, path traversal stays fast. Only blob reads/writes incur network costs.

Performance tuning variables now live in section 4.1 so you can wire them in while editing the .env. Revisit those recommendations whenever you resize the VPS or bucket workload.

Example Benchmark Command:

# Upload a 5 GB test file before and after migration
dd if=/dev/urandom of=/tmp/5gb.bin bs=1M count=5120
/usr/bin/time -v opencloud clients upload /tmp/5gb.bin
Enter fullscreen mode Exit fullscreen mode

Compare timings to evaluate the new setup.


7. Rollback Strategy

If you encounter a blocking issue:

  1. Restore your previous .env (without the S3 overlay) or remove storage/decomposeds3.yml from COMPOSE_FILE.
  2. Ensure STORAGE_USERS_DRIVER=decomposed.
  3. Restart the stack. Because metadata and original blobs never left the disk, OpenCloud returns to the old state immediately.
  4. Investigate the issue offline, fix it, then attempt the migration again.

Keep the S3 bucket intact during rollback so you can resume later without losing uploaded data.


8. Frequently Asked Questions

Q: Can I keep some spaces on local storage and others on S3?

A: Not within a single storage-users instance. You would need two providers and the dual-provider strategy described earlier.

Q: Does Hetzner Object Storage support server-side encryption?

A: Yes. You can enable it by adding DECOMPOSEDS3_SERVER_SIDE_ENCRYPTION=SSE-S3 and ensuring the bucket is configured accordingly.

Q: What about backups once blobs live in S3?

A: Continue backing up metadata locally. For blobs, enable bucket versioning or replicate to another region. Hetzner offers lifecycle policies for that.

Q: How do I monitor transfer costs?

A: Use Hetzner’s usage dashboard or script mc admin trace to log API calls. Combine this with OpenCloud’s access logs to spot heavy users.

Q: Can I use AWS S3, Wasabi, or MinIO instead?

A: Absolutely. Replace the endpoint/region with the provider-specific values. The driver is compatible with any S3 API.


9. Conclusion

Migrating OpenCloud’s blobstore to Hetzner S3 requires careful planning but pays off with elastic storage, predictable costs, and simpler scaling..

Happy scaling-and remember to keep those local metadata backups handy even after the move!

Top comments (0)