Websites & Hosting

How to Back Up a Website and Test the Restore

Learn what a complete website backup contains, how to automate it, and how to run a restore test that proves you can actually get your site back.

Key takeaways

  • A complete backup includes files, database, configuration and a record of the software versions needed to run them.
  • Keep at least one copy off the hosting account, and one that a compromised server cannot overwrite or delete.
  • Decide how much data you can afford to lose and how long you can be down, then set schedule and method to match.
  • A restore test into an isolated copy is the only reliable proof that your backups work.
  • Protect backups as carefully as the live site, because they contain the same private data.

To back up a website properly, copy its files, its database and the settings needed to run it, store those copies somewhere separate from the server, automate the job, and rebuild the site from a copy now and then. The rebuild is the step people skip, and it is the only one that tells you whether the rest worked.

This guide covers a typical self-managed or shared-hosting site. The same questions apply to website builders, where you have fewer controls and should find out what you can export.

What a website is made of

Copying the visible pages is rarely enough. List what your site actually needs:

Part Examples Notes
Files Code, themes, plugins, uploads Uploads change often and can be large
Database Posts, users, orders, settings Must be exported consistently
Configuration Web server rules, environment settings Often outside the web folder
Scheduled jobs Cron entries, queue workers Easy to forget
External settings DNS records, mail settings, API keys Document these; keep secrets protected

Also note versions: the operating system, language runtime, database server and content system. Restoring old code onto much newer software can fail in confusing ways.

Set two targets

Two questions shape everything else. How much recent work could you lose? That is your recovery point objective. How long could the site be unavailable? That is your recovery time objective.

A brochure site updated monthly can tolerate a weekly backup and a day of rebuilding. A store taking orders all day may need database copies every hour or continuous log-based recovery, plus a rehearsed procedure. Be honest here, because tighter targets cost more in storage, tooling and attention.

Where to keep the copies

The common 3-2-1 guideline asks for three copies of your data, on two different kinds of storage, with one off site. For a website, the live site counts as one copy. Keep a recent backup nearby for quick restores and another with a different provider or on your own storage. The reasoning is explained further in backups and the 3-2-1 rule.

Your host's backups are useful, but if the account is suspended, hijacked or billed incorrectly, you may lose the site and those backups together. Also, mirroring or syncing a folder is no substitute, since deletions and corruption copy across; see why sync is not backup.

Where possible, have the backup system pull data from the server, or give the server credentials that can add new backups but not delete old ones. Object storage services often offer versioning or retention locks for this.

A backup plan for one website
Live site Files, database, settings Test copy Where restores are proven Notes Versions, steps, contacts Host snapshot Fast restore, same provider Off-site copy Different account and provider Protected archive Cannot be altered by the web server Live site Files, database, settings Host snapshot Fast restore, same provider Off-site copy Different account and provider Protected archive Cannot be altered by the web server Notes Versions, steps, contacts Test copy Where restores are proven

Back up the database

Export the database with its own tools, which produce a consistent copy. Copying a running database's data files usually doesn't.

For MySQL or MariaDB with InnoDB tables:

mysqldump --single-transaction --routines -u backupuser -p shopdb | gzip > shopdb-$(date +%F).sql.gz

--single-transaction takes a consistent snapshot of transactional tables without locking them for the duration, and --routines includes stored procedures and functions. For PostgreSQL, the custom format works well with the restore tool:

pg_dump -Fc -f shopdb-$(date +%F).dump shopdb

Don't type passwords into commands, where they can appear in shell history and process lists. Use a protected option file such as ~/.my.cnf or ~/.pgpass, readable only by the backup user.

Back up the files

On a Linux server, an archive of the site folder is straightforward:

tar -czf site-files-$(date +%F).tar.gz -C /var/www example.com

For large upload folders, tools that store only changes, such as incremental or deduplicating backup programs, save time and space. On shared hosting, your control panel may create full archives; download them or send them to remote storage automatically.

Back up files and database close together. If they are far apart, you can restore a database that references images the file copy doesn't have.

Automate and watch it

Manual backups happen until the first busy week. Schedule them with cron, your host's scheduler or a backup plugin. A good automated job:

  1. Creates the database dump and file archive.
  2. Encrypts them if they leave systems you control.
  3. Uploads them to remote storage.
  4. Checks that the upload succeeded and the size is plausible.
  5. Removes old copies according to your retention rule.
  6. Alerts you when any step fails, or when no success has been reported on time.

The last point matters. A job that stops running sends no error. Use a monitor that expects a signal after each successful run and complains when it doesn't arrive.

For retention, keep several generations: for example daily copies for two weeks, weekly for two months and monthly for a year. Infections and quiet corruption are often noticed late, so a single most-recent copy may already be damaged. Retention must also respect any obligation to delete personal data.

Protect the backups themselves

A backup holds everything the live site holds: customer details, password hashes, order history and often keys to other services. A forgotten archive in a public web folder is a gift to anyone who guesses its name, so never store backups under the directory your web server publishes.

Encrypt copies before they go to third-party storage, and keep the key somewhere that survives the loss of the server, such as a password manager shared with one other trusted person. Restrict who can download backups, turn on multi-factor authentication for the storage account and use separate credentials for the backup job. If the storage service keeps access logs, glance at them occasionally.

Verify integrity as well. Record a checksum when each archive is created and compare it after transfer:

sha256sum site-files-2026-12-01.tar.gz > site-files-2026-12-01.sha256
sha256sum -c site-files-2026-12-01.sha256

A matching checksum shows the file arrived unchanged. It says nothing about whether the contents were complete in the first place, which is why you still need a restore test. You can also generate and compare digests with the file hash tool.

Backing up hosted builders and managed platforms

With a website builder or hosted store, the provider protects its own infrastructure. That doesn't necessarily mean you can roll back your own mistake, or recover after your account is closed.

Find out what you can export: pages and posts, products, customers, orders, media files and form entries. Check the format, since a spreadsheet of products is easy to reuse and a proprietary bundle may not be. Design and layout often can't be exported at all, so keep your original text and images, and take screenshots of key settings.

Managed hosting usually includes snapshots. Ask how long they are kept, how you restore one, whether you can restore only the database or only files, and whether copies survive cancellation of the plan. Then keep an export of your own anyway.

Test the restore

Pick a recent backup and rebuild the site somewhere isolated: a staging server, a local virtual machine or a container. Use only your backups and your written notes.

A restore drill
1 Prepare an isolated target Matching software versions, no public access 2 Fetch the off-site copy Prove you can reach and decrypt it 3 Restore database and files Follow your written steps 4 Neutralize side effects Block email, payments and scheduled jobs 5 Verify and time it Check content, then fix the notes Prepare an isolated target Matching software versions, no public access 1 Fetch the off-site copy Prove you can reach and decrypt it 2 Restore database and files Follow your written steps 3 Neutralize side effects Block email, payments and scheduled jobs 4 Verify and time it Check content, then fix the notes 5

Restoring the dumps looks like this, into a freshly created test database:

gunzip < shopdb-2026-12-01.sql.gz | mysql -u testuser -p shopdb_test
pg_restore -d shopdb_test shopdb-2026-12-01.dump

Before starting the restored application, disable outgoing mail, point payment settings at test mode and turn off scheduled tasks. Otherwise your test copy might email real customers or charge real cards.

Then verify more than the home page. Sign in, open recent posts or orders, check that images load, run a search and compare a few record counts with expectations. Note how long it took, from deciding to restore to having a working site, and compare that with your target.

What commonly goes wrong

  • The encryption key or storage password was only stored on the server that died.
  • The dump is truncated because the disk filled or the connection dropped.
  • Uploaded files were excluded to save space.
  • Character encoding settings differ, garbling accented text.
  • The new server lacks a required extension or uses an incompatible version.
  • Nobody knows the DNS or certificate steps needed to point visitors at the new machine.

Each failure found during a drill is cheap. Add the fix to your notes and repeat the test after major changes, and at a regular interval such as quarterly.

When you restore for real

Pause before overwriting anything. Take a copy of the broken state, which may hold recent data or evidence. Choose a backup from before the problem began. If the cause was a break-in, restoring alone reopens the same hole, so update software and change credentials before going live. Moving to a new machine overlaps heavily with migrating to a new host, and the same final checks apply.

Finally, tell whoever needs to know what was lost between the backup and the failure. Orders or messages from that window may be recoverable from your payment provider or mail system.

Written for 4Internet with AI writing tools and not reviewed line by line by a person. Check anything you rely on with the maker, provider or standard concerned. Report an error.

Keep reading

All 45 articles in Websites & Hosting →

Latest news on this topic