AdvancedLesson 26 of 304 min read

Backups, migration and staging sites

Back up and restore a site, move it to a new host or address without breaking stored data, and use staging safely, with a real backup and replace test.

In this lesson you will

  • Make and test a complete backup
  • Move a site to a new host
  • Avoid the serialized-data trap
  • Use a staging site

About 18 minutes

Moving house without breaking anything

Elif has built a client’s site on her laptop. Now it has to move to the client’s hosting, with a new address. After the move the home page loads, but half the images are missing and the menus are gone. The reason, which hides in a feature of how WordPress stores settings, is one of the most common migration traps. This lesson covers backups, restores, moving a site and testing changes on a staging copy first.

What a complete backup contains

Part Holds
Database Posts, pages, settings, users, comments
Files Themes, plugins, uploads, configuration

You need both. Keep copies in more than one place, one of them away from the server. Plan how long to keep them, and encrypt copies that hold customer data. Remember the golden rule: a backup is real only after you have restored it somewhere.

Backup and restore, rehearsed for real

A test saved three posts into a backup file, deleted them to imitate an accident and restored them from the file. Then it ran the two ways of changing a web address inside stored data. The output is real:

backup file size: 1786 bytes for 3 posts
after the accident, posts found: 0
restored: 3 | titles: Zz Backup A, Zz Backup B, Zz Backup C
naive replace is still valid serialized data: NO (broken)
safe replace valid: yes -> a:2:{s:3:"url";s:23:"http://newsite.org/shop";s:5:"title";s:3:"Old";}
cleaned: yes

The restore brought back all three posts with new internal numbers, which is normal. The second half shows the migration trap. WordPress stores some settings in a format that records the length of each text. A plain find-and-replace changed the address but not the recorded length, so the stored data became unreadable; WordPress then ignores the setting, and things such as menus and widgets go missing. A safe replacement reads the data, changes the text inside it and writes it back with the correct lengths, as the last line shows. Good migration tools do this for you; a raw replace in a database editor does not.

Moving a site, step by step

  1. Make a full backup of the old site (database and files).
  2. Prepare the new host: matching or newer PHP, a new empty database.
  3. Copy files and import the database.
  4. Update the configuration file with the new database details.
  5. Replace the old address with the new one using a tool that handles stored data safely.
  6. Save Settings, Permalinks to refresh address rules.
  7. Check pages, menus, images, forms, logins and search.
  8. Lower the DNS time-to-live beforehand, then point the domain to the new host.
  9. Keep the old site until the new one is confirmed, and watch for errors.

Staging sites

A staging site is a private copy used for trying updates, redesigns and new plugins. Many hosts create one with a click. Test there, write down exactly what you changed, then repeat the steps on the live site, or use the host’s push tool if it is reliable. Take care with live data: a staging copy of a shop should not send real emails or take real payments, and it should be hidden from search.

Common problems

  • Images missing: the old address is still stored; use a safe replace.
  • Too many redirects: a mismatch between the stored address and HTTPS settings.
  • Database connection error: wrong details in the configuration file.
  • Only the home page works: refresh permalinks.
  • Emails fail: mail settings on the new host.

Practice

Make a full backup of a practice site. Restore it into a second location (a local tool or a hosting staging area), change the address safely and check that menus and images work. Time yourself, and write the steps in your own words as a recovery guide.

Practice answer

A recovery guide of ten clear lines is worth more than a perfect backup nobody knows how to use. Keep a copy of the guide outside the site, because you may need it when the site is down.

Common mistake

Running a raw find-and-replace on the database to change the site address. It breaks stored data. Use a tool that understands it.

A pre-move checklist

Check Why
Backup tested You can go back
PHP and database versions compared Avoids surprises
Email plan decided Mail may stop on the move
Redirects noted Old addresses keep working
Search visibility checked Do not hide the new site

After the move, keep the old copy for a week or two. Monitor errors, forms and orders, and check Search Console for crawl problems. If anything is wrong you can point back to the old site while you fix it. A calm, written plan is what separates a smooth migration from a stressful weekend.

Check what you learned

Five quick questions. Pick an answer and you will see straight away whether it is right and why.

What does a complete backup include?

  1. Only the logo
  2. Only comments
  3. Only the theme
  4. Database and files

You need both.

Why did the naive replace fail?

  1. The stored text length no longer matched
  2. The site was offline
  3. The password was wrong
  4. The theme was old

Serialized data records lengths.

What is a staging site?

  1. A spam folder
  2. A backup of images
  3. A private copy for testing changes
  4. A kind of theme

Test there, then repeat on live.

When is a backup real?

  1. When it is large
  2. When it is old
  3. When it is named
  4. After you have restored it

Restore tests prove it.

What should you do after moving a site?

  1. Delete the old host immediately
  2. Save Permalinks and check pages, menus and forms
  3. Remove all plugins
  4. Disable backups

Keep the old site until confirmed.

Summary

  • Backups need database and files, stored in two places.
  • Test a restore before you need it.
  • Never raw-replace addresses in a database.
  • Try changes on staging first.

Next lesson

Next: working at scale with caching, queries and transients.

Questions

How often should I back up?

Match it to how often content changes: daily for busy sites, weekly for simple ones.

Can I migrate with a plugin?

Yes. Several well-known migration and backup plugins exist. Check reviews and current terms.

Why do IDs change after a restore?

Because new rows get new numbers. Good restore tools keep the original numbers; a simple import may not.

Progress is saved in this browser.