**Moodle backups to external location**

TL;DR

Backuping Moodle1 server to external location requires some gymnastics and the setup is not straight forward. There are plugins that can backup using FTP2, but I didn’t explore them.

What I wanted to accomplish was 1. firstly, moving course backups out of Moodle’s strange file structure and 2. backuping them to external server (Koofr via rclone). Simply put:

Moodle filearea –> /var/backups –rclone–> Koofr

Courses backup is the second backup strategy I’m using. The first one is a daily backup of a virtual server from a proxmox host to NAS via NFS.

1. Set Moodle’s automated backup location (same server)

Firstly, I had to convince Moodle to store backups of courses in my folder.

Moodle -> Site Admin / Courses / Backup / Automated backup setup

Automated backup storage setting is set to Course backup filearea by default. Moodle’s filearea is accessible (in /moodledata/), but the naming of folders and files is … unfriendly to put it mildly and I can’t make any of it. Take a look:

I wanted to change it to ‘Course backup filearea and the specified directory‘. But I couldn’t, because my Moodle install does not allow manually setting paths from admin UI (it’s a security setting). I didn’t want to circumvent it ($CFG->preventexecpath = true; in config.php).

So I had to set the backup path in Moodle’s config.php. Firstly, I couldn’t find how to set it, then I found it in one forum post3.

But firstly, I created a directory where I want my backups and allowed that user www-data (apache server) can write to it:

mkdir /var/moodlebackups chown www-data:www-data /var/moodlebackups chmod 750 /var/moodlebackups

Then I modified Moodle’s config.php and added the location4:

$CFG->forced_plugin_settings['backup']['backup_auto_destination'] = '/var/moodlebackups';

Went back to Moodle’s admin UI, refreshed and I could see the backup location:

Finally I could set Automated backup storage to Course backup filearea and the specified directory.

2. Backup to remote location using rclone and Koofr5

Now that I convinced Moodle to spit out backups of courses to the location I wanted, I proceeded with:

1. Install and configure rclone (a program to copy/sync files to variety of cloud services)

apt install rclone rclone config

To configure rclone, I just followed these instructions.

2. I made a new folder in my Koofr for Moodle backups and tested the connection:

List Koofr dirs:

rclone lsd koofr:Backups/Moodle

Test copying from local folder to Koofr:

rclone copy /var/moodlebackups/ koofr:Backups/Moodle --progress

I used ‘rclone copy’ instead of ‘sync’, because I want copies: if something happens to backups on Moodle server (e. g. get corrupted, compromised or deleted), I don’t wont this to propagate to backup on Koofr.

3. Lastly, I created a cron job that runs rclone every morning at 6AM6 and writes to a log about it:

crontab -e 0 6 * * * /usr/bin/rclone copy /var/moodlebackups koofr:/Backups/Moodle --log-file=/var/log/rclone_backup.log --verbose

In the morning I checked the Koofr’s Backup folder and … voila, backups are there.

Now I have another piece of mind in case anything goes wrong.

  • v4.5 ↩︎
  • For example https://moodle.org/plugins/local_backupftp ↩︎
  • https://moodle.org/mod/forum/discuss.php?d=453937 ↩︎
  • finding this setting gave me a lot of headache. As a last resort, I asked LLM, but it couldn’t help me. Of course it didn’t, what did I expect. It persistently tried to convince me that the right setting is $CFG->autobackuplocation = ‘/var/moodlebackups’, which is wrong. Another proof of LLM’s incapability and my naïveté. But then, I dug in Moodle’s forums (above) and found the right config keyword. Thank you, PEOPLE, especially Susana L.! ↩︎
  • Cloud storage from EU, https://koofr.eu/ ↩︎
  • Why at 6AM? Because Moodle automated backups run at 4AM and they are finished in a few minutes. ↩︎
  • https://blog.rozman.info/moodle-backups-to-external-location/ #backup #koofr #moodle #rclone
    @tomi @po3mah as moodle admin myself, I have so much stories to tell…
    @miskolin @tomi @po3mah Why are you guys admining moodle? For schools and such?
    @mihamarkic @miskolin @tomi Not for schools, but for some adult training/learning projects and as a support env for some consulting activities for companies.
    + it serves as a backend for certificate issuing system.
    We dropped TalentLMS because of 'per user' subscription model and now we have what we have.
    It's fine, until it's not.
    @po3mah @mihamarkic @tomi we are using it for 15 years, no major issues. v4 for now, moving to v5 in summer. Teachers/students know how to use it. It is fine.
    @miskolin @mihamarkic @tomi When I accepted I have to submit bug reports occasionally and then wait for updates to fix bugs, dig through forums for solutions, assemble some things by myself, run manual sql queries for advanced reports like an animal... it's fine :)
    It's like an Ikea package with some missing parts,
    :)