Skip to main content

Foundation

Archiving and compression are the building blocks of reliable backups on a Linux VPS. For WordPress, you are usually trying to produce a portable bundle you can validate, store off-host, and restore quickly under pressure.

Quick Summary
  • tar is the default archiver for directories; it preserves paths and Unix metadata well.
  • gzip/zstd/xz compress single files (SQL dumps and logs are the common targets).
  • For most WordPress file backups, tar.zst (or tar.gz) is the balanced default.
  • Always verify archives and do restore drills to a staging directory.

What you need to back up for WordPress

Most WordPress restores require two independent artifacts:

  1. Files
  • Your WordPress docroot (or at minimum wp-content/).
  • Configuration you cannot regenerate (for example, wp-config.php).
  1. Database
  • A SQL dump from MySQL/MariaDB.
wordpress-backup-components.txt
WordPress backup = files + database dump

files: wp-content/ (uploads/plugins/themes) + config
db: mysqldump (SQL)

Archive vs compression

  • Archiving = combining many files/directories into a single file.
  • Compression = reducing size (trade-offs: CPU, time, decompression speed).
archive-and-compress-mental-model.txt
many files -> tar -> archive.tar -> zstd -> archive.tar.zst

single file -> gzip/zstd/xz -> db.sql.gz / db.sql.zst / db.sql.xz

Choosing formats (practical defaults)

Use these as a starting point:

ScenarioGood defaultWhy
Daily file backupstar.zst or tar.gzGood size/speed, easy restore
Database dumpsdb.sql.zst or db.sql.gzSimple, streamable, fast
Maximum compression (cold storage)tar.xz or .7zSmallest size, slowest
Cross-platform sharing.zipWorks smoothly on Windows/macOS
Encrypted archives at rest.7z (or gpg on tarballs)Built-in encryption and optional splitting
note

If you care about Unix ownership/permissions, prefer tar-based backups. Formats like .zip are excellent for portability, but they are not the most faithful representation of Linux file metadata.

Naming, placement, and retention

Keep backups predictable:

  • Directory: /backups/ or /var/backups/ (or a mounted volume).
  • Naming: include date and what it contains.
backup-name-examples.txt
wp-files-2026-03-01.tar.zst
wp-db-2026-03-01.sql.zst
wp-full-2026-03-01.tar.gz

Retention is policy, not tooling. A common starting point:

  • 7 daily
  • 4 weekly
  • 3 monthly

Verification and restore drills

Verification is what turns "I have backups" into "I can restore":

  • List the contents (does it include what you think it includes?).
  • Test the compressed layer (does it decompress?).
  • Extract to a clean directory and spot-check key files.
warning

Extraction can overwrite files. Always restore into an empty directory first (for example /tmp/restore-test/). Only copy into place after validation.

Quick lab

This lab demonstrates the shape of a backup/verify cycle using tar.gz and gzip.

Create a backup directory:

create-backup-directory.sh
sudo mkdir -p /backups

Archive WordPress files with sensible excludes:

archive-wordpress-files-tar-gzip.sh
sudo tar -C /var/www/html \
--exclude='wp-content/cache' \
--exclude='wp-content/*/cache' \
-czvf "/backups/wp-files-$(date +%F).tar.gz" \
.

Dump and compress the database (adjust credentials and DB name):

dump-and-compress-database-gzip.sh
mysqldump --single-transaction -u DB_USER -p DB_NAME \
| gzip > "/backups/wp-db-$(date +%F).sql.gz"

Verify both artifacts:

verify-archives.sh
tar -tzf "/backups/wp-files-$(date +%F).tar.gz" >/dev/null
gzip -t "/backups/wp-db-$(date +%F).sql.gz"

Restore drill (extract to staging path):

restore-drill-extract-files.sh
sudo rm -rf /tmp/restore-test
sudo mkdir -p /tmp/restore-test
sudo tar -xzf "/backups/wp-files-$(date +%F).tar.gz" -C /tmp/restore-test

Cheat sheet
TaskCommand
Create tar.gz (directory)tar -C /path -czvf out.tar.gz .
List tar.gz contentstar -tzf out.tar.gz
Extract tar.gz to targettar -xzf out.tar.gz -C /tmp/restore-test
Compress a single filegzip file.sql
Decompress to stdoutgunzip -c file.sql.gz > file.sql
Mini quiz
  1. Why is tar used before compression for directory backups?

  2. What is the risk of extracting an archive directly into /var/www/html?

  3. When is .zip a better choice than .tar.gz?

  4. What is the minimum restore test you should do after creating a backup?