Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Gitlab migrate omnibus installation to new server
#!/bin/bash
# ATTENTION: COPY&PASTE RUN EVERY LINE BY HAND AND VERIFY THE OUTPUT
# the old host, must have direct ssh access
# generate ssh-keygen on new host and copy over into authorized_keys
gitlab='root@1.2.3.4'
# Stopping everything on remote system
echo "$gitlab - Gitlab Stop"
ssh $gitlab "gitlab-ctl stop nginx"
ssh $gitlab "gitlab-ctl stop sidekiq"
ssh $gitlab "gitlab-ctl stop mattermost"
echo "$gitlab - Make Backup"
ssh $gitlab "gitlab-backup create SKIP=lfs"
echo "local - Stopping gitlab"
gitlab-ctl stop
gitlab-ctl start postgresql
# bonus points: we migrated from remote s3 docker registry to locally hosted back, because the S3-bill is it not worth.
# echo "Localize docker registry"
# rclone sync s3-registry:pludoni-gitlab-docker/docker/ /var/opt/gitlab/registry/docker/.
# copy ssh hostkey, so that the ssh connection from clients still work
cd /etc/ssh
scp $gitlab:/etc/ssh/ssh_host_* .
service ssh restart
# Maybe copy over /etc/gitlab content, we did it beforehand because we did some modifications for our setup
# echo "$gitlab - syncing content of /etc/gitlab"
# mkdir -p /etc/gitlab/
# rsync -a $gitlab:/etc/gitlab/. /etc/gitlab/.
# gitlab-ctl reconfigure
# copy over last backup
backup_file=`ssh $gitlab "cd /var/opt/gitlab/backups && ls *.tar | tail -n 1"`
echo "Sync - /var/opt/gitlab/backups/"
mkdir -p /var/opt/gitlab/backups/
scp -p $gitlab:/var/opt/gitlab/backups/$backup_file /var/opt/gitlab/backups/$backup_file
chown git:git /var/opt/gitlab/backups/*.tar
# Mattermost data dir
echo "Sync - /var/opt/gitlab/mattermost"
mkdir -p /var/opt/gitlab/mattermost/
rsync -a $gitlab:/var/opt/gitlab/mattermost/. /var/opt/gitlab/mattermost/.
sudo chown -R mattermost /var/opt/gitlab/mattermost/
# Mattermost sql
echo "$gitlab - Creating mattermost backup"
ssh $gitlab 'sudo -u gitlab-psql -- /opt/gitlab/embedded/bin/pg_dump -h /var/opt/gitlab/postgresql mattermost_production | gzip ' > /root/mattermost-db.sql.gz
echo "local - reimport mattermost db"
sudo -u mattermost /opt/gitlab/embedded/bin/dropdb -U gitlab_mattermost -h /var/opt/gitlab/postgresql -p 5432 mattermost_production
sudo -u gitlab-psql /opt/gitlab/embedded/bin/createdb -U gitlab-psql -h /var/opt/gitlab/postgresql -p 5432 mattermost_production
gunzip < /root/mattermost-db.sql.gz | sudo -u mattermost /opt/gitlab/embedded/bin/psql -U gitlab_mattermost -h /var/opt/gitlab/postgresql -p 5432 mattermost_production
gitlab-ctl start
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
gitlab-backup restore
gitlab-ctl reconfigure
gitlab-ctl restart
gitlab-rake gitlab:check SANITIZE=true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.