Skip to content

Instantly share code, notes, and snippets.

@mariusbutuc
Created November 22, 2012 17:55
Show Gist options
  • Save mariusbutuc/4132374 to your computer and use it in GitHub Desktop.
Save mariusbutuc/4132374 to your computer and use it in GitHub Desktop.
BDU: Take online backup of MOODLE2 and store it in S3 script.
#!/bin/sh
###########################################################
#
# Take online backup of MOODLE2 and store it in S3 script.
#
###########################################################
echo '\n\n################# New MOODLE2 backup ################################################################' >> moodle2_backup.log
export DATABASE=MOODLE2
export TZ='America/Toronto' # set Toronto's timezone, for timestamping logs
echo "$(date) \t | #1: Taking online backup" >> moodle2_backup.log
db2_backup_output=`su - db2inst1 -c "db2 backup database $DATABASE online TO /mnt/backups/ include logs"`
echo $db2_backup_output >> moodle2_backup.log
echo "\n$(date) \t | #2: Test the integrity of the backup image" >> moodle2_backup.log
backup_file_full_path=`ls -t1 /mnt/backups/$DATABASE* | head -n1` # full path of the latest backup file
db2ckbkp_output=`su - db2inst1 -c "db2ckbkp $backup_file_full_path" | grep -i 'error\|success'` # case insen. grep for success/error
echo $db2ckbkp_output >> moodle2_backup.log
echo "\n$(date) \t | #3: Store backup image (S3)" >> moodle2_backup.log
backup_file_name_only=`ls -t1 /mnt/backups/$DATABASE* | head -n1 | cut -d/ -f4`
s3_put_output=`s3cmd put $backup_file_full_path s3://bigdatauniversity/$DATABASE/$backup_file_name_only`
echo $s3_put_output >> moodle2_backup.log
echo "\n$(date) \t | #4: TODO: Was the backup stored successfully (S3)?" >> moodle2_backup.log
#TODO: Optionally, using Rightscale, you can check the backup was uploaded to the S3 bigdatauniversity bucket successfully.
echo "\n$(date) \t | #4: Backup finished" >> moodle2_backup.log
echo "Backup finished"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment