Skip to content

Instantly share code, notes, and snippets.

@carsongee
Created January 20, 2015 14:50
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carsongee/9f64e40656c27885ab61 to your computer and use it in GitHub Desktop.
Save carsongee/9f64e40656c27885ab61 to your computer and use it in GitHub Desktop.
course backup to git script for edx-platform
#!/bin/bash
# This script assumes that the git repository is already cloned
# App specifics
EDXAPP_USER="edxapp"
EDXAPP_VENV="/edx/app/edxapp/venvs/edxapp"
EDXAPP_DIR="/edx/app/edxapp/edx-platform"
# Git specifics
export GIT_KEY="/edx/app/course_git_backup/git_backup_deploy"
export EXPORT_DIR="/mnt/course_git_backup"
SERVICE_VARIANT='cms'
git config --global push.default simple
# Dump the courses - ignoring output since it is nasty about stderrs that aren't stderrs
su - $EDXAPP_USER -s /bin/bash -c "cd $EDXAPP_DIR; SERVICE_VARIANT=$SERVICE_VARIANT $EDXAPP_VENV/bin/python manage.py $SERVICE_VARIANT --settings=aws export_all_courses $EXPORT_DIR" > /dev/null 2>&1
cd $EXPORT_DIR
git add .
if [ $? -ne 0 ]; then
echo "Automated course_git_backup has failed, unable to add" >&2
exit 1
fi
git commit -a -m "Automated backup of course xml from cron task at $(date)"
if [ $? -ne 0 ]; then
echo "Automated course_git_backup has failed, unable to commit." >&2
exit 1
fi
ssh-agent bash -c 'ssh-add $GIT_KEY; cd $EXPORT_DIR; git push -q' |& grep -v 'Identity added:'
if [ ${PIPESTATUS[0]} -ne 0 ]; then
echo "Automated course_git_backup has failed, unable to push" >&2
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment