Members CMS
PHP 8.1+ & MySQL Buy license · $349.95
Hosting & security

Backing up a large media library and its database

A media backup without its database, or a database without its files, can't be restored properly. How to back up both, keep copies off-site and test them.

Updated 4 minute read The Members CMS team

If you run a membership site from a large media library, your backups protect years of work. Yet many backup plans have a hidden gap: they copy the files but not the database, or the database but not the files, or both but at different times. When something goes wrong, the restore doesn't quite fit together.

This guide explains what a complete backup of a media library looks like, how often to take one, where to keep copies and, most importantly, how to check that a backup will actually restore.

Why files and database belong together

A media CMS keeps two kinds of information. The files are the photos and videos themselves. The database holds everything about them: titles, descriptions, categories, statuses, which file belongs to which set, and each website's category rules and settings.

Neither is much use without the other:

  • Files without the database are just folders. You lose titles, categories, statuses and every website's settings.
  • The database without the files points at nothing. Every gallery is empty.
  • Files and database from different times don't match. Sets added after the database backup have no records, and records may point at files that no longer exist.

So the aim is a matching pair: a database backup and a file backup taken together, so that one describes the other.

What to include

A complete backup usually covers:

  1. The database, exported in full.
  2. The original media files.
  3. Configuration files, such as database connection settings.
  4. Any uploaded promotion graphics or story images not stored with the media.

Generated thumbnails and previews are optional. They can be recreated from the originals, so leaving them out saves space, but restoring will take longer while they are regenerated. For a very large library, skipping them is often a sensible trade.

Large libraries

Copying hundreds of gigabytes every night is slow and expensive. Incremental backups, which only copy files that are new or changed, make this practical. Because originals in a well-run library are never altered, most files never change after upload, so incremental copies stay small.

Taking a consistent pair

The simplest way to keep files and database in step is to back up the database first, then the files, during a quiet period when nobody is uploading. Any files added between the two steps will simply have no record yet, which is easy to spot and fix. The reverse order is worse, because the database could then refer to files the backup never copied.

How often and how many

How often you back up depends on how much work you could bear to lose. If you upload new sets every day, a daily backup makes sense. Keep several generations so you can go back before a mistake that wasn't noticed straight away.

BackupHow oftenKeep for
DatabaseDaily7 daily copies
DatabaseWeekly8 weekly copies
Media files (incremental)DailyAs long as the weekly database copies
Full off-site copyWeekly or monthlyAt least two copies

This is only an example. The key ideas are several copies, a mix of recent and older ones, and a schedule that runs automatically, ideally by a server cron job rather than someone remembering. A job that depends on a person tends to be skipped in exactly the week it would have mattered.

Keep copies off the server

A backup on the same server as the library protects you from accidental deletions, but not from a disk failure, a hacked account or a hosting problem. At least one copy should live somewhere else: a different server, a storage service or a drive you keep yourself.

A few practical tips:

  • Use a separate account and password for off-site storage, so one compromised login can't delete everything.
  • Encrypt backups that leave your server, especially if they contain admin details.
  • Check how long a full download would take. Restoring a terabyte over a slow connection can take days.
  • Remember to budget disk space for backups when choosing hosting. See what you need to self-host a content CMS.

Test your restores

A backup that has never been restored is only a hope. Files can be incomplete, exports can be corrupted, and steps can be forgotten. Now and then, restore a backup to a test location and check it:

  1. The database imports without errors.
  2. Sets open and show their images and videos.
  3. Categories, statuses and website settings look right.
  4. Counts of sets and files match what you expect.

Write down the steps you followed. If you ever need to restore for real, you'll be doing it under pressure, and a written checklist helps.

Integrity checks between backups

It also helps to check the live library regularly for missing files, orphaned files with no record, and duplicates. Problems caught early don't end up copied into every backup. A well-organised library, as described in our guide to organising one media library for several websites, is much easier to check.

How Members CMS handles this

Members CMS includes Maintenance > Backup and Restore, which makes database and media backups, verifies them and restores them, with scheduled backups run by cron. Maintenance > Integrity Checking looks for missing, orphaned, changed and duplicate files, with checksum verification and quarantine, and the same menu has Thumbnail Regeneration and a Storage Overview showing originals, previews, backups and your largest sets. Metadata can also be exported as CSV or JSON from the Media Library.

Each set lives in its own storage folder named by a stable ID, and renaming a set never moves its files, so the media side changes only when you add or replace files, which keeps any incremental off-site copies you make small. An off-site copy is still your job, and well worth having.

Frequently asked questions

Why do the files and database need to be backed up together?

The database holds titles, categories, publication statuses and which file belongs to which set. Files without it are just a pile of folders, and the database without files points at nothing.

How many backups should I keep?

Keep several, for example daily copies for a week and weekly copies for a month or two, with at least one copy stored away from the server.

How do I know a backup works?

Restore it to a test location now and then. A backup that has never been restored is only a hope.

Get three guides like this every month, plus software update notices.Subscribe →