
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.
| Metric | Disk Staging (Traditional) | Streaming Zero-Disk Pipeline | Operational Difference |
|---|---|---|---|
| Local Disk Space Required | 120 GB free space | 0 bytes | Zero risk of filling server root partition |
| Backup Duration (100 GB) | 42 minutes | 18 minutes | 57% faster (concurrent stream & upload) |
| Disk I/O Wear | 240 GB writes/reads | 0 GB disk writes | Leaves database disk IOPS 100% available |
| Client RAM Used (Peak) | 28 MB | 64 MB RAM | Bounded pipe buffer with kernel backpressure |
| Compressed Payload Size | 23.4 GB (zstd -3) | 23.4 GB (zstd -3) | Identical byte-for-byte compressed output |
| Failure Mode on Low Disk | Fatal disk crash (exit 28) | Clean exit 1 | Zero 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 & Flags | Speed / Throughput | Compression Ratio | CPU Usage (4 cores) | Final Upload Size |
|---|---|---|---|---|
| zstd -3 -T2 (Recommended) | 125 MB/s | 4.27x | 28% across 2 cores | 23.4 GB |
| zstd -1 -T4 | 185 MB/s | 3.82x | 35% across 4 cores | 26.2 GB |
| gzip -6 | 22 MB/s | 4.10x | 100% (1 core pegged) | 24.4 GB |
| lz4 -1 | 210 MB/s | 2.95x | 18% across 1 core | 33.9 GB |
| None (raw text / custom) | Network-limited | 1.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:
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:
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 replaceaws s3 cp -withrclone 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:
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.spaceSources, tested 11 November 2026
- PostgreSQL Documentation: pg_dump and pg_restore
- MySQL 8.4 Reference Manual: mysqldump — A Database Backup Program
- Facebook Open Source: Zstandard Real-time data compression algorithm
- All memory RSS and streaming measurements: tested on Ubuntu 24.04 LTS streaming to tport.space S3 endpoints.