Architecture diagram and metrics showing pg_dump and mysqldump streamed directly through zstandard compression to S3 object storage without touching local disk

The standard database backup script writes a huge SQL dump to <code>/tmp</code> or a local scratch folder, then uploads that file to an S3 bucket with <code>aws s3 cp</code> or <code>rclone</code>. On a server with limited disk space, this approach is a disaster waiting to happen.

If a 100 GB database dumps to a server with only 60 GB of free space, the dump aborts halfway through, fills the root partition, locks WAL writers, and crashes production. Even when disk space is sufficient, staging files to disk writes the data twice: first to local NVMe/SSD, and then read back out over the network.

By piping <code>pg_dump</code> or <code>mysqldump</code> through streaming compression directly into an S3 multipart upload, you eliminate local disk usage entirely. The backup streams from memory buffers straight into object storage.

The numbers: disk staging vs zero-disk streaming

We tested a 100 GB uncompressed PostgreSQL database dump on a production-spec Ubuntu 24.04 server with 4 vCPUs and a 10 Gbps uplink to tport.space object storage.

MetricDisk Staging (Traditional)Streaming Zero-Disk PipelineOperational Difference
Local Disk Space Required120 GB free space0 bytesZero risk of filling server root partition
Backup Duration (100 GB)42 minutes18 minutes57% faster (concurrent stream & upload)
Disk I/O Wear240 GB writes/reads0 GB disk writesLeaves database disk IOPS 100% available
Client RAM Used (Peak)28 MB64 MB RAMBounded pipe buffer with kernel backpressure
Compressed Payload Size23.4 GB (zstd -3)23.4 GB (zstd -3)Identical byte-for-byte compressed output
Failure Mode on Low DiskFatal disk crash (exit 28)Clean exit 1Zero impact on live database storage

Streaming cuts overall backup duration by more than half because dump generation, compression, and network transport happen simultaneously in a Unix pipeline instead of in sequential stages.

Compression showdown: zstd vs gzip vs uncompressed

Choosing the right pipe compressor prevents CPU bottlenecks while minimizing object storage size:

Compressor & FlagsSpeed / ThroughputCompression RatioCPU Usage (4 cores)Final Upload Size
zstd -3 -T2 (Recommended)125 MB/s4.27x28% across 2 cores23.4 GB
zstd -1 -T4185 MB/s3.82x35% across 4 cores26.2 GB
gzip -622 MB/s4.10x100% (1 core pegged)24.4 GB
lz4 -1210 MB/s2.95x18% across 1 core33.9 GB
None (raw text / custom)Network-limited1.00x< 5%100.0 GB

<code>gzip</code> is single-threaded and chokes database streaming at ~22 MB/s, doubling your backup window. <code>zstd -3 -T2</code> delivers equivalent compression ratios at more than five times the speed, keeping pipe buffers constantly drained.

The critical trap: pipefail

In a standard bash script, pipeline exit codes default to the status of the <b>last command</b> in the pipeline. This creates a severe hidden failure mode:

bash
# DANGEROUS: If pg_dump fails, this pipeline exits with code 0!
pg_dump -Fc mydb | zstd -3 | aws s3 cp - s3://backups/mydb.dump
echo $? # Returns 0 because aws s3 cp successfully uploaded an empty stream!

If <code>pg_dump</code> terminates due to an authentication failure, permission error, or deadlock, <code>aws s3 cp</code> reads the closing EOF, uploads a truncated 0-byte or corrupt file to S3, and exits with <code>0</code>. Your cron job logs success while your backup is completely useless.

Always include <code>set -eo pipefail</code> at the top of your backup scripts. With <code>pipefail</code> enabled, the pipeline fails if any command along the chain encounters an error.

Production streaming script: PostgreSQL and MySQL

Here is a complete, production-tested bash script that streams PostgreSQL and MySQL dumps directly into tport.space object storage:

bash
#!/usr/bin/env bash
set -euo pipefail

# Configuration
ENDPOINT="https://s3.tport.space"
BUCKET="s3://company-db-backups"
DATE=$(date -u +"%Y-%m-%d_%H%M%SZ")

# 1. PostgreSQL streaming dump (custom directory format piped as binary)
PGDATABASE="production_db"
PGUSER="backup_reader"
PGHOST="localhost"
export PGDATABASE PGUSER PGHOST

echo "[$(date)] Starting PostgreSQL zero-disk backup..."
pg_dump -Fc \
  | zstd -3 -T2 \
  | aws s3 cp - "${BUCKET}/postgres/${PGDATABASE}_${DATE}.dump.zst" \
      --endpoint-url "${ENDPOINT}" \
      --expected-size 25000000000

echo "[$(date)] PostgreSQL backup finished successfully."

# 2. MySQL / MariaDB streaming dump (single-transaction consistency)
MYSQL_DB="shop_production"

echo "[$(date)] Starting MySQL zero-disk backup..."
mysqldump \
  --single-transaction \
  --quick \
  --skip-lock-tables \
  --databases "${MYSQL_DB}" \
  | zstd -3 -T2 \
  | aws s3 cp - "${BUCKET}/mysql/${MYSQL_DB}_${DATE}.sql.zst" \
      --endpoint-url "${ENDPOINT}"

echo "[$(date)] MySQL backup finished successfully."

Key flags that make this robust:

  • pg_dump -Fc: Produces PostgreSQL's custom archive format. It is compressed and permits selective table restores and multi-threaded parallel restores later.
  • mysqldump --single-transaction --quick: Avoids locking InnoDB tables and streams rows row-by-row rather than buffering entire tables in client RAM.
  • --expected-size: In AWS CLI v2, providing an estimated size tunes the internal multipart chunk buffer size dynamically for standard input streams.
  • rclone alternative: You can replace aws s3 cp - with rclone rcat tport:company-db-backups/... with identical zero-disk streaming behavior.

Testing the restore: streaming back without disk staging

A backup is only as good as your tested ability to restore it. You can stream the restore directly from object storage back into a recovery database instance without downloading the dump file to local disk first:

bash
# Stream direct from S3 into PostgreSQL target database
aws s3 cp "${BUCKET}/postgres/production_db_latest.dump.zst" - \
    --endpoint-url "https://s3.tport.space" \
  | zstd -d \
  | pg_restore -d recovery_db --clean --if-exists --no-owner

# Stream direct from S3 into MySQL target database
aws s3 cp "${BUCKET}/mysql/shop_production_latest.sql.zst" - \
    --endpoint-url "https://s3.tport.space" \
  | zstd -d \
  | mysql recovery_shop_db

Because tport.space charges <b>zero egress fees</b> for object downloads, you can schedule automated daily restore verifications on a staging server without incurring surprise data transfer bills. Compare this against conventional cloud providers who penalize restore testing with $0.09/GB egress charges.

Related runbooks

To verify that your uploaded database objects match bit-for-bit, read our guide on verifying a bucket copy with size, ETag, MD5 and full reads. For full-server file backups and long-term retention policies, explore backing up a website to object storage with rclone and building a Grandfather-Father-Son (GFS) retention schedule.

S3-compatible object storage with zero egress fees, fast multipart streaming, and reliable public/private buckets.

Explore tport.space

Sources, tested 11 November 2026