Commit 5cd988249fa7f8495111523a17bb2d28cfa7177a
Exists in
master
and in
4 other branches
Merge pull request #4140 from amacarthur/restore-fixes-clean
fixes for gitlab restore with non-standard backup and repo dirs
Showing
3 changed files
with
22 additions
and
12 deletions
Show diff stats
lib/backup/repository.rb
@@ -71,7 +71,7 @@ module Backup | @@ -71,7 +71,7 @@ module Backup | ||
71 | 71 | ||
72 | print 'Put GitLab hooks in repositories dirs'.yellow | 72 | print 'Put GitLab hooks in repositories dirs'.yellow |
73 | gitlab_shell_user_home = File.expand_path("~#{Gitlab.config.gitlab_shell.ssh_user}") | 73 | gitlab_shell_user_home = File.expand_path("~#{Gitlab.config.gitlab_shell.ssh_user}") |
74 | - if system("#{gitlab_shell_user_home}/gitlab-shell/support/rewrite-hooks.sh") | 74 | + if system("#{gitlab_shell_user_home}/gitlab-shell/support/rewrite-hooks.sh #{Gitlab.config.gitlab_shell.repos_path}") |
75 | puts " [DONE]".green | 75 | puts " [DONE]".green |
76 | else | 76 | else |
77 | puts " [FAILED]".red | 77 | puts " [FAILED]".red |
lib/tasks/gitlab/backup.rake
@@ -90,13 +90,21 @@ namespace :gitlab do | @@ -90,13 +90,21 @@ namespace :gitlab do | ||
90 | settings = YAML.load_file("backup_information.yml") | 90 | settings = YAML.load_file("backup_information.yml") |
91 | ENV["VERSION"] = "#{settings[:db_version]}" if settings[:db_version].to_i > 0 | 91 | ENV["VERSION"] = "#{settings[:db_version]}" if settings[:db_version].to_i > 0 |
92 | 92 | ||
93 | - # restoring mismatching backups can lead to unexpected problems | ||
94 | - if settings[:gitlab_version] != %x{git rev-parse HEAD}.gsub(/\n/,"") | ||
95 | - puts "GitLab version mismatch:".red | ||
96 | - puts " Your current HEAD differs from the HEAD in the backup!".red | ||
97 | - puts " Please switch to the following revision and try again:".red | ||
98 | - puts " revision: #{settings[:gitlab_version]}".red | ||
99 | - exit 1 | 93 | + # backups directory is not always sub of Rails root and able to execute the git rev-parse below |
94 | + begin | ||
95 | + Dir.chdir(Rails.root) | ||
96 | + | ||
97 | + # restoring mismatching backups can lead to unexpected problems | ||
98 | + if settings[:gitlab_version] != %x{git rev-parse HEAD}.gsub(/\n/, "") | ||
99 | + puts "GitLab version mismatch:".red | ||
100 | + puts " Your current HEAD differs from the HEAD in the backup!".red | ||
101 | + puts " Please switch to the following revision and try again:".red | ||
102 | + puts " revision: #{settings[:gitlab_version]}".red | ||
103 | + exit 1 | ||
104 | + end | ||
105 | + ensure | ||
106 | + # chdir back to original intended dir | ||
107 | + Dir.chdir(Gitlab.config.backup.path) | ||
100 | end | 108 | end |
101 | 109 | ||
102 | Rake::Task["gitlab:backup:db:restore"].invoke | 110 | Rake::Task["gitlab:backup:db:restore"].invoke |
lib/tasks/gitlab/shell.rake
@@ -26,10 +26,12 @@ namespace :gitlab do | @@ -26,10 +26,12 @@ namespace :gitlab do | ||
26 | warn_user_is_not_gitlab | 26 | warn_user_is_not_gitlab |
27 | 27 | ||
28 | gitlab_shell_authorized_keys = File.join(File.expand_path("~#{Gitlab.config.gitlab_shell.ssh_user}"),'.ssh/authorized_keys') | 28 | gitlab_shell_authorized_keys = File.join(File.expand_path("~#{Gitlab.config.gitlab_shell.ssh_user}"),'.ssh/authorized_keys') |
29 | - puts "This will rebuild an authorized_keys file." | ||
30 | - puts "You will lose any data stored in #{gitlab_shell_authorized_keys}." | ||
31 | - ask_to_continue | ||
32 | - puts "" | 29 | + unless ENV['force'] == 'yes' |
30 | + puts "This will rebuild an authorized_keys file." | ||
31 | + puts "You will lose any data stored in #{gitlab_shell_authorized_keys}." | ||
32 | + ask_to_continue | ||
33 | + puts "" | ||
34 | + end | ||
33 | 35 | ||
34 | system("echo '# Managed by gitlab-shell' > #{gitlab_shell_authorized_keys}") | 36 | system("echo '# Managed by gitlab-shell' > #{gitlab_shell_authorized_keys}") |
35 | 37 |