Verified Commit b1601899 authored by Jelle van der Waa's avatar Jelle van der Waa 🚧
Browse files

Backup gitlab with gitlab-backup tool



Use Gitlab's official backup tool for dumping the database, git
repositories and other data with a wrapper script similiar to the
postgres and mysql backup scripts.
Signed-off-by: Jelle van der Waa's avatarJelle van der Waa <jelle@archlinux.org>
parent 33519eea
......@@ -53,6 +53,10 @@
file: path={{ mysql_backup_dir }} state=directory owner=root group=root
when: mysql_backup_dir is defined
- name: install gitlab backup script
template: src=backup-gitlab.sh.j2 dest=/usr/local/bin/backup-gitlab.sh owner=root group=root mode=0755
when: inventory_hostname == "gitlab.archlinux.org"
- name: install systemd timer and service for backup
template: src={{ item }}.j2 dest=/etc/systemd/system/{{ item }} owner=root group=root mode=0644
with_items:
......
#!/bin/bash
#
# Script to backup Gitlab running in a Docker container
#
# https://docs.gitlab.com/omnibus/settings/backups.html#creating-backups-for-gitlab-instances-in-docker-containers
#
backupdir="{{ gitlab_backupdir }}"
echo "emptying backup directory ${backupdir}"
# Verify that the gitlab_backupdir in ansible was defined, otherwise we will rm /* and remove the previous backup
rm -r "${backupdir:?backup dir unset}/"*
docker exec gitlab gitlab-backup create SKIP=tar
......@@ -49,6 +49,10 @@ if systemctl is-active mysqld || systemctl is-active mariadb; then
/usr/local/bin/backup-mysql.sh || true
fi
{% if inventory_hostname == "gitlab.archlinux.org" %}
systemctl is-active docker && /usr/local/bin/backup-gitlab.sh
{% endif %}
borg create -v --stats -C lz4 \
-e /proc \
-e /sys \
......@@ -58,9 +62,16 @@ borg create -v --stats -C lz4 \
-e /var/cache \
-e /var/lib/archbuild \
-e /var/lib/archbuilddest \
-e /var/lib/docker \
-e "$backup_mountdir/proc" \
-e "$backup_mountdir/sys" \
-e "$backup_mountdir/dev" \
-e "$backup_mountdir/run" \
-e "$backup_mountdir/tmp" \
-e "$backup_mountdir/var/cache" \
-e "$backup_mountdir/var/lib/archbuild" \
-e "$backup_mountdir/var/lib/archbuilddest" \
-e "$backup_mountdir/var/lib/docker" \
-e "$backup_mountdir/srv/archive" \
{{ item['host'] }}:{{ item['dir'] }}::$(date "+%Y%m%d-%H%M%S") "$backup_mountdir"
borg prune -v {{ item['host'] }}:{{ item['dir'] }} --keep-daily=7 --keep-weekly=4 --keep-monthly=6
......
gitlab_backupdir: /srv/gitlab/data/backups
Supports Markdown
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