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/moodlebackupsThen 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 --progressI 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 --verboseIn 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.

