Skip to main content

zstd - Fast Compression

zstd (Zstandard) is a modern compressor with an unusually good speed-to-ratio trade-off. For WordPress VPS operations, it is a strong default for database dumps and for directory backups when paired with tar (.tar.zst).

Quick Summary
  • Compress: zstd file.sql -> file.sql.zst
  • Decompress: zstd -d file.sql.zst or unzstd file.sql.zst
  • Test: zstd --test file.sql.zst
  • Directory backup: tar -I zstd -cvf wp-files.tar.zst /var/www/html

When to use zstd

Use zstd when:

  • You want fast backups and fast restores.
  • You compress large SQL dumps, log bundles, and WordPress file archives.
  • You want a good default compression algorithm for automation.

If you need maximum compression for cold storage, consider xz (and accept the time cost).


Prerequisites

  • Ubuntu 22 / 24 LTS VPS.

  • Installed zstd and tar utilities.

  • Basic file permission & path knowledge.

  • Access to WordPress directories such as:

    /home/dev_wpstrategist/public_html/, /home/wpbackup/, /var/log/.


Core syntax

zstd-core-syntax.sh
# ──────────────────────────────
# 1. Compress a single file (same location)
zstd [OPTION] [INPUT_FILE]

# Example:
zstd /home/dev_wpstrategist/error.log
# → Output: /home/dev_wpstrategist/error.log.zst

# ──────────────────────────────
# 2. Decompress a .zst file
unzstd [INPUT_FILE.zst]
# or
zstd -d [INPUT_FILE.zst]

# Example:
zstd -d /home/dev_wpstrategist/error.log.zst
# → Output: /home/dev_wpstrategist/error.log

# ──────────────────────────────
# 3. Compress with specific level (1–19)
zstd -# [INPUT_FILE]

# Example (max compression):
zstd -19 /home/wpbackup/db.sql
# → Output: db.sql.zst (highest ratio, slower)

# ──────────────────────────────
# 4. Compress and save to another directory
zstd -o [OUTPUT_PATH] [INPUT_FILE]

# Example:
zstd -o /home/wpbackup/db_$(date +%F).sql.zst /home/dev_wpstrategist/db.sql

# ──────────────────────────────
# 5. View compression statistics
zstd -v [INPUT_FILE]

# ──────────────────────────────
# 6. Combine with tar to create a .tar.zst archive (Export)
tar -I zstd -cvf [OUTPUT].tar.zst [SOURCE_DIR]

# Example:
tar -I zstd -cvf /home/wpbackup/wpfiles_$(date +%F).tar.zst /home/dev_wpstrategist/public_html

# ──────────────────────────────
# 7. Extract a .tar.zst archive (Import)
tar -I zstd -xvf [INPUT].tar.zst -C [TARGET_DIR]

# Example:
tar -I zstd -xvf /home/wpbackup/wpfiles_2025-10-25.tar.zst -C /home/dev_wpstrategist/public_html/

# ──────────────────────────────
# 8. Stream backup over SSH
tar -I zstd -cvf - [SOURCE_DIR] | ssh root@remote "cat > /backup/wp_$(date +%F).tar.zst"

# ──────────────────────────────
# 9. Dump & compress WordPress DB
mysqldump -u [USER] -p'[PASS]' [DB_NAME] | zstd -19 -o /home/wpbackup/db_$(date +%F).sql.zst

# ──────────────────────────────
# 10. Decompress & import DB
zstd -dc [INPUT].sql.zst | mysql -u [USER] -p'[PASS]' [DB_NAME]


Key options

OptionDescriptionExampleUse CaseCPU Impact
-#Compression level 1–19zstd -9 file.sqlAdjust ratio vs speed🟢 Low–🟡 Medium
-dDecompress filezstd -d file.zstRestore backups🟢
-oOutput file pathzstd -o /dest/out.zst fileStore elsewhere🟢
-vVerbosezstd -v fileShow stats🟢
--rmRemove source file after compresszstd --rm fileSave disk space🟡
--testVerify archive integrityzstd --test file.zstValidate before restore🟢
--longEnable large window (better ratio on large files)zstd --long=27 fileHuge site archives🔴
tar -I zstdIntegrate with tartar -I zstd -cvf backup.tar.zst dir/Full WordPress backups🟡–🔴 (depends level)

Examples

Basic Compression

zstd-basic-compress.sh
zstd wp-config.php

Output:

example-zstd-basic-compress.txt
wp-config.php.zst : 77.81% compressed (5 KB → 3.9 KB)

Use Case: Light config backup.

CPU Impact: Low.


Max Compression Level

zstd-max-compress.sh
zstd -19 wpdb.sql

Output:

example-zstd-max-compress.txt
wpdb.sql : 90.2% compressed (120 MB → 11.7 MB)

Use Case: Database archive before transfer.

CPU Impact: High (slower ≈ 3× CPU load).


Keep Original and Save Elsewhere

zstd-output-to-path.sh
zstd -o /home/wpbackup/db_2025-10-25.sql.zst /home/dev_wpstrategist/db.sql

Output:

example-zstd-output-to-path.txt
/home/wpbackup/db_2025-10-25.sql.zst : 82.1% ratio

Use Case: Store compressed DB in backup folder.

CPU Impact: Moderate.


Decompress Database

zstd-decompress-file.sh
zstd -d /home/wpbackup/db_2025-10-25.sql.zst

Output:

db_2025-10-25.sql restored OK

Use Case: Prepare restore.

CPU Impact: .


Full WordPress Backup as .tar.zst

create-wordpress-tar-zst.sh
tar -I zstd -cvf /home/wpbackup/wp_2025-10-25.tar.zst /home/dev_wpstrategist/public_html

Output (snippet):

example-tar-zst-output-snippet.txt
public_html/wp-admin/
public_html/wp-content/
public_html/wp-includes/
Archive size : 450 MB → 95 MB (78.8% ratio)

Use Case: High-speed compressed site backup.

CPU Impact: – (depends level).


Extract .tar.zst Archive

extract-wordpress-tar-zst.sh
tar -I zstd -xvf /home/wpbackup/wp_2025-10-25.tar.zst -C /home/dev_wpstrategist/public_html

Output:

Files extracted successfully.

Use Case: Restore entire WordPress directory.


Verify Integrity

zstd-test-integrity.sh
zstd --test /home/wpbackup/db_2025-10-25.sql.zst && echo "OK"

Output:

OK

Use Case: Verify backup not corrupted.

CPU Impact: .


Check Compression Stats

zstd-verbose-stats.sh
zstd -v /home/wpbackup/db_2025-10-25.sql.zst

Output:

example-zstd-verbose-output.txt
Compressed : 110 MB → 9.8 MB (91.1%)
Compression speed : 280 MB/s Decompression speed : 900 MB/s


WordPress VPS use cases

Use CaseDescriptionExample CommandBenefit
DB BackupsCompress SQL dumps`mysqldump …zstd -19 -o …`
Site FilesFull .tar.zst backuptar -I zstd -cvf backup.tar.zst /var/www/htmlFaster transfer
LogsRotate & compress logszstd --rm /var/log/*.logSave disk space
Remote TransferPipe via SSH`tar -I zstd -cvf - dirssh …`
AutomationAdd to cron0 2 * * * tar -I zstd …Daily backups

Best practices

  • Use 19 only for final, non-urgent archives.
  • For daily backups, prefer 9 (balance speed vs ratio).
  • Always run -test before restoring.
  • Combine tar -I zstd to package entire directories.
  • Automate cleanup of old archives with find … -delete.
  • Monitor CPU usage on VPS to avoid overload.

Quick lab

  1. Export DB

    quick-lab-dump-db.sh
    mysqldump -u root -p wpdb > wpdb.sql

  2. Compress with zstd

    quick-lab-compress-db.sh
    zstd -9 wpdb.sql

  3. Verify

    quick-lab-verify-db.sh
    zstd --test wpdb.sql.zst && echo "Backup Valid"

  4. Restore

    quick-lab-restore-db.sh
    zstd -dc wpdb.sql.zst | mysql -u root -p wpdb


Cheat sheet

zstd-cheat-sheet.sh
zstd file # Compress file → file.zst
zstd -d file.zst # Decompress
zstd -# file # Level (1–19)
zstd -o out.zst in # Custom output
zstd --test file.zst # Verify integrity
tar -I zstd -cvf a.tar.zst dir/ # Create archive
tar -I zstd -xvf a.tar.zst -C /target # Extract archive
zstd -v file # Show stats
zstd --rm file # Compress & remove source


Mini quiz

  1. What command integrates zstd with tar?
  2. Which option verifies a .zst file’s integrity?
  3. What is the maximum compression level available?
  4. How would you decompress wp_2025-10-25.tar.zst to /var/www/html/?
  5. Which level should you use for daily scheduled backups to balance CPU and speed?

Restore checklist

Use this checklist before restoring a .tar.zst or .sql.zst backup:

  • Verify integrity (zstd --test ...).
  • Extract to staging (/tmp/restore-test/).
  • Confirm expected content exists (wp-content/uploads/, wp-config.php).
restore-drill-tar-zst.sh
sudo rm -rf /tmp/restore-test
sudo mkdir -p /tmp/restore-test
tar -I zstd -xvf /home/wpbackup/wp_2025-10-25.tar.zst -C /tmp/restore-test

Automation notes

  • Avoid very high levels in cron if the VPS is small; start with -3 to -9.
  • Consider lowering CPU and I/O priority for scheduled backups.
run-zstd-with-lower-priority.sh
nice -n 10 ionice -c2 -n7 zstd -9 -o /home/wpbackup/db.sql.zst /home/wpbackup/db.sql

warning

Compression is only half the story. A backup you cannot restore quickly is not an operational backup.