Simple backup scripts for Moodle site

Simple backup scripts for Moodle site

by steve baxter -
Number of replies: 0

Apologies if this topic has been covered before I couldn't find anything on the forum exactly the same.

Here are a couple of simple backup scripts which will do a complete weekly backup in tar.gz format and incremental daily backup. They also delete old weekly backups (one month) and daily (older than 7 days). 

The scripts are for linux servers. Replace MYSQLREADUSER and MYSQLPASSWORD with your own database user with read access to the moodle database. You should have a backup path available and substitute this for the backup path in the script. Place the daily script in /etc/cron.daily and the weekly in /etc/cron.weekly you will also need to make the scripts executable:

# chmod +x daily.sh
# chmod +x weekly.sh

I have the following backup targets which are samba shares on a NAS:

/moodlebackups/daily
/moodlebackups/weekly

You can easily extend this to backup multiple moodle installations.

Comments and Improvements would be most welcome. Scripts included as text below:

 

#!/bin/sh
#
#Moodles backup script - INCREMENTAL DAILY
#created : 14th July 2008
#author : s baxter
#moodlebackups is a samba share on backup server
#
#removes sql files older than a week at the end
#
Today="`date +%d_%m_%y`";
#moodle - DAILY
sudo mysqldump -uMYSQLREADUSER -pMYSQLPASSWORD moodle > /tmp/moodle_$Today.sql
sudo cp /tmp/moodle_$Today.sql /moodlebackups/daily/
sudo rm /tmp/moodle_$Today.sql
sudo cp /var/moodledata /moodlebackups/daily/ -R -u
sudo cp /var/www/moodle /moodlebackups/daily/ -R -u
#remove old sql files
sudo find /moodlebackups/daily -name "*.sql" -mtime +7 -exec rm {} \;

 

 

 

#!/bin/sh
#
#Moodles backup script - COMPLETE WEEKLY
#created : 14th July 2008
#author : s baxter
##moodlebackups is a samba share on backup server
#
#removes files older than a month at the end
#
Today="`date +%d_%m_%y`";
#moodle - WEEKLY
sudo mysqldump -uMYSQLREADUSER -pMYSQLPASSWORD moodle > /tmp/moodle_$Today.sql
sudo tar -zcpf /tmp/moodle_$Today.tar.gz /var/moodledata /var/www/moodle /tmp/moodle_$Today.sql
sudo cp /tmp/moodle_$Today.tar.gz /moodlebackups/weekly/
sudo rm /tmp/moodle_$Today.tar.gz
sudo rm /tmp/moodle_$Today.sql
sudo find /moodlebackups/weekly -name "*.tar.gz" -mtime +30 -exec rm {} \;

 

 

Average of ratings: Useful (1)