Skip to content

Commit

Permalink
gitlab: add script to create fs and raid for backup partition
Browse files Browse the repository at this point in the history
This change adds a script to configure the two additional SSDs
to be used as backup partition for /srv/gitlab-backup. As mentioned in
Ie77560b55076c94bec255f5577e2d75492496d08 we were unable to implement
this in partman, so bootstrapping the backup partition was moved to
a dedicated script.

Bug: T330172
Bug: T333674
Change-Id: I8766182572f2a3da2916b85c7ec3226b60ba5119
  • Loading branch information
anon6789 committed Apr 20, 2023
1 parent abb2f86 commit 6534b6d
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
7 changes: 7 additions & 0 deletions modules/gitlab/files/gitlab-backup-raid.cfg
Original file line number Diff line number Diff line change
@@ -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
48 changes: 48 additions & 0 deletions modules/gitlab/files/provision-backup-fs.sh
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions modules/gitlab/manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}

0 comments on commit 6534b6d

Please sign in to comment.