Skip to content

Instantly share code, notes, and snippets.

Last active February 2, 2023 03:20
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Gitlab migrate omnibus installation to new server
# the old host, must have direct ssh access
# generate ssh-keygen on new host and copy over into authorized_keys
# 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