blob: eacb5f5aae48ba7d25e406bf42d61894c71f52b4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
namespace :backup do
desc "GITLAB | Create a backup of the GitLab CI database"
task create: :environment do
configure_cron_mode
mysql_to_postgresql = (ENV['MYSQL_TO_POSTGRESQL'] == '1')
$progress.puts "Applying final database migrations ... ".blue
Rake::Task['db:migrate'].invoke
$progress.puts "done".green
$progress.puts "Dumping database ... ".blue
Backup::Database.new.dump(mysql_to_postgresql)
$progress.puts "done".green
$progress.puts "Dumping builds ... ".blue
Backup::Builds.new.dump
$progress.puts "done".green
backup = Backup::Manager.new
tar_file = backup.pack
backup.cleanup
backup.remove_old
# Relax backup directory permissions to make the migration easier
File.chmod(0755, GitlabCi.config.backup.path)
$progress.puts "\n\nYour final CI export is in the following file:\n\n"
system(*%W(ls -lh #{tar_file}))
$progress.puts
end
desc "GITLAB | Show database secrets"
task show_secrets: :environment do
configure_cron_mode
$progress.puts <<-EOS
If you are moving to a GitLab installation installed from source, replace the
contents of /home/git/gitlab/config/secrets.yml with the following:
---
production:
db_key_base: #{JSON.dump(GitlabCi::Application.secrets.db_key_base)}
If your GitLab server uses Omnibus packages, add the following line to
/etc/gitlab/gitlab.rb:
gitlab_rails['db_key_base'] = #{GitlabCi::Application.secrets.db_key_base.inspect}
EOS
end
desc "GITLAB | Restore a previously created backup"
task restore: :environment do
configure_cron_mode
backup = Backup::Manager.new
backup.unpack
$progress.puts "Restoring database ... ".blue
Backup::Database.new.restore
$progress.puts "done".green
$progress.puts "Restoring builds ... ".blue
Backup::Builds.new.restore
$progress.puts "done".green
backup.cleanup
end
def configure_cron_mode
if ENV['CRON']
# We need an object we can say 'puts' and 'print' to; let's use a
# StringIO.
require 'stringio'
$progress = StringIO.new
else
$progress = $stdout
end
end
end
# Disable colors for CRON
unless STDOUT.isatty
module Colored
extend self
def colorize(string, options={})
string
end
end
end
|