Skip to content

Instantly share code, notes, and snippets.

@hwakabh
Last active February 29, 2024 05:51
Show Gist options
  • Save hwakabh/4cf2d5d959ec2aca26990033efe634c3 to your computer and use it in GitHub Desktop.
Save hwakabh/4cf2d5d959ec2aca26990033efe634c3 to your computer and use it in GitHub Desktop.
GitLab backup utilities
#!/bin/bash
## Before you run the script:
## - Make sure the backup directories would have already created
## - Change variables below for your environments
## examples:
## BKDIR=/var/backup/gitlab.bk
## DEFDIR=/var/opt/gitlab/backups
BKDIR=PATH_TO_DIR_BACKUP_SAVED
DEFDIR=PATH_TO_TARGET_DIR_TO_BACKUP
# Get GitLab Configurations backups
tar cfz ${BKDIR}/$(date "+%s_%Y_%m_%d_etc_gitlab.tar.gz") -C /etc gitlab
# Backing up repository data with Rails
/opt/gitlab/bin/gitlab-rake gitlab:backup:create
# Copy repository data to backup directory
cp -rp ${DEFDIR}/* $BKDIR
# Lotations
find $BKDIR -mtime +2 |xargs rm -rf
find $DEFDIR -mtime +2 |xargs rm -rf

GitLab backup utilities

  • Make backups of following GitLab configurations

    • /etc/gitlab/*
      • Base configurations of GitLab environments
    • User data within GitLab system databases
      • With gitlab-rake, create backups of repository data
  • Pre-requirements

    • Before running script, the target directories must be created by user.
      • Confirm that the directory would be created
      • Modify the paramenters PATH_TO_DIR_BACKUP_SAVED and PATH_TO_TARGET_DIR_TO_BACKUP in the script
  • Run the script

    • bash ./get_daily_gitbk.sh
      • It should be better that you execute the script with crond so that you could get daily backups.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment