The automated backup script in code/admin/cli/ is pretty much all courses so no reason to attempt interfacing any bash shell. However, backup.php is for single but can ...
Since I have other scripts for mysql queries etc. I got tried of trying to remember things for every server so started using mdlvars.txt for those scripts ... now I only have to edit mdlvars.txt and the other scripts work.
mdlvars.txt - non-executable - readable by root only.
# use checkvars first
# you must manually create the backup directories
# you must provide paths and values.
# paths do NOT have trailing slashes.
# be sure to include the variables between the ticks
mdcode='/var/www/html/moodle34'
mdpath='/var/www/moodle34data'
mddbuser=''
mddbpass=''
mddbname='moodle34ssl'
msbudir='/home/backup/m34'
mcbudir='/home/backup/m34/courses'
mversion='344+'
checkvars - made executable by root only ... viewable by root only
source mdlvars.txt;
echo 'mdcode Path to moodle code: '$mdcode
echo 'mdpath Path to moodle data: '$mdpath
echo 'mddbuser Moodle DB User: '$mddbuser
echo 'mddbname Moodle DB Name: '$mddbname
echo 'mddbpass Moodle DB Pass: '$mddbpass
echo 'msbudir Moodle Backup Directory: '$msbudir
echo 'mcbudir Moodle Backup Courses: '$mcbudir
echo 'Moodle Version: '$mversion
niclbackups - non-interactive backups - make executable by root only
#!/bin/bash
source mdlvars.txt
for i in $(cat ./cids.txt)
do
echo 'Course ID in que:' $i;
php backup.php --courseid=$i --destination=$mcbudir
done
ls -l $mcbudir;
echo 'Done!';
To get cids.txt built:
getcids - make readable by root only and executable by root only.
source mdlvars.txt;
mysql -u $mddbuser -p$mddbpass -e "use $mddbname;select id from mdl_course;"> cids.txt;cat cids.txt
edit cids.txt to remove the columns label and any course id you desire NOT
to backup ... like 1 - which is the front page.
cids.txt looks like:
3
4
5
6
2
One can have a cron job point to: niclbackups
One can copy niclbackups to different versions ... like a niclbackupslarge
and adjust the cids.txt listing for the cids of large courses.
For one run of all courses advise using nohup in conjunction with bash shell script .
https://linux.die.net/man/1/nohup
'spirit of sharing', Ken