WordPress Backup and Restore on Linux: Database, wp-content and Automation

wordpress backup linux - custom-wpback-featured.png

A WordPress backup that only copies wp-content cannot restore your site — posts and settings live in MySQL/MariaDB. Operators search for all-in-one backup plugins, but on Linux servers the reliable pattern is mysqldump plus file archive, stored off-server.

Database skills: mysqldump guide,
file sync: rsync backups,
fresh install context: WordPress LEMP install.

Two Halves: Files and Database

Themes, plugins, and uploads under wp-content; everything else critical in SQL tables prefixed wp_ (or custom prefix).

files + DB
both required

Back Up wp-content

Use rsync or tar; exclude object-cache and tmp dirs if plugins recreate them.

basharchive files
sudo tar -czf /backup/wp-content-$(date +%F).tar.gz -C /var/www/example.com wp-content
rsync wp-content
tar z

mysqldump the WordPress Database

Use --single-transaction for InnoDB to avoid long locks; gzip the result.

bashdatabase dump
mysqldump -u wpuser -p --single-transaction wordpress | gzip > /backup/wordpress-$(date +%F).sql.gz
mysqldump
gzip

Script and Retention

Nightly cron with 7–30 day rotation; copy to another region or object storage.

bashsimple retention
find /backup -name 'wordpress-*.sql.gz' -mtime +14 -delete
cron
retention

WP-CLI (Optional)

Helpful for exports, plugin lists, and search-replace during migrations.

bashwp-cli
wp db export /backup/wp-cli-$(date +%F).sql --path=/var/www/example.com
wp db export
CLI

Restore Procedure

Create empty database, import SQL, restore files, fix ownership, flush permalinks in wp-admin.

bashimport
gunzip < /backup/wordpress-2026-10-07.sql.gz | mysql -u wpuser -p wordpress
restore order
DB first

Staging Clones

Copy backups to a staging vhost; run URL search-replace; block indexing.

TipNever point staging DNS at production without understanding cookie and SEO implications.
staging
search-replace

Automate With systemd Timers

More observable than bare cron — logs in journal, easy OnCalendar syntax.

timer unit
off-site

Test Restores Quarterly

An untested backup is a guess. Import into a throwaway database and browse key pages.

bashlist archive
tar -tzf /backup/wp-content-$(date +%F).tar.gz | head
validate
RTO/RPO

Quick Reference

  • Always: database dump + wp-content
  • Store copies off the web server
  • Restore drill at least quarterly

Related tutorials

Diagrams are original illustrations by Gnome IT Solutions. Tutorial text © Gnome IT Solutions.