Moodle Backup

Moodle Backup

by Syed Ali -
Number of replies: 3

Hi there,


I am taking backup of moodle database everyday, but now I want to know how often you guys take backup of moodledata folder on server?

Average of ratings: -
In reply to Syed Ali

Re: Moodle Backup

by Brandon Jimenez -

Hello Syed


It'd depend on your needs. So if you have a shared hosting, you could schedule a daily backup, or weekly... 

In reply to Syed Ali

Re: Moodle Backup

by Ken Task -
Picture of Particularly helpful Moodlers
Depends upon site and usage/purpose of site.    A K12 entity in the USA right now is looking at last week of school for many.
So End of Academic Year procedures should come into play.   Teachers reset courses which removes student accounts in the course as well as all of their assignments (uploaded files).   So this week, those following that process, filedir (where the files are really stored) is having files moved from it to trashdir ... and 4 days later, when cron job/task kick in, trashdir cleaned.

Also, if a teacher was wise, right after resetting the course, they would backup the course ... no user ... and keep that one.   But, should remove all backups of the course taken during this academic year.  There is no admin level tool to find all backups, etc..
So this to say there is another bump ... could be upwards if the course content grew.   And, if a teacher leaves without 'check out' process ... account remains, course they used hidden ... lots of potentially space waisting files there - which will remain for ever if not discovered by or taken care of in a 'departing' process.

If you host for a K12 entity, might be wise to contact that K12 entity for some guidance as opposed to assuming.

Do know that k12 entity sites, if not managed nor maintained ... ie, Moodle Admin not really aware of consequencses of lack of action/plan/process ...  could eventually, hit a 'no space left' ... even if the data is on a 1 or 2 TB partition.  And, in the case of DB files actually residing on that same partition and running out of space could have what becomes un-recoverable issues with DB.

Factors?   Are there records retention management policies in play at your entity?   Does your entity provide training courses for international students?

So backing up all of moodledata isn't really required ... but filedir, I would think, is.   Match the daily SQL dump as close as one can.

In case one had to resort to restoring from backups, the older your moodledata backup is compared to the last known good SQL dump might be months.  one then ends up with 'orphaned' meta data mdl_files and possibly 'orphaned' (coud be signficant in size) files themselves which have no reference in DB.

Consider rsyncing at least the filedir directory of the moodledata directory on a daily basis as a means of 'backup'.

A corp ... training is purpose ... international customers ... depends upon training schedule.   Don't have Academic End of Year process need.   How often the training changes, which would/coiuld involve new scorm packages/videos,  kinda determines the scheduling of backups.   Still a good idea to daily SQL dump ... and, I think, a daily rsync of filedir or in this case, file sytem repositories which could be used with aliases ... still in order.

Clear as mud ... huh? ;)
'spirit of sharing', Ken

In reply to Syed Ali

Re: Moodle Backup

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers

Here is the script that I run every night on my VPS.  This is run from CRON at 3am or so each morning.  (You will need to make a few changes to this based upon your own installation, but I think that you will get the idea.  Also, I intermittently move a backup to another system.)

# This is Rick Jerz's backup script for his production Moodle

# It keep 7 days of backup files.

# config.php is also in the moodle backup, but I like to be double safe for this important file.

# 1) config.php, 2) the database, 3) moodle (just to keep the current version), and 4) moodledata

#

# As one might see, I have a folder called "backup_moodle" on my server where I keep the backups.

# Things to improve:

#  Add calculation for amount of time.  Write this to log file.


# #################

# (When sharing, replace (your account), usernamen and password.)

# #################



# Today's Date

NOW=$(date +%F)

# x days ago

WEEKAGO=$(date --date="7 day ago" +%F)


# Delete the old (7 days) files first

rm -f /home/(your account)/backup_moodle/$WEEKAGO-config.php

rm -f /home/(your account)/backup_moodle/$WEEKAGO-moodledb.sql

rm -f /home/(your account)/backup_moodle/$WEEKAGO-moodle.gz

rm -f /home/(your account)/backup_moodle/$WEEKAGO-moodledata.gz


# Backup up the current files

echo Backup the Moodle database

mysqldump -u(your username) -p(your password) --opt -r/home/(your account)/backup_moodle/$NOW-moodledb.sql rjerzx_moodle3

echo Backup config.php

cp /home/(your account)/public_html/moodle/config.php /home/(your account)/backup_moodle/$NOW-config.php

echo Backup moodle

tar cfz backup_moodle/$NOW-moodle.gz public_html/moodle

echo Backup moodledata

tar cfz backup_moodle/$NOW-moodledata.gz moodledata3/


# Future improvements:

# Make an entry into the 'log' file


# Move/copy the backup files to a remote location

# Right now, I do this manually.


# In the future, use rsync the backups to a remote computer.

#   This command doesn't work yet.  It needs a little work.

# rsync -av /home/(your account)/backup_moodle rjerz1@domain.com:/home/rjerz1 --delete


# Notes for Restoring these backups.

#  Forthcoming:


Average of ratings: Useful (1)