From 9c82bca5ee274d700ec3166d4521d4c6d2ff896c Mon Sep 17 00:00:00 2001 From: Angus MacArthur Date: Wed, 29 May 2013 15:19:23 -0400 Subject: [PATCH 1/2] fixes for gitlab restore with non-standard backup and repo dirs These fixes will allow a restore of gitlab when the backups and repositories directories are in non-standard locations (ie sub-dirs of gitlabhq). Also allows the restore to be run from script overriding the need of a user to confirm the rebuild of the authorized_keys file. --- lib/backup/repository.rb | 2 +- lib/tasks/gitlab/backup.rake | 3 +++ lib/tasks/gitlab/shell.rake | 10 ++++++---- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/backup/repository.rb b/lib/backup/repository.rb index 62a510f2acc..c5e3d049fd7 100644 --- a/lib/backup/repository.rb +++ b/lib/backup/repository.rb @@ -71,7 +71,7 @@ module Backup print 'Put GitLab hooks in repositories dirs'.yellow gitlab_shell_user_home = File.expand_path("~#{Gitlab.config.gitlab_shell.ssh_user}") - if system("#{gitlab_shell_user_home}/gitlab-shell/support/rewrite-hooks.sh") + if system("#{gitlab_shell_user_home}/gitlab-shell/support/rewrite-hooks.sh #{Gitlab.config.gitlab_shell.repos_path}") puts " [DONE]".green else puts " [FAILED]".red diff --git a/lib/tasks/gitlab/backup.rake b/lib/tasks/gitlab/backup.rake index 65d99d1aea3..920d29a444e 100644 --- a/lib/tasks/gitlab/backup.rake +++ b/lib/tasks/gitlab/backup.rake @@ -90,6 +90,9 @@ namespace :gitlab do 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 + 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 diff --git a/lib/tasks/gitlab/shell.rake b/lib/tasks/gitlab/shell.rake index ec5451dd47c..11d4eacaa69 100644 --- a/lib/tasks/gitlab/shell.rake +++ b/lib/tasks/gitlab/shell.rake @@ -26,10 +26,12 @@ namespace :gitlab do warn_user_is_not_gitlab gitlab_shell_authorized_keys = File.join(File.expand_path("~#{Gitlab.config.gitlab_shell.ssh_user}"),'.ssh/authorized_keys') - puts "This will rebuild an authorized_keys file." - puts "You will lose any data stored in #{gitlab_shell_authorized_keys}." - ask_to_continue - puts "" + unless ENV['force'] == 'yes' + puts "This will rebuild an authorized_keys file." + puts "You will lose any data stored in #{gitlab_shell_authorized_keys}." + ask_to_continue + puts "" + end system("echo '# Managed by gitlab-shell' > #{gitlab_shell_authorized_keys}") -- GitLab From 5f4fea17ad42d24f069d19d36853b7ea61ee66c8 Mon Sep 17 00:00:00 2001 From: Angus MacArthur Date: Mon, 3 Jun 2013 11:00:24 -0400 Subject: [PATCH 2/2] Correction to restore expected current directory --- lib/tasks/gitlab/backup.rake | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/tasks/gitlab/backup.rake b/lib/tasks/gitlab/backup.rake index 920d29a444e..d071938acb5 100644 --- a/lib/tasks/gitlab/backup.rake +++ b/lib/tasks/gitlab/backup.rake @@ -91,15 +91,20 @@ namespace :gitlab do 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 - 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 + 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) end Rake::Task["gitlab:backup:db:restore"].invoke -- GitLab