Skip to content

Instantly share code, notes, and snippets.

@arlimus
Last active January 2, 2016 21:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arlimus/8365108 to your computer and use it in GitHub Desktop.
Save arlimus/8365108 to your computer and use it in GitHub Desktop.
Upgrading gitlab data from caveman to modern age.
## prerequisite:
## deploy https://github.com/ogom/cookbook-gitlab
## have repos in place (/home/git/repositories)
## have data in mysql
service gitlab stop
# we need ruby1.9.1 for old gitlab migration...
apt-get install -y libpq-dev ruby1.9.1 ruby1.9.1-dev
update-alternatives --set ruby /usr/bin/ruby1.9.1
# update process
cd /home/git/gitlab
# remove old checkout branches (we create new tracking ones which fail if they exist)
git reset --hard HEAD && git checkout master
for i in $(git branch | sed 's/^..//' |grep -v "\(deploy\|master\)"); do
git branch -D "$i"
done
# set ruby to 1.9.1
export PATH='/usr/bin:/usr/local/bin:/bin:/usr/local/games:/usr/games'
# 3.1
git reset --hard HEAD && git checkout -t origin/3-1-stable && bundle install
# adjust the config so db:migrate works
# taken from the example config at 3-1-stable
cp config/gitlab.yml config/gitlab.yml.bck
echo "
git:
path: /usr/bin/git
email:
from: notify@localhost
git_host:
admin_uri: git@localhost:gitolite-admin
base_path: /home/git/repositories/
hooks_path: /home/git/.gitolite/hooks/
gitolite_admin_key: gitlab
git_user: git
upload_pack: true
receive_pack: true
" >> config/gitlab.yml
bundle exec rake db:migrate RAILS_ENV=production
mv config/gitlab.yml.bck config/gitlab.yml
# 4.0
git reset --hard HEAD && git checkout -t origin/4-0-stable && bundle install
bundle exec rake db:migrate RAILS_ENV=production
bundle exec rake gitlab:enable_namespaces RAILS_ENV=production
# will fail in updating gitolite (of course, it's not installed)
# since i don't have any projects with namespaces, that's ok
# 4.1 (ruby 1.9.3)
git reset --hard HEAD && git checkout -t origin/4-1-stable && bundle install
bundle exec rake db:migrate RAILS_ENV=production
# 4.2 (ruby 1.9.3)
git reset --hard HEAD && git checkout -t origin/4-2-stable && bundle install
bundle exec rake db:migrate RAILS_ENV=production
# set ruby back to 2.0.0
export PATH='/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games'
# 5.0
git reset --hard HEAD && git checkout -t origin/5-0-stable && bundle install
cd /home/git/gitlab-shell/support && ./rewrite-hooks.sh; cd /home/git/gitlab
bundle exec rake db:migrate RAILS_ENV=production
yes yes | bundle exec rake gitlab:shell:setup RAILS_ENV=production
bundle exec rake gitlab:shell:build_missing_projects RAILS_ENV=production
rm -rf /home/git/gitlab-satellites; mkdir -p /home/git/gitlab-satellites
bundle exec rake gitlab:wiki:migrate safe_migrate=true RAILS_ENV=production
# 5.1
git reset --hard HEAD && git checkout -t origin/5-1-stable && bundle install
bundle exec rake db:migrate RAILS_ENV=production
# 5.4
git reset --hard HEAD && git checkout -t origin/5-4-stable && bundle install
bundle exec rake db:migrate RAILS_ENV=production
yes yes | bundle exec rake migrate_merge_requests RAILS_ENV=production
yes yes | bundle exec rake migrate_milestones RAILS_ENV=production
bundle exec rake assets:precompile RAILS_ENV=production
# 6.0
git reset --hard HEAD && git checkout -t origin/6-0-stable && bundle install
bundle exec rake db:migrate RAILS_ENV=production
yes yes | bundle exec rake migrate_groups RAILS_ENV=production
# adjust the migration serviceto accept not running redis...
echo "diff --git a/app/services/project_transfer_service.rb b/app/services/project_transfer
index 3b8c484..ee06bd4 100644
--- a/app/services/project_transfer_service.rb
+++ b/app/services/project_transfer_service.rb
@@ -19,7 +19,11 @@ class ProjectTransferService
end
project.namespace = new_namespace
- project.save!
+ begin
+ project.save!
+ rescue Exception=>e
+ p e
+ end
# Move main repository
unless gitlab_shell.mv_repository(old_path, new_path)
" > project_transfer_service.diff
patch -p1 < project_transfer_service.diff
yes yes | bundle exec rake migrate_global_projects RAILS_ENV=production
yes yes | bundle exec rake migrate_keys RAILS_ENV=production
bundle exec rake migrate_inline_notes RAILS_ENV=production
bundle exec rake cache:clear RAILS_ENV=production
bundle exec rake assets:clean RAILS_ENV=production
bundle exec rake gitlab:satellites:create RAILS_ENV=production
# 6.2
#sudo -u git sh -c "cd /home/git/gitlab && bundle exec rake db:migrate RAILS_ENV=production"
git reset --hard HEAD && git checkout -t origin/6-2-stable && bundle install
bundle exec rake db:migrate RAILS_ENV=production
bundle exec rake migrate_iids RAILS_ENV=production
# 6.4
git reset --hard HEAD && git checkout -t origin/6-4-stable && bundle install
bundle exec rake db:migrate RAILS_ENV=production
# prep
bundle exec rake assets:clean RAILS_ENV=production
bundle exec rake assets:precompile RAILS_ENV=production
bundle exec rake cache:clear RAILS_ENV=production
# getting done, reset permissions
chown -R git:git /home/git/gitlab
chown -R git:git /home/git
chmod -R ug+rwX,o-rwx /home/git/repositories/
chmod -R ug-s /home/git/repositories/
find /home/git/repositories/ -type d -print0 | xargs -0 chmod g+s
# done
service gitlab start
# check the result
sudo -u git sh -c "cd /home/git/gitlab && bundle exec rake gitlab:env:info RAILS_ENV=production"
sudo -u git sh -c "cd /home/git/gitlab && bundle exec rake gitlab:check RAILS_ENV=production"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment