I have a bash script I wrote to backup a Moodle installation. It works fine, I've tested the backups, but there's a problem with it; when I do the backups, since I have to use
sudo to type the password every time, I have to physically type in the password instead of just running a
cron job to do it automatically.
Now I suspect this has something to do with either something I don't know about
cron or using an SSH key; either way I'd like to automate the backup.
#!/bin/bash # Turn on Maintance mode and log it... logger "BEGIN Turning on maintance mode in moodle" lynx -cmd_script=./backupScripts/turnOnMaintMode http://moodle.leeand00domain.local logger "END Turning on maintance mode complete." logger "BEGIN Creating Backup Directory" export bkdir=$(date +"%Y-%m-%d") mkdir $bkdir cd $bkdir logger "END Creating Backup Directory" #Get a backup copy of the database logger "BEGIN Backing up the Moodle Database" mysqldump -u moodleuser --password=XXXXX -C -Q -e --create-options moodle > moodle-database.sql logger "END Backing up the Moodle Database" #Get a backup copy of moodle data logger "BEGIN Backing up moodledata" tar -cvzf moodledata.tar.gz --exclude='/var/moodledata/cache' --exclude='/var/moodledata/lang' --exclude='/var/moodledata/sessions' --exclude='/var/moodledata/temp' /var/moodledata && tar -cvzf moodleinstallation.tar.gz /var/www logger "END Backing up moodledata" cd .. tar -cvzf $bkdir.tar.gz $bkdir # Turn off Maintance mode and log it... logger "BEGIN Turning off maintance mode in moodle" lynx -cmd_script=./backupScripts/turnOffMaintMode http://moodle.leeand00domain.local logger "END Turning off maintance mode in moodle complete."