diff --git a/modules/gitlab/files/gitlab-backup-raid.cfg b/modules/gitlab/files/gitlab-backup-raid.cfg new file mode 100644 index 00000000000..887966ea947 --- /dev/null +++ b/modules/gitlab/files/gitlab-backup-raid.cfg @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: Apache-2.0 +# File was created using sfdisk --dump on a properly configured disk. +label: dos +label-id: 0x94fe5067 +unit: sectors +sector-size: 512 +start= 2048, size= 3750746800, type=fd \ No newline at end of file diff --git a/modules/gitlab/files/provision-backup-fs.sh b/modules/gitlab/files/provision-backup-fs.sh new file mode 100755 index 00000000000..e078c30d9fc --- /dev/null +++ b/modules/gitlab/files/provision-backup-fs.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# SPDX-License-Identifier: Apache-2.0 + +# Provision filesystems and raid for GitLab backup volume +# GitLab backups are stored on dedicated SSDs /dev/sdc and /dev/sdd +# https://phabricator.wikimedia.org/T333674 + +RAID_NAME="/dev/md1" +MOUNT_POINT="/srv/gitlab-backup" + +set -u +set -x + +create_fs() { + if [ ! -e $RAID_NAME ]; then + sfdisk /dev/sdc < /opt/gitlab-backup-raid.cfg + sfdisk /dev/sdd < /opt/gitlab-backup-raid.cfg + + mdadm --create $RAID_NAME --level=mirror --raid-devices=2 /dev/sdc1 /dev/sdd1 + mkfs.ext4 $RAID_NAME + else + echo "Raid $RAID_NAME already exists, skipping creation" + fi + +} + +mount_fs() { + if [ ! -d "$MOUNT_POINT" ]; then + mkdir $MOUNT_POINT + else + echo "Mountpoint $MOUNT_POINT already exists, skipping creation" + fi + + if ! grep -q "^$RAID_NAME $MOUNT_POINT " /etc/fstab ; then + echo "$RAID_NAME $MOUNT_POINT ext4 defaults 0 0" >> /etc/fstab + else + echo "fstab entry for $RAID_NAME at $MOUNT_POINT already exists, skipping creation" + fi + + if ! findmnt $MOUNT_POINT; then + mount $MOUNT_POINT + else + echo "$MOUNT_POINT already mounted, skipping mount" + fi +} + +create_fs +mount_fs \ No newline at end of file diff --git a/modules/gitlab/manifests/init.pp b/modules/gitlab/manifests/init.pp index d154c200dae..ba1f13be52b 100644 --- a/modules/gitlab/manifests/init.pp +++ b/modules/gitlab/manifests/init.pp @@ -150,4 +150,21 @@ restore_dir_data => $backup_dir_data, restore_interval => $restore_interval, } + + # Install configuration file for gitlab backup partition layout. + file {'/opt/gitlab-backup-raid.cfg': + mode => '0744' , + owner => 'root', + group => 'root', + source => 'puppet:///modules/gitlab/gitlab-backup-raid.cfg'; + } + + # Install scipt to configure backup partition layout and raid. + # This script is executed manually while provisioning a new GitLab instance. + file {'/opt/provision-backup-fs.sh': + mode => '0744' , + owner => 'root', + group => 'root', + source => 'puppet:///modules/gitlab/provision-backup-fs.sh'; + } }