Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OERu
Gitlab Backup
Commits
1de8de1c
Commit
1de8de1c
authored
Mar 10, 2021
by
Dave Lane
Browse files
initial commit of working code
parent
931ab95e
Changes
2
Hide whitespace changes
Inline
Side-by-side
gitlabbackup-cron
0 → 100644
View file @
1de8de1c
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
gitlabbackup.sh
0 → 100755
View file @
1de8de1c
#!/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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment