From cd86b155042f6fca18c231b862d8e923eb38b441 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Mon, 19 May 2014 16:20:53 +0000 Subject: Add GitLab backup automation This adds a systemd timer unit to back up a GitLab instance every four hours. The backup is placed as /home/git/gitlab-backup.tar and it is expected Something Else retrieves that. --- gitlab-server/manifest | 3 +++ .../usr/share/gitlab-install/backup-gitlab | 22 ++++++++++++++++++++++ .../systemd-units/gitlab-backup.service | 11 +++++++++++ .../systemd-units/gitlab-backup.timer | 8 ++++++++ gitlab-server/usr/share/gitlab-setup | 2 +- 5 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 gitlab-server/usr/share/gitlab-install/backup-gitlab create mode 100644 gitlab-server/usr/share/gitlab-install/systemd-units/gitlab-backup.service create mode 100644 gitlab-server/usr/share/gitlab-install/systemd-units/gitlab-backup.timer diff --git a/gitlab-server/manifest b/gitlab-server/manifest index 8d1dae7a..7ac74744 100644 --- a/gitlab-server/manifest +++ b/gitlab-server/manifest @@ -1,5 +1,6 @@ 0100755 0 0 /usr/share/gitlab-setup 0040755 0 0 /usr/share/gitlab-install +0100755 0 0 /usr/share/gitlab-install/backup-gitlab 0040755 0 0 /usr/share/gitlab-install/gitlab 0040755 0 0 /usr/share/gitlab-install/gitlab/config 0100644 0 0 /usr/share/gitlab-install/gitlab/config/gitlab.yml @@ -32,3 +33,5 @@ 0100644 0 0 /usr/share/gitlab-install/systemd-units/nginx.service 0100644 0 0 /usr/share/gitlab-install/systemd-units/postgres.service 0100644 0 0 /usr/share/gitlab-install/systemd-units/redis.service +0100644 0 0 /usr/share/gitlab-install/systemd-units/gitlab-backup.service +0100644 0 0 /usr/share/gitlab-install/systemd-units/gitlab-backup.timer diff --git a/gitlab-server/usr/share/gitlab-install/backup-gitlab b/gitlab-server/usr/share/gitlab-install/backup-gitlab new file mode 100644 index 00000000..a6c3e3f5 --- /dev/null +++ b/gitlab-server/usr/share/gitlab-install/backup-gitlab @@ -0,0 +1,22 @@ +#!/bin/sh +# +# Run the gitlab backup script. The backup will be stored as +# /home/git/gitlab-backup.tar . A separate backup host will need to +# back that up. +# +# This script be run as the git user on a GitLab host. + +set -e + +export PATH=/usr/local/bin:/usr/bin:/bin + +cd /home/git/gitlab +mkdir -p /home/git/gitlab/tmp/backups +bundle exec rake gitlab:backup:create RAILS_ENV=production + +ls /home/git/gitlab/tmp/backups/[0-9]*.tar | +tail -n1 | +while read filename +do + mv "$filename" /home/git/gitlab-backup.tar +done diff --git a/gitlab-server/usr/share/gitlab-install/systemd-units/gitlab-backup.service b/gitlab-server/usr/share/gitlab-install/systemd-units/gitlab-backup.service new file mode 100644 index 00000000..967a65e3 --- /dev/null +++ b/gitlab-server/usr/share/gitlab-install/systemd-units/gitlab-backup.service @@ -0,0 +1,11 @@ +[Unit] +Description=GitLab Backup Run +After=postgres.service + +[Install] +WantedBy=gitlab.target + +[Service] +ExecStart=/usr/share/gitlab-install/backup-gitlab +User=git +Group=git diff --git a/gitlab-server/usr/share/gitlab-install/systemd-units/gitlab-backup.timer b/gitlab-server/usr/share/gitlab-install/systemd-units/gitlab-backup.timer new file mode 100644 index 00000000..1c2f57ba --- /dev/null +++ b/gitlab-server/usr/share/gitlab-install/systemd-units/gitlab-backup.timer @@ -0,0 +1,8 @@ +[Unit] +Description=GitLab Backup Timer + +[Install] +WantedBy=gitlab.target + +[Timer] +OnCalendar=*-*-* 00/4:00:00 diff --git a/gitlab-server/usr/share/gitlab-setup b/gitlab-server/usr/share/gitlab-setup index 5c53c859..e1084a1b 100755 --- a/gitlab-server/usr/share/gitlab-setup +++ b/gitlab-server/usr/share/gitlab-setup @@ -100,5 +100,5 @@ cp /usr/share/gitlab-install/nginx.conf /etc/nginx/nginx.conf # make systemd units to start gitlab and required stuff on boot cd /etc/systemd/system cp /usr/share/gitlab-install/systemd-units/* . -systemctl enable redis.service nginx.service postgres.service gitlab.target gitlab-unicorn.service gitlab-sidekiq.service gitlab-ci-sidekiq.service gitlab-ci-unicorn.service +systemctl enable redis.service nginx.service postgres.service gitlab.target gitlab-unicorn.service gitlab-sidekiq.service gitlab-ci-sidekiq.service gitlab-ci-unicorn.service gitlab-backup.timer gitlab-backup.service reboot -- cgit v1.2.1