Commit 1b6c28b9766aff2075bcd6e8c394ac4b9ed66f96
1 parent
430d3ad4
Exists in
master
and in
4 other branches
Update output of gitlab:backup:resore
Showing
1 changed file
with
39 additions
and
35 deletions
Show diff stats
lib/tasks/gitlab/backup.rake
... | ... | @@ -5,6 +5,8 @@ namespace :gitlab do |
5 | 5 | # Create backup of GitLab system |
6 | 6 | desc "GITLAB | Create a backup of the GitLab system" |
7 | 7 | task :create => :environment do |
8 | + warn_user_is_not_gitlab | |
9 | + | |
8 | 10 | Rake::Task["gitlab:backup:db:create"].invoke |
9 | 11 | Rake::Task["gitlab:backup:repo:create"].invoke |
10 | 12 | |
... | ... | @@ -22,23 +24,23 @@ namespace :gitlab do |
22 | 24 | end |
23 | 25 | |
24 | 26 | # create archive |
25 | - print "Creating backup archive: #{Time.now.to_i}_gitlab_backup.tar " | |
27 | + print "Creating backup archive: #{Time.now.to_i}_gitlab_backup.tar ... " | |
26 | 28 | if Kernel.system("tar -cf #{Time.now.to_i}_gitlab_backup.tar repositories/ db/ backup_information.yml") |
27 | - puts "[DONE]".green | |
29 | + puts "done".green | |
28 | 30 | else |
29 | - puts "[FAILED]".red | |
31 | + puts "failed".red | |
30 | 32 | end |
31 | 33 | |
32 | 34 | # cleanup: remove tmp files |
33 | - print "Deleting tmp directories..." | |
35 | + print "Deleting tmp directories ... " | |
34 | 36 | if Kernel.system("rm -rf repositories/ db/ backup_information.yml") |
35 | - puts "[DONE]".green | |
37 | + puts "done".green | |
36 | 38 | else |
37 | - puts "[FAILED]".red | |
39 | + puts "failed".red | |
38 | 40 | end |
39 | 41 | |
40 | 42 | # delete backups |
41 | - print "Deleting old backups... " | |
43 | + print "Deleting old backups ... " | |
42 | 44 | if Gitlab.config.backup.keep_time > 0 |
43 | 45 | file_list = Dir.glob("*_gitlab_backup.tar").map { |f| f.split(/_/).first.to_i } |
44 | 46 | file_list.sort.each do |timestamp| |
... | ... | @@ -46,15 +48,17 @@ namespace :gitlab do |
46 | 48 | %x{rm #{timestamp}_gitlab_backup.tar} |
47 | 49 | end |
48 | 50 | end |
49 | - puts "[DONE]".green | |
51 | + puts "done".green | |
50 | 52 | else |
51 | - puts "[SKIPPING]".yellow | |
53 | + puts "skipping".yellow | |
52 | 54 | end |
53 | 55 | end |
54 | 56 | |
55 | 57 | # Restore backup of GitLab system |
56 | 58 | desc "GITLAB | Restore a previously created backup" |
57 | 59 | task :restore => :environment do |
60 | + warn_user_is_not_gitlab | |
61 | + | |
58 | 62 | Dir.chdir(Gitlab.config.backup.path) |
59 | 63 | |
60 | 64 | # check for existing backups in the backup dir |
... | ... | @@ -63,22 +67,22 @@ namespace :gitlab do |
63 | 67 | if file_list.count > 1 && ENV["BACKUP"].nil? |
64 | 68 | puts "Found more than one backup, please specify which one you want to restore:" |
65 | 69 | puts "rake gitlab:backup:restore BACKUP=timestamp_of_backup" |
66 | - exit 1; | |
70 | + exit 1 | |
67 | 71 | end |
68 | 72 | |
69 | 73 | tar_file = ENV["BACKUP"].nil? ? File.join("#{file_list.first}_gitlab_backup.tar") : File.join(ENV["BACKUP"] + "_gitlab_backup.tar") |
70 | 74 | |
71 | 75 | unless File.exists?(tar_file) |
72 | 76 | puts "The specified backup doesn't exist!" |
73 | - exit 1; | |
77 | + exit 1 | |
74 | 78 | end |
75 | 79 | |
76 | - print "Unpacking backup... " | |
80 | + print "Unpacking backup ... " | |
77 | 81 | unless Kernel.system("tar -xf #{tar_file}") |
78 | - puts "[FAILED]".red | |
82 | + puts "failed".red | |
79 | 83 | exit 1 |
80 | 84 | else |
81 | - puts "[DONE]".green | |
85 | + puts "done".green | |
82 | 86 | end |
83 | 87 | |
84 | 88 | settings = YAML.load_file("backup_information.yml") |
... | ... | @@ -86,7 +90,7 @@ namespace :gitlab do |
86 | 90 | |
87 | 91 | # restoring mismatching backups can lead to unexpected problems |
88 | 92 | if settings[:gitlab_version] != %x{git rev-parse HEAD}.gsub(/\n/,"") |
89 | - puts "gitlab_version mismatch:".red | |
93 | + puts "GitLab version mismatch:".red | |
90 | 94 | puts " Your current HEAD differs from the HEAD in the backup!".red |
91 | 95 | puts " Please switch to the following revision and try again:".red |
92 | 96 | puts " revision: #{settings[:gitlab_version]}".red |
... | ... | @@ -97,11 +101,11 @@ namespace :gitlab do |
97 | 101 | Rake::Task["gitlab:backup:repo:restore"].invoke |
98 | 102 | |
99 | 103 | # cleanup: remove tmp files |
100 | - print "Deleting tmp directories..." | |
104 | + print "Deleting tmp directories ... " | |
101 | 105 | if Kernel.system("rm -rf repositories/ db/ backup_information.yml") |
102 | - puts "[DONE]".green | |
106 | + puts "done".green | |
103 | 107 | else |
104 | - puts "[FAILED]".red | |
108 | + puts "failed".red | |
105 | 109 | end |
106 | 110 | end |
107 | 111 | |
... | ... | @@ -114,26 +118,26 @@ namespace :gitlab do |
114 | 118 | task :create => :environment do |
115 | 119 | backup_path_repo = File.join(Gitlab.config.backup.path, "repositories") |
116 | 120 | FileUtils.mkdir_p(backup_path_repo) until Dir.exists?(backup_path_repo) |
117 | - puts "Dumping repositories:" | |
121 | + puts "Dumping repositories ..." | |
118 | 122 | project = Project.all.map { |n| [n.path, n.path_to_repo] } |
119 | 123 | project << ["gitolite-admin.git", File.join(Gitlab.config.git_base_path, "gitolite-admin.git")] |
120 | 124 | project.each do |project| |
121 | - print "- Dumping repository #{project.first}... " | |
125 | + print "#{project.first.yellow} ... " | |
122 | 126 | if Kernel.system("cd #{project.second} > /dev/null 2>&1 && git bundle create #{backup_path_repo}/#{project.first}.bundle --all > /dev/null 2>&1") |
123 | - puts "[DONE]".green | |
127 | + puts "done".green | |
124 | 128 | else |
125 | - puts "[FAILED]".red | |
129 | + puts "failed".red | |
126 | 130 | end |
127 | 131 | end |
128 | 132 | end |
129 | 133 | |
130 | 134 | task :restore => :environment do |
131 | 135 | backup_path_repo = File.join(Gitlab.config.backup.path, "repositories") |
132 | - puts "Restoring repositories:" | |
136 | + puts "Restoring repositories ... " | |
133 | 137 | project = Project.all.map { |n| [n.path, n.path_to_repo] } |
134 | - project << ["gitolite-admin.git", File.join(File.dirname(project.first.second), "gitolite-admin.git")] | |
138 | + project << ["gitolite-admin.git", File.join(Gitlab.config.git_base_path, "gitolite-admin.git")] | |
135 | 139 | project.each do |project| |
136 | - print "- Restoring repository #{project.first}... " | |
140 | + print "#{project.first.yellow} ... " | |
137 | 141 | FileUtils.rm_rf(project.second) if File.dirname(project.second) # delete old stuff |
138 | 142 | if Kernel.system("cd #{File.dirname(project.second)} > /dev/null 2>&1 && git clone --bare #{backup_path_repo}/#{project.first}.bundle #{project.first}.git > /dev/null 2>&1") |
139 | 143 | permission_commands = [ |
... | ... | @@ -141,9 +145,9 @@ namespace :gitlab do |
141 | 145 | "sudo chown -R #{Gitlab.config.ssh_user}:#{Gitlab.config.ssh_user} #{Gitlab.config.git_base_path}" |
142 | 146 | ] |
143 | 147 | permission_commands.each { |command| Kernel.system(command) } |
144 | - puts "[DONE]".green | |
148 | + puts "done".green | |
145 | 149 | else |
146 | - puts "[FAILED]".red | |
150 | + puts "failed".red | |
147 | 151 | end |
148 | 152 | end |
149 | 153 | end |
... | ... | @@ -156,9 +160,9 @@ namespace :gitlab do |
156 | 160 | backup_path_db = File.join(Gitlab.config.backup.path, "db") |
157 | 161 | FileUtils.mkdir_p(backup_path_db) unless Dir.exists?(backup_path_db) |
158 | 162 | |
159 | - puts "Dumping database tables:" | |
163 | + puts "Dumping database tables ... " | |
160 | 164 | ActiveRecord::Base.connection.tables.each do |tbl| |
161 | - print "- Dumping table #{tbl}... " | |
165 | + print "#{tbl.yellow} ... " | |
162 | 166 | count = 1 |
163 | 167 | File.open(File.join(backup_path_db, tbl + ".yml"), "w+") do |file| |
164 | 168 | ActiveRecord::Base.connection.select_all("SELECT * FROM `#{tbl}`").each do |line| |
... | ... | @@ -167,25 +171,25 @@ namespace :gitlab do |
167 | 171 | file << output.to_yaml.gsub(/^---\n/,'') + "\n" |
168 | 172 | count += 1 |
169 | 173 | end |
170 | - puts "[DONE]".green | |
174 | + puts "done".green | |
171 | 175 | end |
172 | 176 | end |
173 | 177 | end |
174 | 178 | |
175 | - task :restore=> :environment do | |
179 | + task :restore => :environment do | |
176 | 180 | backup_path_db = File.join(Gitlab.config.backup.path, "db") |
177 | 181 | |
178 | - puts "Restoring database tables:" | |
182 | + puts "Restoring database tables (loading fixtures) ... " | |
179 | 183 | Rake::Task["db:reset"].invoke |
180 | 184 | |
181 | 185 | Dir.glob(File.join(backup_path_db, "*.yml") ).each do |dir| |
182 | 186 | fixture_file = File.basename(dir, ".*" ) |
183 | - print "- Loading fixture #{fixture_file}..." | |
187 | + print "#{fixture_file.yellow} ... " | |
184 | 188 | if File.size(dir) > 0 |
185 | 189 | ActiveRecord::Fixtures.create_fixtures(backup_path_db, fixture_file) |
186 | - puts "[DONE]".green | |
190 | + puts "done".green | |
187 | 191 | else |
188 | - puts "[SKIPPING]".yellow | |
192 | + puts "skipping".yellow | |
189 | 193 | end |
190 | 194 | end |
191 | 195 | end | ... | ... |