Commit 1de8de1c authored by Dave Lane's avatar Dave Lane
Browse files

initial commit of working code

parent 931ab95e
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
#
# run system backups
#
# daily - at 7:30 pm, mon-sun
30 21 * * * root /home/data/scripts/gitlabbackup/gitlabbackup.sh
#!/bin/bash
#
# Author: dave@oerfoundation.org
# License: GPL v3 (or latest)
#
# the purpose of this script is to backup up the current docker-compose-deployed Gitlab instance into
# a directory on the host, suitable for including in the host's incremental file backups.
#
DC=`which docker-compose`
DIR=/home/docker/git.oeru.org
CONTAINER=web
COMMAND='gitlab-rake gitlab:backup:create'
LOG=/var/log/gitlabbackup.log
DATE=`date`
DATESTR=`date +"%Y_%m_%d"`
TESTSTR='Creating backup archive:'
BUDIR=$DIR/backups
BUPAT="*_gitlab_backup.tar"
TMP=/tmp
#
# run the actual command
CWD=`pwd`
cd $DIR
# first check that the container's running
if [[ `$DC ps | grep -c "$CONTAINER"` == 1 ]] ; then
# backup, using this command
OUT=`$DC exec -T $CONTAINER $COMMAND`
# check the output for "Creating backup archive:"
RESULT=`echo "$OUT" | grep "$TESTSTR" -`
#echo "Result = $RESULT"
# get the name of the backup:
BU=`echo $RESULT | sed "s/^$TESTSTR \(.*\.tar\).*$/\1/g"`
#echo "Backup file: $BU"
if [[ ! -z $BU ]] ; then
echo "created backup: $BU in $BUDIR"
echo "protecting latest backup"
echo "mv $BUDIR/$BU $TMP"
#echo `ls -l $BUDIR`
mv $BUDIR/$BU $TMP
#echo `ls -l $TMP/$BU`
if [[ -f $TMP/$BU ]] ; then
echo "remove other backups in $BUDIR"
echo "removing $BUDIR/$BUPAT"
rm $BUDIR/$BUPAT
echo "releasing latest backup"
mv $TMP/$BU $BUDIR
else
echo "failed to protect backup, not removing other backups in $BUDIR"
fi
else
echo "failed to create a backup!"
fi
else
echo "Container \"$CONTAINER\" does not appear to be running."
fi
cd $CWD
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment