Backup of multiple courses in a course category

Backup of multiple courses in a course category

by Rahul Palyam -
Number of replies: 4

Hello moodle devs,

I am relatively new to moodle development, with little knowledge of PHP which makes it difficult. If someone would help me with the below problem that would be great.

My moodle website version is 3.1.1. For an admin access, right now there is an option to backup a single course as seen below.

Backup option for course


I wanted to know if there is an admin setting which allows to backup multiple courses at the same time?

Thanks in advance for your help!

Average of ratings: -
In reply to Rahul Palyam

Re: Backup of multiple courses in a course category

by Ken Task -
Picture of Particularly helpful Moodlers

Not a dev myself, but do admin several instances of Moodle on Linux platform.   Moodle config (automated backups or single course backups) are not done all at once ... but rather one at a time.   Backups are intensive processing.

So think to get what you want you'll have to resort to the scripts in moodlecode/admin/cli/ .... of which there is one for backing up a single course - backup.php

One could create a txt file that is nothing more than the course ID's you desire to backup and then loop a bash shell script through the cids.txt file to backup each course.    I'd also make sure to use the 'destination' option of backup.php so that the backups don't get lost in the sea of files in moodledata/filedir/

Here's an example of a bash shell script that backs up just one course:

cat courses.txt;
echo 'This backups up the course ID given it from list above.';
echo 'Course ID: '$1;
echo 'paused ...';
read $keypress;
php backup.php --courseid=$1 --destination=/home/backup/m33/

A cli script to get course ID's:

mysql -u root -p'' -e "use moodle2;select id from mdl_course;" > courseids.txt;cat courseids.txt

You'd have to edit the courseids.txt file and remove the first line so that all that file contains is the CID's you want to backup.

Here's a looper bash shell script example:

for i in `cat ./courselist2.txt`
do
    echo "Course ID in que:" $i;
    php backup.php --courseid=$i --destination=/home/clibackups/
done

The courselist2.txt file is nothing more than a text file with the course ID's to backup ... each CID on a single line:

Like so:
20
21
22
23
383

I'd skip CID 1 as that is the front page ... which cannot be restored to the front page anyway.

'spirit of sharing', Ken


Average of ratings: Useful (2)
In reply to Ken Task

Re: Backup of multiple courses in a course category

by Rahul Palyam -

Thanks a lot for sharing the info Ken, i'll give this a try for now.. However i wanted to know if there was an option in the web interface.. I found a plugin which has this function, have to explore that.

In reply to Rahul Palyam

Re: Backup of multiple courses in a course category

by Ken Task -
Picture of Particularly helpful Moodlers

Welcome.   But you say you found a plugin for that?   Mind sharing back?  URL to plugin ... I'd like to try that out also.

'spirit of sharing', Ken