How to Separate WordPress Uploads, Database, and Code for Easier Backups
Most WordPress backups fail at the worst moment not because the backup is missing, but because it is one giant file nobody wants to touch. When you separate WordPress uploads database code into three parts, each piece gets its own schedule, storage, and restore path. A 2 GB media folder no longer blocks a 40 MB database dump, and a theme update no longer forces you to re-copy every image. This guide shows a layout that works on a plain LEMP VPS with no paid plugin: uploads stay in wp-content/uploads, the database gets dumped with mysqldump on a cron job, and code lives in Git.
Why One Big Backup Makes Restores Painful
The default backup most site owners use is one archive holding everything: core files, themes, plugins, the database, and every image. That sounds simple until you need it. A 3 GB archive is slow to download, and many hosts kill the restore halfway through because of PHP time limits or disk quotas. One bad byte can ruin the whole file, and you cannot restore just the posts without the media folder too.
Splitting the backup changes the math. A database dump is usually a few megabytes, so it can run every night with two weeks of copies kept. Uploads change slowly, so one incremental copy a day is enough. Code changes only when you update something, so a Git commit covers it. When a restore goes wrong, you know which piece failed and fix that piece.
The Three Parts of a WordPress Site
Every WordPress install breaks down into three parts that behave differently. Understanding the WordPress file structure is what makes the split possible.
- Code: WordPress core, themes, and plugins. You can download core again from wordpress.org at any time and reinstall a theme or plugin from its source.
- Database: posts, pages, comments, users, settings, and links between them. This changes every time someone publishes or comments, and it is the part you can never rebuild from scratch.
- Uploads: images, PDFs, and other media in the wp-content uploads folder. This folder grows steadily, rarely shrinks, and is usually the biggest part of the site by far.
On a typical small site that means a few hundred megabytes of code, a 10 to 50 MB database, and an uploads folder growing past 1 GB. Treating all three the same wastes time and disk space. A bloated database makes it worse, so it helps to shrink a bloated WordPress database without a plugin before you set up the new routine.
How to Separate WordPress Uploads Database Code in Practice
You do not need a plugin or a new server layout to split the three parts, just three small jobs, each with its own target folder. Create a backup root outside the web root, for example /var/backups/mysite/, with three folders inside: db/, uploads/, and code/. Nothing there is reachable from the web, which keeps the backups out of public view.
Each job touches only its own part: mysqldump writes one compressed database file per day, rsync copies only changed files from wp-content/uploads, and git archive packs your theme and custom plugin folders. If one job fails, the other two still run, and the cron log tells you which one to fix.
One common mistake is backing up the whole WordPress folder as a code backup. That pulls the uploads folder back in through the side door. Point the code job at wp-content/themes/your-theme and your custom plugin only, and leave core files out, since you can fetch a clean copy of core in minutes.
Back Up the Database on Its Own Schedule
The database deserves the most frequent schedule because it holds the content you cannot replace. The mysqldump WordPress database backup is the standard approach: a nightly dump that takes seconds on a small site. Pipe it through gzip, name the file with the date, and keep 14 daily copies. A 30 MB database compresses to a few megabytes, so two weeks of history costs almost nothing.
The command is short: mysqldump -u wpuser -p'password' wordpress_db | gzip > /var/backups/mysite/db/$(date +%F).sql.gz. Store the password in a credentials file with mode 600 instead of putting it on the command line, and run the job from cron at a quiet hour. Our guide to back up MySQL databases automatically with mysqldump and cron covers the cron setup and rotation in full.
A dump restores with one mysql command, and you can test it on a staging copy without touching the live site. If a plugin update breaks the database, you restore last night’s dump and lose at most a day of comments, not the whole site. That narrow blast radius is the whole point of a solid WordPress backup strategy.
Back Up Uploads Without Re-copying Everything
Uploads are the slow part of most backups because the folder only grows. A full copy every night wastes bandwidth and disk space on files that have not changed in months. Rsync copies only new and changed files, so the nightly job finishes in seconds after the first run.
Run rsync from the live uploads folder to the backup folder, then copy that folder off the server. Keeping the only copy on the same VPS is not a backup. Send it to S3-compatible storage with Restic, which encrypts and deduplicates the data, and you get offsite copies without a second server. Our guide on how to back up a VPS to S3-compatible storage with Restic covers the setup step by step.
Old media is the quiet disk eater here. A site that has run for three years often holds full-size images from posts that were rewritten or deleted long ago. Before you size the offsite storage, remove originals you no longer use, and read the offsite backup strategy for a single VPS and the 3-2-1 rule so the uploads copy lives in more than one place.
Version Code and Keep It Out of the Backup
Code is the one part that should not be backed up the way the other two are. A theme or a custom plugin is a small set of files that changes in clear steps, and Git tracks those steps better than any archive. Put your theme and any custom plugin in a Git repo, commit after each change, and push to a remote.
This also changes how you deploy. Instead of editing files on the server and hoping the backup caught the change, push a commit and pull it on the server. If a deploy breaks the site, you check out the previous commit and the site is back in under a minute.
Two rules keep this clean. First, add wp-config.php, uploads/, and cache folders to .gitignore so secrets and media never land in the repo. Second, never commit WordPress core or third-party plugins from the directory. Those come from their own sources, and including them only makes the repo slow to clone.
Test the Restore Before You Need It
A backup you have never restored is a guess, not a safety net. Set up a staging copy on a subdomain, restore the database dump, sync the uploads folder, and check out the code at the live commit. If the staging site loads with the latest posts, the three parts fit together. If it fails, you learn that on a quiet afternoon instead of during an outage.
Run this test once a month, and again after any big change: a host move, a WordPress major update, or a switch in backup tooling. The test takes about fifteen minutes once the staging site exists, and it catches the failures that matter, like a dump that stopped mid-write or an rsync job that silently skipped a folder. Our walkthrough on how to test your VPS backup by restoring it before you actually need it shows a safe way to run it without touching production.
A Simple Weekly Routine That Keeps It Working
The split only helps if it keeps running, so do a short weekly check. None of this needs a dashboard or a paid tool, just five minutes and a terminal.
- Check that last night’s database dump exists and is not empty.
- Check that the uploads rsync ran and the offsite copy is current.
- Check that the live code matches the latest Git commit.
- Delete dumps and archives older than your retention window.
- Once a month, restore everything to staging and confirm the site loads.
Alert on the two failures that matter most: a missing dump and a failed offsite copy. A cron job that emails you only on failure is enough. Once you separate WordPress uploads database code into three small jobs, backups stop being a chore you dread and become a habit you barely notice. That is the difference between sites that recover in minutes and sites that spend a weekend rebuilding from an old archive.