Giter Club home page Giter Club logo

sund / auto-gitlab-backup Goto Github PK

View Code? Open in Web Editor NEW
313.0 19.0 73.0 815 KB

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.

Home Page: http://sund.github.io/auto-gitlab-backup/

License: GNU General Public License v2.0

Shell 100.00%
backup gitlab-installation backup-archive auto-gitlab-backup shell backup-script rsync

auto-gitlab-backup's Introduction

Auto GitLab Backup

AGB Logo


Synopsis

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. There is also a restore script available (see below.)

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 Omnibus installation and verify you can back it up with the rake task as documented in the GitLab Documents.

For Backblaze usage, configure your system for the Backblaze Command-Line Tool Also, see the wiki page on B2.

Set up gitlab to expire backups

Change /etc/gitlab/gitlab.rb to expire backups

# backup keep time
gitlab_rails['backup_keep_time'] = 604800

Installation

Clone to your directory of choice. I usually use /usr/local/sbin

git clone [email protected]:sund/auto-gitlab-backup.git

Updates

Compare the auto-gitlab-backup.conf.sample file with your own copy. Make changes as needed to ensure no errors are encountered.

Configure

cp auto-gitlab-backup.conf.sample auto-gitlab-backup.conf

edit auto-gitlab-backup.conf

## user account on remote server
#  likely 'git' user
remoteUser=""

## remote host
#  a backup gitlab server?
remoteServer=""

## path to an alternate ssh key, if needed.
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 --
# gitlab doesn't seem to complain with a subfolder
# in there. Plus it will rsync up with the backup.
# So you won't need to enable a separate rsync run
localConfDir="/var/opt/gitlab/backups/configBackups"

## set $remoteServer path for gitlab configs
# blank disables remote copy
# unless $localConfDir is outside /var/opt/gitlab/backups/configBackups
# you can leave this blank
remoteConfDest=""

## ssh port or 873 for rsyncd port
remotePort=22

## git user home.
#  Only change the below setting if you have git's home in a different location
gitHome="/var/opt/gitlab"

## only set below if rvm is in use and you need to source the rvm env file
# echo $(rvm env --path)
RVM_envPath=""

## only use the below settings if your destination is using rsync in daemon mode
remoteModule=""
rsync_password_file=""

## only change if configs are in different locations. (unlikely)
localConfig="/etc/gitlab"
localsshkeys="/var/opt/gitlab/.ssh"

## Check remote quota
#  change to true or 1 to enable
checkQuota="0"

cron settings

Example for crontab to run at 5:05am everyday.

5 5 * * * /usr/local/sbin/auto-gitlab-backup/auto-gitlab-backup.sh

Restore

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 for more detailed instructions or submit a Issue.

Contribute

See Contribution Guide to improve this script.

auto-gitlab-backup's People

Contributors

dmitry-kovalev avatar jcalonso avatar klasyc avatar lytsing avatar soraver avatar sund avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

auto-gitlab-backup's Issues

errors with GL 8.5.0

/usr/local/sbin/auto-gitlab-backup/auto-gitlab-backup.sh: line 101: gitlab-ci-rake: command not found

testing mode

for testing ssh and rsync operations, create a testing mode that skips the rake operations and goes directly to rsync functions. Maybe also some debugging and printing variables.

How to save ssh remote password?

Hi, first of all, i want to thank you for this helpful script!
It works fine manually but each time I launch your script with "/usr/local/sbin/auto-gitlab-backup/auto-gitlab-backup.sh", it asks me the remote ssh password.
In fact, I can't find option in "auto-gitlab-backup.conf" which refers to remote password. Is it "rsync_password_file"?
Thanks

Permission issue when raking ci backups

root ᐅ varina → /var/opt/gitlab/ci-backups ᐉ  gitlab-ci-rake backup:create
Applying final database migrations ... 
done
Dumping database ... 
Dumping PostgreSQL database gitlab_ci_production ... [DONE]
done
Dumping builds ... 
tar: /var/opt/gitlab/gitlab-ci/builds: Cannot chdir: Permission denied
tar: Error is not recoverable: exiting now
done
Creating backup archive: 1453914753_gitlab_ci_backup.tar ... done
Uploading backup archive to remote storage  ... skipped
Deleting tmp directories ... done
done
done
Deleting old backups ... done. (0 removed)


Your final CI export is in the following file:

-rw-r--r-- 1 gitlab-ci gitlab-ci 90K Jan 27 12:12 /var/opt/gitlab/ci-backups/1453914753_gitlab_ci_backup.tar

Directory permissions to restrictive for root to access:

ll /var/opt/gitlab/gitlab-ci
total 32
drwx------ 4 git       git        4096 Oct  1 15:18 builds

Manually fix:

sudo chown -R git:root /var/opt/gitlab/gitlab-ci/builds/
sudo chmod -R g+rwx /var/opt/gitlab/gitlab-ci/builds/

Wait and see if the next upgrade fixes/breaks things.

fatal error when raking a backup

root ᐅ varina → /var/opt/gitlab/backups ᐉ  gitlab-rake gitlab:backup:create
fatal: Not a git repository (or any of the parent directories): .git
Dumping database ... 

typo

fix in readme:

5 5 * * * /usr/local/sbin/autogitbackup/auto-gitlab-backup.sh 

to show real path

restore also run gitlab rewrite-hooks.sh

last import hooks were wrong and no updates in imported repos were notes on Dashboard.

Might just 'borrow' code as for installs with custom git home, it will fail.

Fix or find workaround to permissions change

===== Archiving Configs =====
Local config backup aren't enabled or /var/opt/gitlab/backups/configBackups is not writable.

permissions change on folder overtime gitlab is updated. find a work around or other location for backups.

update logo for readme

Have following elements based on features available:

icons to show:

  • repo backup
  • config backup
  • remote copy (rsync)

rsync (1)use custom Port; (2)server url should be “$remoteUser@$remoteServer::$remoteDest”

rsync Problem
(1)use custom Port;
(2)server url should be “$remoteUser@$remoteServer::$remoteDest”

rsyncUp() {

rsync up with default key

echo =============================================================
echo Start rsync to rsync.net/backup no key
echo =============================================================
#rsync -Cavz --delete-after /$gitRakeBackups/ $remoteUser@$remoteServer:$remoteDest
rsync -Cavz --port=$remotePort --password-file=$rsync_password_file --delete-after /$gitRakeBackups/ $remoteUser@$remoteServer::$remoteDest

}

restore faild

root@gitlab backups]# cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
11.11.4
[root@gitlab backups]# ll
total 227840
-rw------- 1 git git 233308160 Jul 11 17:45 1562838333_2019_07_11_11.11.4_gitlab_backup.tar

[root@ELK-SZ-03 backups]# cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
11.11.4
[root@ELK-SZ-03 backups]# gitlab-rake gitlab:backup:restore BACKUP=1562838333_2019_07_11_11.11.4_gitlab_backup.tar
The backup file 1562838333_2019_07_11_11.11.4_gitlab_backup.tar_gitlab_backup.tar does not exist!

Auto ssh password

hi there

Great script thanx!!! is there a way to automate the ssh password, as currently i need to add the remote dir ssh password before it cab copy the backup to the remote dir. So cant run it automatically

unified

Merge omnibus and the regular master branch so that it doesn't matter which instal (omnibus or other) is used, the master branch is production.

Backup repository wrong located (omnibus)

When trying to make the backup it tries to open this folder:
du: cannot access /var/opt/gitlab/gitlab/tmp/backups': No such file or directory
`

and the folder should be /var/opt/gitlab/backups

To fix that gitlabHome and gitRackeBackups should have this values:
gitlabHome="$gitHome/" gitRakeBackups="$gitlabHome/backups"

This is from the omnibus-master branch.

It keeps asking me for password.

Here's my configuration:

remoteUser="ada" #user account on remote server
remoteServer="ada-datanode4" #remote host
remoteDest="/home/ada/gitlab_backup" #remote path
sshKeyPath="" #path to an alternate ssh key, if needed.
remotePort=22 # ssh port or 873 for rsyncd port
## Only change the below setting if you have git's home in a different location
gitHome="/var/opt/gitlab"
## only set below if rvm is in use and you need to source the rvm env file
# echo $(rvm env --path)
RVM_envPath=""
## only use the below settings if your destination is using rsync in daemon mode
remoteModule=""
rsync_password_file=""
checkQuota="" #change to true or 1 to enable

I've ssh-copy-id so I thought there's no need to use password, but when I ran auto-gitlab-backup.sh it always asking me for password.

Deleting old backups ... skipping
===== Sizing =====
Total disk space used for backup storage..
Size - Location
3.0G /var/opt/gitlab/backups

=============================================================
Start rsync to
ada-datanode4:/home/ada/gitlab_backup
default key

ada@ada-datanode4's password:

How to solve this problem?
Another question, the backup_keep_time setting only affect backup files in local machine, but backup files transfered to remote server will not be affected, correct?

Config backup names are not kept

Really liking this script, saved me sooo much time trying to figure out bash and rsync. A++++ :)

Only little issue I seem to have is in regards to the config backups. I have configured the script to also automate and move backing up the gitlab configuration, this works brilliantly. I followed the default way of having a configBackups directory within the main Gitlab backups folder. The backups work and are copied over to my other machine via rsync. However, the names of these backups are not kept. The names of the main rake backups are kept though. I thought maybe it was because there was a space in the file names, but this wasn't the case.

For example a backup created today would have the name of gitlabConf-17-05-03 21:27:30. The file on the Gitlab server is correctly named. However, after the transfer on the second server it is instead called GR05BW~T.TGZ

I know very little about rsync so is this some kind of configuration that needs to be done with this? Are you able to reproduce this? Seems strange considering the main backups are working.

quiet errors

/usr/local/sbin/auto-gitlab-backup/auto-gitlab-backup.sh: line 70: /usr/local/sbin/auto-gitlab-backup/auto-gitlab-backup.conf: No such file or directory
No confFile found.

QuietRake option does not work

When i set quietRake=1 option in the configuration file, it is simply ignored and rake still prints lots of debug messages. After a quick research it turned out that the rake command is generated before the configuration file is actually loaded. The fix seems to be very simple, look at my patch which solves the issue for me:

diff --git a/auto-gitlab-backup.sh b/auto-gitlab-backup.sh
index 0faddad..d50f67a 100755
--- a/auto-gitlab-backup.sh
+++ b/auto-gitlab-backup.sh
@@ -41,12 +41,6 @@ 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"
-if [[ $quietRake == 1 ]]
-then
-  rakeBackup="gitlab-rake gitlab:backup:create CRON=1"
-else
-  rakeBackup="gitlab-rake gitlab:backup:create"
-fi

 ###
 ## Functions
@@ -95,6 +89,14 @@ archiveConfig() {
 rakeBackup() {
     echo ===== raking a backup =====
     cd $gitRakeBackups
+
+    if [[ $quietRake == 1 ]]
+    then
+      rakeBackup="gitlab-rake gitlab:backup:create CRON=1"
+    else
+      rakeBackup="gitlab-rake gitlab:backup:create"
+    fi
+
     $rakeBackup
 }

Anyway, thank you for a useful script. It saves me a lot of time!

Feature Request: Disable delete on rsync end

Hey there,

I'm wondering if it's possible to enable a option to disable the delete feature on the backup server end? This is because I'd like to have the backups on my gitlab server be deleted once they're a week old but a 6 months old on by backup server end due to space constraints on the gitlab server end.

gitlab-ci

For 7.11.x make an option to backup gitlab-ci

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.