Skip to content

Instantly share code, notes, and snippets.

@shivai
Last active July 13, 2021 22:04
Show Gist options
  • Save shivai/4ce9848d98d855c8d672338f76a322b7 to your computer and use it in GitHub Desktop.
Save shivai/4ce9848d98d855c8d672338f76a322b7 to your computer and use it in GitHub Desktop.

Restore from backup

Install the version that you want:

curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | bash
apt-cache madison gitlab-ce
apt install gitlab-ce=12.10.2-ce.0

in this sample we are going to config Gitlab with external Postgresql:

apt install postgresql=9.6+181+deb9u3
systemctl status postgresql@9.6-main.service

Now, copy these files from the gitlab which you want restore from it:

cp gitlab.rb   /etc/gitlab/
cp gitlab.rb  /etc/gitlab/

change psql configuration ip and port in gitlab.rb then:

Gitlab-ctl reconfigure

archive your backup and then put in the backups directotory like this:

tar -cf 3_gitlab_backup.tar *
cp 3_gitlab_backup.tar /var/opt/gitlab/backups/

Finally you can restore it with the following command:

gitlab-backup restore BACKUP=3

after restore run these commands:

gitlab-ctl reconfigure
gitlab-ctl restart
gitlab-rake gitlab:check SANITIZE=true

if you want add ssl to gitlab you should change the configuration in this file:

vim /var/opt/gitlab/nginx/conf/gitlab-http.conf

you need certificate and change port to 443, after that gitlab will create nginx config file based on these informatio.

Upgrade gitlab 12.10 to 13.0.14

According to the gitlab update documentation if you want upgrad eyour gitlab to the another version, you should follow a special path, in this example we want upgrade 12.10 to latest minor version of 13. At first we should upgrade our gitlab t =o the latest minor of the current version, here 12.10 is the lastest for 12. Now we should first upgrade it to first minor of teh next version 13.0.14 then upgrade to latest minor version of 13.

Create a backup from current status:

gitlab-rake gitlab:backup:create BACKUP=dump GZIP_RSYNCABLE=yes DIRECTORY=daily

For version 13 we should have postgresql 11 atleat, we are going to install postgresql 13:

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc |  apt-key add -
sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
apt update
apt-cache madison postgresql
apt install postgresql=13+225.pgdg90+1

now we should migrate to new postgresql:

systemctl stop postgresql@9.6-main.service
systemctl stop postgresql@13-main.service

**Change config of new postgres like the ol version Migrate to postgres13:

su - postgres
cd  /tmp
/usr/lib/postgresql/13/bin/pg_upgrade --old-datadir /var/lib/postgresql/9.6/main --new-datadir /var/lib/postgresql/13/main --old-bindir /usr/lib/postgresql/9.6/bin --new-bindir /usr/lib/postgresql/13/bin --old-port 5432 --new-port 5433 --old-options '-c config_file=/etc/postgresql/9.6/main/postgresql.conf' --new-options '-c config_file=/etc/postgresql/13/main/postgresql.conf'

now create a backup from important files of current gitlab:

By root user:
# cp /etc/gitlab/gitlab.rb ~
# cp /etc/gitlab/gitlab-secrets.json ~

we need change pgdump version of gitlab to 13:

mv /opt/gitlab/embedded/bin/{pg_dump,pg_dump_11}
ln -sn /usr/lib/postgresql/13/bin/pg_dump /opt/gitlab/embedded/bin/

If the new psql port is difference you should change it in gitlab.rb. Finally run these commands:

gitlab-ctl reconfigure
apt install gitlab-ce=13.0.14-ce.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment