From db9a6013311229e546d7ba53adc61e2bf44f7570 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Thu, 27 Feb 2014 17:37:31 +0100 Subject: [PATCH] Backport gitlab-rails backup script improvement --- config/patches/gitlab-rails/backup_read_REVISION.patch | 22 ---------------------- config/patches/gitlab-rails/backup_use_VERSION.patch | 44 ++++++++++++++++++++++++++++++++++++++++++++ config/software/gitlab-rails.rb | 6 ++++-- 3 files changed, 48 insertions(+), 24 deletions(-) delete mode 100644 config/patches/gitlab-rails/backup_read_REVISION.patch create mode 100644 config/patches/gitlab-rails/backup_use_VERSION.patch diff --git a/config/patches/gitlab-rails/backup_read_REVISION.patch b/config/patches/gitlab-rails/backup_read_REVISION.patch deleted file mode 100644 index 333ef17..0000000 --- a/config/patches/gitlab-rails/backup_read_REVISION.patch +++ /dev/null @@ -1,22 +0,0 @@ -diff --git a/lib/backup/manager.rb b/lib/backup/manager.rb -index efaefa4..8f0e38f 100644 ---- a/lib/backup/manager.rb -+++ b/lib/backup/manager.rb -@@ -7,7 +7,7 @@ module Backup - s = {} - s[:db_version] = "#{ActiveRecord::Migrator.current_version}" - s[:backup_created_at] = Time.now -- s[:gitlab_version] = %x{git rev-parse HEAD}.gsub(/\n/,"") -+ s[:gitlab_version] = File.read(Rails.root.join('REVISION')).chomp - s[:tar_version] = %x{tar --version | head -1}.gsub(/\n/,"") - - Dir.chdir(Gitlab.config.backup.path) -@@ -92,7 +92,7 @@ module Backup - Dir.chdir(Rails.root) - - # restoring mismatching backups can lead to unexpected problems -- if settings[:gitlab_version] != %x{git rev-parse HEAD}.gsub(/\n/, "") -+ if settings[:gitlab_version] != File.read(Rails.root.join('REVISION')).chomp - puts "GitLab version mismatch:".red - puts " Your current HEAD differs from the HEAD in the backup!".red - puts " Please switch to the following revision and try again:".red diff --git a/config/patches/gitlab-rails/backup_use_VERSION.patch b/config/patches/gitlab-rails/backup_use_VERSION.patch new file mode 100644 index 0000000..42c15b1 --- /dev/null +++ b/config/patches/gitlab-rails/backup_use_VERSION.patch @@ -0,0 +1,44 @@ +diff --git a/lib/backup/manager.rb b/lib/backup/manager.rb +index efaefa4..a93d35a 100644 +--- a/lib/backup/manager.rb ++++ b/lib/backup/manager.rb +@@ -7,7 +7,7 @@ module Backup + s = {} + s[:db_version] = "#{ActiveRecord::Migrator.current_version}" + s[:backup_created_at] = Time.now +- s[:gitlab_version] = %x{git rev-parse HEAD}.gsub(/\n/,"") ++ s[:gitlab_version] = Gitlab::VERSION + s[:tar_version] = %x{tar --version | head -1}.gsub(/\n/,"") + + Dir.chdir(Gitlab.config.backup.path) +@@ -87,21 +87,15 @@ module Backup + settings = YAML.load_file("backup_information.yml") + ENV["VERSION"] = "#{settings[:db_version]}" if settings[:db_version].to_i > 0 + +- # backups directory is not always sub of Rails root and able to execute the git rev-parse below +- begin +- Dir.chdir(Rails.root) +- +- # restoring mismatching backups can lead to unexpected problems +- if settings[:gitlab_version] != %x{git rev-parse HEAD}.gsub(/\n/, "") +- puts "GitLab version mismatch:".red +- puts " Your current HEAD differs from the HEAD in the backup!".red +- puts " Please switch to the following revision and try again:".red +- puts " revision: #{settings[:gitlab_version]}".red +- exit 1 +- end +- ensure +- # chdir back to original intended dir +- Dir.chdir(Gitlab.config.backup.path) ++ # restoring mismatching backups can lead to unexpected problems ++ if settings[:gitlab_version] != Gitlab::VERSION ++ puts "GitLab version mismatch:".red ++ puts " Your current GitLab version (#{Gitlab::VERSION}) differs from the GitLab version in the backup!".red ++ puts " Please switch to the following version and try again:".red ++ puts " version: #{settings[:gitlab_version]}".red ++ puts ++ puts "Hint: git checkout v#{settings[:gitlab_version]}" ++ exit 1 + end + end + end diff --git a/config/software/gitlab-rails.rb b/config/software/gitlab-rails.rb index 7a1e9ad..31be83d 100644 --- a/config/software/gitlab-rails.rb +++ b/config/software/gitlab-rails.rb @@ -43,8 +43,10 @@ build do # source code to include the Git revision of the code included in the omnibus # build. command "sed -i \"s/.*REVISION.*/REVISION = '$(git log --pretty=format:'%h' -n 1)'/\" config/initializers/2_app.rb" - patch :source => "backup_read_REVISION.patch" - command "git rev-parse HEAD > REVISION" + + # gitlab-rails master has improved the versioning logic for backups. The old + # solution is painful for omnibus-gitlab so we are backporting the improvement. + patch :source => "backup_use_VERSION.patch" # The user uploads path is not (yet) configurable in gitlab-rails. As a # workaround, omnibus-gitlab creates a symlink for public/uploads. This breaks -- libgit2 0.21.2