Moosh - Bulk Backup Restore Courses

Given a file with content as below per line which can be created based on sudo -u www-data moosh course-list | awk -F "," '{ print $1 "," $3}':

"1234","XX - XXXX/XXX/XX"

This will perform a backup to /var/backups/moodle/(courseshortcode):

while read i; do \
echo $i |\
sed 's/\"//g' |\
sed 's/\//_/g' |\
awk -F ',' '{ print "time sudo -u www-data moosh course-backup -f " "'\''/var/backups/moodle/"$2".mbz'\'' " $1}';\
done < migrated_ok_id

Transfer backup files over:

rsync -ah --progress [email protected]:/var/backups/moodle/* /var/backups/moodle/.

Given a folder with backup files as below:

# ls -1 /var/backups/moodle
XXXX-X-XXX_XXXX_XX.mbz

Format filenames to course shortcodes including / removing .mbz:

ls -1 /var/backups/moodle | sed s/\_/\\//g | sed s/\.mbz$//g > /home/x/restore

Get a list of course IDs for the backup courses above based on course shortcodes:

sudo -u www-data moosh course-list | grep -f /home/x/restore | awk -F ',' '{ print $1 "," $3 }' | sed s/\"//g | sed s/\\//_/g | sed s/$/.mbz/g > /home/x/restore_clean

Based on the backup files above and corresponding course ids based on course shortcodes perform the restore:

while read i; do \
echo $i |\
awk -F ',' '{ print "time sudo -u www-data moosh course-restore -o " "'\''/var/backups/moodle/"$2"'\'' " $1}';\
done < restore_clean