Skip to content

Commit

Permalink
Merge pull request #44 from sund/develop
Browse files Browse the repository at this point in the history
Merge v1.7 • Disturbing Lack of Faith
  • Loading branch information
sund authored Jul 1, 2016
2 parents 0a44b74 + 261b819 commit f4bc212
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 12 deletions.
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@

## Synopsis

A script to use omnibus-gitlab's own backup ```gitlab-rake``` command on a cron schedule and rsync to another server, if wanted. There is also a restore script available (see below.)
A simple script to backup your Gitlab data. This script will copy the backup archives of your gitlab installation via rsync, or scp. Also, you can copy backups to [Backblaze’s B2 Cloud Storage service.](https://www.backblaze.com/b2/cloud-storage.html) There is also a restore script available (see below.)

It can backup and copy the Gitlab-CI DB, if configured.
It can backup and copy the ```gitlab.rb``` config file, if configured.

This script is now more omnibus-gitlab centric. Compare your config file with the template! Usage with a source install is possible but not expressly shown here.

## Installation

### Prerequisites

Deploy a working GitLab installation and verify you can back it up with the rake task as documented in the [GitLab Documents](http://doc.gitlab.com/ce/raketasks/backup_restore.html).
Deploy a working GitLab Omnibus installation and verify you can back it up with the rake task as documented in the [GitLab Documents](http://doc.gitlab.com/ce/raketasks/backup_restore.html).

For Backblaze usage, configure your system for the [Backblaze Command-Line Tool](https://www.backblaze.com/b2/docs/quick_command_line.html) Also, see the [wiki page on B2](https://github.com/sund/auto-gitlab-backup/wiki/Backblaze-B2-Command-Line-Tool).

#### Set up gitlab to expire backups

Expand Down Expand Up @@ -62,6 +64,22 @@ sshKeyPath=""
## $remoteServer path for gitlab backups
remoteDest="/var/opt/gitlab/backups"

## backup gitlab configs
# change to 1 to enable
backupConfigs=“0”

## rake quietly
# change to 1 to enable quiet rake job
quietRake=0

## enable backblaze b2 sync
# change to 1 to enable
# and set bucket name
# and change b2keepDays if other than 5 days is desired
b2blaze=0
b2Bucketname=“”
b2keepDays=“5”

## set $localConfDir
# blank disables conf backups
# you can create /var/opt/gitlab/backups/configBackups --
Expand Down Expand Up @@ -114,3 +132,11 @@ Example for crontab to run at 5:05am everyday.
*Still under development but useful*

run ```./restoreGitLab.sh -r``` and it will attempt to restore a backup. You may have to run some rake commands manually.

## Help

See the [Wiki](https://github.com/sund/auto-gitlab-backup/wiki) for more detailed instructions or submit a [Issue](https://github.com/sund/auto-gitlab-backup/issues).

## Contribute

See [Contribution Guide](https://github.com/sund/auto-gitlab-backup/blob/master/CONTRIBUTING.md) to improve this script.
Binary file modified agb_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions auto-gitlab-backup.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ remoteDest="/var/opt/gitlab/backups"
# change to 1 to enable
backupConfigs="0"

## rake quietly
# change to 1 to enable quiet rake job
quietRake=0

## enable backblaze b2 sync
# change to 1 to enable
# and set bucketname
# and change b2keepDays if other than 5 days is desired
b2blaze=0
b2Bucketname=""
b2keepDays="5"

## set $localConfDir
# blank disables conf backups
# you can create /var/opt/gitlab/backups/configBackups --
Expand Down
170 changes: 161 additions & 9 deletions auto-gitlab-backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ gitlab_rails="/opt/gitlab/embedded/service/gitlab-rails"
PDIR=$(dirname $(readlink -f $0))
dateStamp=`date +"%F %H:%m:%S"`
confFile="$PDIR/auto-gitlab-backup.conf"
rakeBackup="gitlab-rake gitlab:backup:create"
if [[ $quietRake == 1 ]]
then
rakeBackup="gitlab-rake gitlab:backup:create CRON=1"
else
rakeBackup="gitlab-rake gitlab:backup:create"
fi

###
## Functions
Expand Down Expand Up @@ -70,15 +75,20 @@ checkSize() {

archiveConfig() {
echo ===== Archiving Configs =====
if [[ -w $localConfDir && $backupConfigs = 1 ]]
if [[ $backupConfigs = 1 ]]
then
tar -czf "$localConfDir/gitlabConf-$dateStamp.tgz" $localConfig $localsshkeys
if [[ -w $localConfDir ]]
then
tar -czf "$localConfDir/gitlabConf-$dateStamp.tgz" $localConfig $localsshkeys

# remove files not within 3 days
find $localConfDir -type f -mtime +3 -exec rm -v {} \;
# remove files not within 3 days
find $localConfDir -type f -mtime +3 -exec rm -v {} \;

else
echo "$localConfDir is not writable."
fi
else
echo "Local config backup aren't enabled or $localConfDir is not writable."
echo "Local config backups aren't enabled!"
fi
}

Expand Down Expand Up @@ -152,7 +162,6 @@ rsyncKey_dryrun() {
fi
}


rsyncDaemon() {
# rsync up with specific key
echo =============================================================
Expand Down Expand Up @@ -185,7 +194,6 @@ rsyncDaemon_dryrun() {
fi
}


sshQuotaKey() {
#quota check: with a key remoteServer, run the quota command
if [[ $checkQuota == "true" || $checkQuota = 1 ]]
Expand Down Expand Up @@ -221,7 +229,7 @@ usage() {
echo "Usage:"
echo "$0 -h | --help this help page"
echo "$0 -d | --dry-run test rsync operations; no data transmitted."
echo "$0 no options, perform backup and rsync."
echo "$0 no options, perform backup, rsync or b2 operations."
echo ""
}

Expand All @@ -239,6 +247,144 @@ areWeRoot() {
fi
}

b2Sync() {
# b2 sync
echo =============================================================
echo -e "Start b2 sync of $gitRakeBackups to bucket $b2Bucketname \n"

if [[ $b2blaze == 0 ]]
then
echo "Backblaze b2 file operations not enabled!"
else

# test for b2 command
if type b2 > /dev/null 2>&1
then
# bucketname set and readable
if [ ! -z $b2Bucketname ]
then
if test -r "$gitRakeBackups" -a -d "$gitRakeBackups"
then
b2 sync --noProgress --keepDays $b2keepDays --replaceNewer $gitRakeBackups/ b2://$b2Bucketname/backups/
else
echo " gitRakeBackups ($gitRakeBackups) not readable."
fi
else
echo " b2Bucketname not set."
fi
else
echo " b2 command not found!"
fi

fi
echo ""
}

b2SyncProgress() {
# b2 sync
echo =============================================================
echo -e "Start b2 sync of $gitRakeBackups to bucket $b2Bucketname \n"

if [[ $b2blaze == 0 ]]
then
echo "Backblaze b2 file operations not enabled!"
else

# test for b2 command
if type b2 > /dev/null 2>&1
then
# bucketname set and readable
if [ ! -z $b2Bucketname ]
then
if test -r "$gitRakeBackups" -a -d "$gitRakeBackups"
then
b2 sync --keepDays $b2keepDays --replaceNewer $gitRakeBackups/ b2://$b2Bucketname/backups/
else
echo " gitRakeBackups ($gitRakeBackups) not readable."
fi
else
echo " b2Bucketname not set."
fi
else
echo " b2 command not found!"
fi

fi
echo ""
}

b2SyncConf() {
# b2 sync
echo =============================================================
echo -e "Start b2 sync of /etc/gitlab to bucket $b2Bucketname/configs/ \n"

if [[ $backupConfigs == 1 ]]
then
if [[ $b2blaze == 0 ]]
then
echo "Backblaze b2 file operations not enabled!"
else

# test for b2 command
if type b2 > /dev/null 2>&1
then
# bucketname set and readable
if [ ! -z $b2Bucketname ]
then
if test -r "$gitRakeBackups" -a -d "$gitRakeBackups"
then
b2 sync --noProgress --keepDays $b2keepDays --replaceNewer /etc/gitlab/ b2://$b2Bucketname/configs/
else
echo " gitRakeBackups ($gitRakeBackups) not readable."
fi
else
echo " b2Bucketname not set."
fi
else
echo " b2 command not found!"
fi

fi
fi
echo ""
}

b2SyncConfProgress() {
# b2 sync
echo =============================================================
echo -e "Start b2 sync of /etc/gitlab to bucket $b2Bucketname/configs/ \n"

if [[ $backupConfigs == 1 ]]
then
if [[ $b2blaze == 0 ]]
then
echo "Backblaze b2 file operations not enabled!"
else

# test for b2 command
if type b2 > /dev/null 2>&1
then
# bucketname set and readable
if [ ! -z $b2Bucketname ]
then
if test -r "$gitRakeBackups" -a -d "$gitRakeBackups"
then
b2 sync --keepDays $b2keepDays --replaceNewer /etc/gitlab/ b2://$b2Bucketname/configs/
else
echo " gitRakeBackups ($gitRakeBackups) not readable."
fi
else
echo " b2Bucketname not set."
fi
else
echo " b2 command not found!"
fi

fi
fi
echo ""
}

confFileExist() {
# read the conffile
if [ -e $confFile -a -r $confFile ]
Expand Down Expand Up @@ -267,15 +413,18 @@ case $1 in
if [[ $remoteModule != "" ]]
then
rsyncDaemon_dryrun
b2SyncProgress
# no Daemon so lets see if we are using a special key
else if [ -e $sshKeyPath -a -r $sshKeyPath ] && [[ $sshKeyPath != "" ]]
then
rsyncKey_dryrun
b2SyncProgress
sshQuotaKey
else if [[ $remoteServer != "" ]]
then
# use the defualt
rsyncUp_dryrun
b2SyncProgress
sshQuota
fi
fi
Expand All @@ -295,15 +444,18 @@ case $1 in
if [[ $remoteModule != "" ]]
then
rsyncDaemon
b2Sync
# no Daemon so lets see if we are using a special key
else if [ -e $sshKeyPath -a -r $sshKeyPath ] && [[ $sshKeyPath != "" ]]
then
rsyncKey
b2Sync
sshQuotaKey
else if [[ $remoteServer != "" ]]
then
# use the defualt
rsyncUp
b2Sync
sshQuota
fi
fi
Expand Down

0 comments on commit f4bc212

Please sign in to comment.