Moodle site backup and restore: why a course backup is not enough
Course backups created inside Moodle capture course content only: activities, resources, grade settings and, optionally, user data within a course. They do not capture the platform itself. A whole-site backup has to capture three things together: the database, the moodledata directory and the Moodle code, including config.php and any custom or third-party plugins. If you restore a database without the matching moodledata files, files uploaded to courses will be missing or broken. If you restore code from a different point in time, the database schema and plugin versions may not match. The three must come from the same moment, or the restored site will not start cleanly.
Teams need a site-level plan for four kinds of event: loss of a server or storage volume, a failed upgrade that leaves the database in an unusable state, ransomware that encrypts application files or database data, and accidental deletion of a large body of courses, users or categories. Course backups can recover some of these cases one course at a time, but they are slow to restore at scale and do not bring back site settings, authentication configuration, enrolment data or plugin state. Before a major change, such as a move to a new release, confirm that your backup set is complete and restorable on its own, since upgrades are where teams most often need to roll back.
This page covers the design of site backup and restore: what must be captured, how to keep the three parts consistent, how to test restores and how to set recovery time and recovery point targets for a learning platform. It does not prescribe specific backup products or scripts, because those depend on your storage, database and hosting. Before you design anything, confirm with your own environment which database engine and version you run, where moodledata lives, and who owns the restore decision during an exam period or a term-end assessment window.
Which parts of a Moodle site must be backed up and when each fits
This table compares the four layers that make up a Moodle site: the database, the moodledata directory, the code and configuration, and course backups. Read each row as a separate piece you must capture, then check how it fits with upgrades and server moves. The main takeaway is that a course backup alone cannot rebuild a site.
| Layer | What it holds and how it is captured | What breaks if it is missing | Upgrade and server move role |
|---|---|---|---|
| Database | Users, enrolments, grades, course structure, settings and most plugin data. Captured with a consistent database dump or engine-level snapshot taken while Moodle is quiet. | Almost nothing in Moodle can be read back. Accounts, grades and course records are lost, and file references point to nothing. | Required for any move. Upgrades change its schema, so take a fresh copy immediately before the upgrade starts. |
| moodledata directory | Uploaded files, file pool, temporary and cache data, and backup and restore files. Captured as a filesystem copy that matches the database snapshot. | Database rows remain but file links break. Course content, assignments and user uploads become missing or unreadable. | Must travel with the database. A database from one point in time and files from another often produce broken links. |
| Code and configuration | Moodle code, installed plugins, themes, the config.php file, web server and PHP settings, and any custom patches. Captured from version control, a release archive or a file copy. | The site cannot start or must be rebuilt by hand. Custom plugins and theme changes may be lost. | Confirm the exact code version and plugin versions that match the database. Upgrades need matching code, so keep a copy of the pre-upgrade tree. |
| Course backups | Course-level .mbz archives created by Moodle's backup tool, with optional user data. Captured inside Moodle as scheduled or manual exports. | Restores a single course or activity only. Does not recover site settings, users, grades kept outside the course or the wider platform. | Useful for moving individual courses between sites. Not a substitute for a full site backup, and not a fallback for a failed upgrade. |
| Consistency between layers | Database, moodledata and code must describe the same moment. Confirm how your storage and database tools handle this in your environment. | Mismatched layers cause errors that look like corruption, even when each part was captured correctly. | Plan a single change window or a quiesced snapshot before every upgrade or move. |
| Restore testing | A timed restore of all layers into a separate environment, followed by logging in and checking courses and files. | Untested backups are unknown. Gaps such as missing file paths or plugin versions appear only during an incident. | Run a test restore before each major upgrade and after backup configuration changes. |
| Recovery time expectations | The time to restore all layers, plus validation. Ask your team or partner to measure this in your environment rather than assume it. | Without a measured figure, a recovery target for a learning platform is a guess. | Confirm the target with academic and support leaders before a term starts, since restores often overlap with peak use. |
How the database and moodledata must match at restore time
The database and the moodledata directory only describe the same site if they are captured at the same moment. Moodle's database holds the references: file records that point to content hashes, user uploads recorded as rows, and course and activity state that depends on files existing on disk. If the database is captured on Monday and moodledata on Tuesday, a restored site can show file links with no matching file on disk, or files on disk that no row refers to. The first case produces broken images, missing assignment submissions and failed course restores. The second wastes space and makes later cleanup harder to reason about. Neither failure is obvious at restore time, so a restore test should check both sides, not just whether the login page loads.
There are three practical ways to get a consistent point. The first is maintenance mode during capture: put the site into maintenance mode, stop cron and other writers, dump the database, copy moodledata, then reopen the site. This is simple and easy to verify, but the window is the full capture time, so confirm with your administrators how long users can be locked out. The second is a storage snapshot taken across both the database volume and the moodledata volume at one point, which needs a storage platform that can snapshot them atomically and a database that is quiesced or consistent at snapshot time. The third is a quiesced database, where the database engine provides a consistent backup while the site keeps running, paired with a moodledata copy that accepts some drift. The third option needs careful testing, because files written during the window can exist without matching rows, so ask your DBA and your platform team to document exactly what their tool guarantees.
Two more inputs must be captured with the data. The config.php file holds the database connection, the dataroot path and any forced settings, so a restore without it will point at the wrong database or file store. The exact Moodle code version also matters, because the database schema is tied to it and upgrade paths are version-specific. Record the release and build from the site's Site administration pages and keep the code tree, or a reproducible way to rebuild it, alongside each backup set. Plugin versions belong in that record too. Confirm with your vendor or your own build process which artifacts you need to reproduce the same code, and test that the restored site reports the same version before anyone runs an upgrade.
How the parts of a whole-site backup fit together
The flow starts on the live Moodle site, where the web server, PHP, the database, moodledata, code and configuration all hold part of the state. Each part is copied to a separate backup store that sits behind its own trust boundary, so a compromise of production does not reach the copies. The restore target is separate infrastructure, and a restore test must pass before the backup is accepted. If the test fails, the team goes back to the backup process rather than trusting the copy.
Live site components are copied to a separate store, then restored and tested elsewhere.
Backup approaches for virtual machines, containers and bare metal
On virtual machines, the most common approach is to snapshot the whole guest, which captures the code directory, the moodledata directory and the database server's files at one point in time. That only works as a consistent copy if the database is quiesced or flushed before the snapshot, and if moodledata and the database sit on storage that the hypervisor snapshots atomically. Otherwise a snapshot can hold a database that references files written after it was taken, or files whose matching rows were never committed.
- Database first, then disk: Dump or flush the database through its own tooling before the snapshot, so the snapshot holds a state the database can recover from.
- Moodledata on the same snapshot: Confirm that moodledata is included in the same snapshot set as the database, not on a separate share that is copied on a different schedule.
- Maintenance mode during capture: Put the site in maintenance mode for the window where the dump or snapshot runs, so users and cron do not write mid-capture.
- Snapshot scope: Check whether the hypervisor snapshot includes all attached disks, and whether it can be taken while the guest is running without a memory state.
- Snapshots are not backups: Confirm that snapshots are copied off the hypervisor to separate storage on a schedule you have tested.
Ask your hypervisor or storage vendor whether their snapshots are crash-consistent or application-consistent, and whether they can coordinate with the database through a quiesce hook.
In containerized deployments, the code usually lives in the image, while moodledata and the database live on external volumes. Backing up the image does not capture site state, and the container's writable layer is not a place to keep moodledata. The team has to back up the volumes and the database as one set and record which image tag was running, so the code, the data and the schema match on restore.
- Image as code: Record the exact image digest and any local patches or plugins baked into a custom image, since the registry copy alone does not hold site configuration.
- Volume snapshots: Confirm whether your storage driver can snapshot persistent volumes consistently, and whether it can run a freeze hook for the database volume.
- Database outside the cluster: If the database runs as a managed or separate service, its backup schedule is separate, so align the two windows and record both timestamps.
- Config and secrets: Back up the configuration files, the
config.phpcontents and secret objects that the deployment injects, because they are not part of moodledata. - Restore target: Confirm that the restore can recreate the same image tag and volume claims in a clean namespace or host.
Ask your platform team and storage vendor whether volume snapshots are application-consistent, how they handle a quiesce, and whether a restore has been tested on a second cluster.
On bare metal, there is no hypervisor to snapshot the machine, so the team must capture each part with tools that run on the host or with storage features the hardware provides. The three parts are usually dumped separately: the database with its own logical or physical backup tool, moodledata and code with a file-level copy or a filesystem snapshot. The gap appears when these run at different times, or when the filesystem is copied while files are still being written.
- Logical database dump: Use the database engine's native backup tool with a consistent transaction mode, and record the start time of the dump.
- Filesystem snapshot: If the volume manager or filesystem supports point-in-time snapshots, take the snapshot of moodledata and the database files in the same operation.
- Code captured from version control: Record the Moodle version, the plugin versions and local patches, so the code can be rebuilt from source and configuration.
- Hardware and RAID state: Note the storage layout, because restoring to different disk geometry or a new controller can change how data is recovered.
- Offsite copy: Confirm that backups leave the server on a schedule and that the copy is encrypted and readable on a different machine.
Confirm with your hardware and storage vendor whether their snapshot or replication features are crash-consistent, and whether a restore onto replacement hardware has been rehearsed.
Setting up a whole-site backup routine with restore checks
This sequence produces a backup set that captures the Moodle database, moodledata and code together at one point in time, stored away from the production system, and proven by a full restore into a separate environment before anyone relies on it. Each step ends with a check the team can record.
Document the running versions and locations
The administrator records the Moodle version, the PHP version, the database engine and version, the web server document root, the location of the moodledata directory and the path to config.php. Check the Moodle release notes for the running version so the restore target can match the supported PHP and database versions named there. For Moodle 5.1 and later, confirm the document root points to the /public directory. Done when the inventory is written down and a second administrator can read it and locate every item without asking the first one.
Define a consistent capture method
Decide how the database dump, the moodledata directory and the code tree are captured so they describe the same moment. The usual approach is to place the site in maintenance mode or otherwise stop writes, dump the database, then copy moodledata and the code, and record the time of each step. Note that course backups created inside Moodle hold course content only and do not replace this set. Done when a written runbook lists the exact order of capture, the commands or tools used, and the place where each artifact is written. Confirm the method with your database and storage vendors, since their tools determine how consistency is achieved.
Set retention and an offsite copy
Set how many generations of backups you keep and where they live. Keep at least one copy in a separate storage account or location with its own credentials, so a compromise or mistaken deletion in the production environment cannot remove every copy. Encrypt the backups at rest and restrict who can read them, because they contain learner personal data and grade records. Done when the retention rule and offsite destination are documented, and a test write from the backup host to that destination succeeds with the intended permissions.
Schedule the capture job
Automate the capture with a scheduler you control, such as system cron or your platform's job runner, and run it under a service account with only the rights it needs. Use the same maintenance window logic your change process uses so learners are not writing during the dump. Log start time, end time, file sizes and checksums for each artifact. Done when the scheduled job has completed successfully on consecutive runs and the log shows matching sizes and checksums in the offsite location.
Verify the backup artifacts
Before any restore test, check each backup set. Confirm the database dump loads without errors into a scratch database, the moodledata archive lists its expected directory structure, and the checksums match the copies in the offsite location. Keep a record of the Moodle version beside the set so a restore uses matching code. Done when every set passes these checks and failed captures raise an alert to the on-call administrator instead of silently replacing the last good set.
Restore the full site into a separate environment
Build a separate environment that matches the production Moodle version, PHP version and database engine named in the release notes, then restore the database, moodledata and code from the same capture. Point the web server document root at the correct directory and update config.php with the restore environment's database and data path settings. Never let the restored site send email to learners or call live integrations. Done when the restore completes without manual edits to the database.
Check the restored site functions
Confirm the restored site starts without errors, the status check report shows no missing dependencies, and the moodledata files open correctly. Run cron manually and confirm it completes. Sign in with a test administrator account, then open a sample course, confirm enrolled users and grades appear, and open a file uploaded to a course. Record each check with its result and date. Done when the checklist is signed off and any failures are logged as defects against the backup process.
Record the recovery results and repeat the test
Write down how long the restore took from start to a working sign-in, which steps needed manual work, and which artifacts were missing or inconsistent. Use these notes to set your recovery time target with the business owners, since the restore duration is the figure they need to plan against. Schedule the restore test to repeat on a regular basis and after any major Moodle upgrade or database change. Done when the target and the next test date are agreed and recorded in the operations runbook.
How to protect backup copies from loss and misuse
A whole-site Moodle backup contains everything an attacker or careless administrator would want: user records, grades, uploaded files and the database credentials that open them. The cards below cover the risks that most often leave those copies exposed, and the control to plan for each. Confirm what your storage actually provides before you rely on any of them.
Backups hold personal data
A site backup includes the user table, enrolments, grades, messages and every file in moodledata, so it is a full copy of the learner record. Treat it with the same classification and retention rules as the live site. Plan a retention period per backup set, a documented owner, and a deletion step so old copies do not outlive the data they hold. Ask your compliance team which backup copies they are required to keep and for how long.
Credentials in config.php
The Moodle config.php file holds the database password, and any SMTP, object storage or web service secrets you have added. A backup of the code tree therefore carries live credentials unless you exclude or separately protect that file. Decide where the secrets are kept, restrict who can read the backup archive, and rotate the database password after any suspected exposure. Check whether your secrets manager can supply these values at restore time instead of storing them in the archive.
Backups beside production
A backup written to the same host, disk, or cloud account as production fails together with production. A compromised administrator account or a single misconfigured bucket policy can reach both at once. Plan a separate account or project for backup storage, with its own administrators and its own credentials that the Moodle server can write with but not delete from. Confirm with your provider whether separate accounts and cross-account write-only roles are available in your environment.
Encryption at rest
Database dumps and moodledata archives are stored as plain files unless you encrypt them before or as they are written. Choose between storage-side encryption managed by your provider, encryption by the backup tool before upload, and key management that keeps keys apart from the backups they protect. Confirm who holds the keys, how they are rotated, and whether a restore can be performed by the recovery team without the original administrator account.
Too many administrators
Many sites give every Moodle site administrator and every server operator read access to the backup store, so the backup inherits the widest access in the team. Limit read access to a named recovery group, log every download and restore, and separate the person who schedules backups from the person who can open them. Review the access list at each change window and after staff leave.
Ransomware reaching backups
Ransomware that encrypts a production server often looks for mounted volumes, network shares and stored credentials that can also reach backup stores. If an attacker can delete or overwrite backups, the copies protect nothing. Where the storage supports object lock or immutable retention, enable it for a fixed period. Where it does not, keep an offline or separately administered copy and test restoring from it. Ask your provider which immutability options are available and how they are enforced.
Setting recovery time and recovery point targets for a learning platform
Set the recovery point target (how much recent data you can afford to lose) and the recovery time target (how long the platform can be down) before you choose a backup schedule or storage design. The right figures come from your academic calendar and assessment windows, not from a generic benchmark. Ask your registrar, course leads, assessment office and student services what happens when a quiz attempt, an assignment upload or a grade entry disappears. A lost discussion post is an annoyance. A lost submission during a graded window can trigger appeals, extensions and regulatory questions. Record the answer per activity type and per period of the year, because a backup gap in week one of term matters differently from one in the summer break.
Each target then drives a concrete design choice. A tight recovery point target means more frequent database dumps or replication, plus a backup job that captures moodledata at the same cadence, since uploaded files and the database are only useful together. A tight recovery time target means the backup store must be reachable quickly from the restore environment, and that someone has rehearsed bringing up the code, config.php, the database and the data directory on new hardware. Storage location follows the same logic: keep at least one copy outside the failure domain of the live site. Restore testing consumes the most staff time, so ask your team to estimate how many people, hours and test environments a full restore and a functional check of quizzes, grades and logins will need, and size the test cadence to your assessment calendar.
Confirm each figure with the people who will be blamed if it is missed, and write them down with an owner and a review date. Ask your hosting provider and any Moodle partner to state what they can restore, how long it takes and what they need from you in writing, then test those claims. If you are running a recent release, check its server and database requirements in the Moodle releases page because an emergency rebuild on a different PHP or database version will extend recovery time. Treat the targets as decisions to revisit each term, not as settings you adopt once and forget.
What to confirm in your environment before you rely on a restore
A restore is only as good as the environment it was taken from and the environment it is restored into. The items below are the facts to pin down with your own team, the vendor documentation and your database documentation before you call a backup recoverable. Each one is easy to assume and expensive to discover during an outage.
Exact Moodle and PHP versions
Record the precise Moodle release and PHP version running in production, not the major version alone. A restore must use the same release, and the PHP version must match what the code expects, because the database schema and code are only consistent with each other for the release that wrote them. Confirm the upgrade path from your current release with the Moodle release notes before you plan a rebuild on newer code.
Moodle releasesDatabase engine version support
Confirm that your database engine version is supported by the Moodle release you run, and that your backup method (logical dump, physical copy or a managed snapshot) is supported by that engine version. A dump taken with one client version may not load cleanly into another, so check the database documentation for the restore target. Record the engine version in the backup manifest so the restore team knows what to install.
Data stored outside moodledata
Find every location that holds site data but sits outside moodledata, such as external object storage, a separate repository plugin store, cache directories, or custom scripts writing to disk. A backup of the database and moodledata will miss these, and a restored site will show broken links or missing files. Walk the configuration and the file system with your team and list each location with its owner and backup method.
Web server document root
Confirm that the web server document root points to the directory the release in use expects. From Moodle 5.1, the document root must point to the public directory rather than the main Moodle folder, or the site may show directory listings or errors. A restored server built from an old configuration can fail for this reason even when the data is intact, so include the web server configuration in the restore test.
Moodle 5.1 release notesPlugins restored with the code
Confirm that every third-party plugin is captured with the code backup, at the exact version that matches the database state. Plugin tables and settings live in the database, so a restored database with a missing or older plugin directory will stop the site or fail the upgrade check. Keep a versioned inventory of plugins, including local and theme code, and confirm each one is in the restore set.
Restore tests on the current version
Confirm that a full restore has been completed on the current release, on infrastructure similar to production, within the last change cycle. A backup that was tested on an earlier release, or never tested, is a hypothesis. Record the time the restore took, the steps that needed manual work and the checks that passed, and use those results to set your recovery time targets.
Questions buyers ask about Moodle site backup and restore
Are Moodle course backups enough to protect my learning platform?
No. A course backup from Moodle's course backup function captures one course's content and, optionally, its user data. It does not capture the whole site. A full recovery needs three things captured together: the database, the moodledata directory where uploaded files and caches live, and the code tree, including any custom themes and plugins. Course backups are useful for restoring a single course or moving content, but they cannot rebuild site settings, users, enrolments, grades across the site, authentication configuration or plugins. Treat them as a complementary tool, not as your disaster recovery plan.
What does a whole-site backup involve in effort?
The effort sits in design and proof, not in the copy command. The work includes choosing the backup tooling for your database and file storage, scheduling database and moodledata captures so they describe the same point in time, storing copies off the primary host, setting retention, and documenting who can start a restore. Costs rise with the size of moodledata, the number of environments, storage encryption needs and how many systems must be covered by the same snapshot, such as an external log database or object storage. Ask any provider to split the quote into design, implementation, runbook writing and handover, and to state which parts recur.
How long does a restore test take to plan?
Planning a restore test depends on how much of the site you must rebuild in a separate environment and how well the current backups are documented. Start by confirming the Moodle version, PHP and database versions your backup targets, because restoring onto a different stack can fail before any data is checked. Then agree the test scope: full restore, a sample of courses, or a timed rebuild. Ask your provider or internal team to state the planning and test durations in writing, and to name the assumptions behind them, such as environment availability and data volume. No duration can be stated here without a figure from your own environment.
Can our own team run whole-site backup and restore?
Often yes, if you have a Linux operations group, database administration skill and a habit of testing restores. Internal teams usually struggle with three things: keeping the database and moodledata consistent, repeating restore tests on a schedule rather than once, and updating the runbook after each Moodle upgrade or plugin change. Consider whether the team can commit time for quarterly or per-release restore drills. An outside partner can design the procedure, build the tooling, run the first full test and train your staff, then hand over. Decide which parts you keep in-house before comparing quotes.
What does the work need from our side?
Plan for access and decisions before work starts. You will need administrative access to the servers, database and storage, a named owner for each recovery target, and approved change windows for any backup or restore test that stops the site or writes heavily to the database. Storage for backup copies must be sized and located under your data residency rules, and you need a separate test environment that is not the production site. Confirm whether backups must be encrypted at rest, who holds the keys, and how long copies must be kept. Also confirm which Moodle maintenance steps, such as maintenance mode, your team already uses.
How do recovery time and recovery point targets change the design?
Recovery time objective (how long the site may be down) and recovery point objective (how much data loss is tolerable) set the design. A short recovery time usually means a warm standby, hot database replica or automated restore pipeline, which increases infrastructure and maintenance cost. A tight recovery point means more frequent database captures and continuous file replication, which raises storage and log volume. A relaxed target allows nightly full backups and a manual restore. Agree both targets per component, because grades, file uploads and external integrations may need different values. Write the targets down, then test them. Untested targets are assumptions.
Do we need a documented restore runbook as well as backups?
Yes. A backup that no one can restore under pressure does not meet a recovery need. A runbook records the order of restore steps, the commands and configuration keys to check, how to point the web server document root at the correct directory for your Moodle version, how to verify the restored site, and who approves the cutover. For compliance reviews, the runbook and the dated results of past restore tests are usually the evidence that matters. Ask any provider to deliver the runbook, test records and a handover session as named deliverables.
How DeployOpen scopes and tests Moodle site backups
DeployOpen treats the Moodle site as one system: database, moodledata and the code tree are scoped, backed up and restored together, then proven with a timed restore test in infrastructure you control. Engagements are fixed-scope, with the backup design, restore runbook and test results agreed in writing before work starts.
How we scope
- Inventory the database, moodledata, code, config.php and any external file storage that a restore would need.
- Agree which data classes count as user data, and how long each must be kept under your retention policy.
- Record recovery point and recovery time targets with your learning, operations and compliance owners in writing.
How we build
- Design a backup job that captures the database and moodledata from one agreed point, with a documented consistency approach.
- Configure off-host, encrypted copies of the code tree, configuration and database dumps in storage you control.
- Write a restore runbook covering the database, moodledata, paths and web server document root for your Moodle version.
How we hand over
- Deliver a timed full restore test to a separate environment, with results recorded against your agreed targets.
- Provide the backup schedule, retention settings, alerting rules and access controls as documented configuration.
- Walk your administrators through a restore drill so the runbook is tested by the people who will use it.
How we support
- Retest backups and restores after Moodle upgrades, PHP or database version changes and storage moves.
- Available as a retainer for scheduled restore tests, monitoring review and runbook updates.
- Confirm with your team which vendor, storage and hosting constraints apply before any retest is planned.

