2012-07-09 17:45:43 -04:00
|
|
|
require 'active_record/fixtures'
|
|
|
|
|
|
|
|
namespace :gitlab do
|
2012-12-20 14:17:09 -05:00
|
|
|
namespace :backup do
|
2012-09-26 07:18:10 -04:00
|
|
|
# Create backup of GitLab system
|
2015-06-23 10:52:40 -04:00
|
|
|
desc "GitLab | Create a backup of the GitLab system"
|
2018-01-24 03:12:33 -05:00
|
|
|
task create: :gitlab_environment do
|
2012-12-23 15:15:25 -05:00
|
|
|
warn_user_is_not_gitlab
|
2014-11-20 09:46:04 -05:00
|
|
|
configure_cron_mode
|
2012-12-23 15:15:25 -05:00
|
|
|
|
2012-12-20 14:17:09 -05:00
|
|
|
Rake::Task["gitlab:backup:db:create"].invoke
|
|
|
|
Rake::Task["gitlab:backup:repo:create"].invoke
|
2013-04-10 08:41:47 -04:00
|
|
|
Rake::Task["gitlab:backup:uploads:create"].invoke
|
2015-09-15 04:24:30 -04:00
|
|
|
Rake::Task["gitlab:backup:builds:create"].invoke
|
2015-10-12 17:47:32 -04:00
|
|
|
Rake::Task["gitlab:backup:artifacts:create"].invoke
|
2015-11-03 15:28:07 -05:00
|
|
|
Rake::Task["gitlab:backup:pages:create"].invoke
|
2015-11-18 05:39:26 -05:00
|
|
|
Rake::Task["gitlab:backup:lfs:create"].invoke
|
2016-05-16 18:17:57 -04:00
|
|
|
Rake::Task["gitlab:backup:registry:create"].invoke
|
2012-07-09 17:45:43 -04:00
|
|
|
|
2013-08-05 05:26:33 -04:00
|
|
|
backup = Backup::Manager.new
|
|
|
|
backup.pack
|
|
|
|
backup.cleanup
|
|
|
|
backup.remove_old
|
2012-07-09 17:45:43 -04:00
|
|
|
end
|
|
|
|
|
2012-09-26 07:18:10 -04:00
|
|
|
# Restore backup of GitLab system
|
2016-03-08 17:52:48 -05:00
|
|
|
desc 'GitLab | Restore a previously created backup'
|
2018-01-24 03:12:33 -05:00
|
|
|
task restore: :gitlab_environment do
|
2012-12-23 15:15:25 -05:00
|
|
|
warn_user_is_not_gitlab
|
2014-11-20 09:46:04 -05:00
|
|
|
configure_cron_mode
|
2012-12-23 15:15:25 -05:00
|
|
|
|
2013-08-05 05:26:33 -04:00
|
|
|
backup = Backup::Manager.new
|
|
|
|
backup.unpack
|
2012-07-09 17:45:43 -04:00
|
|
|
|
2016-03-08 17:52:48 -05:00
|
|
|
unless backup.skipped?('db')
|
2017-11-07 10:10:57 -05:00
|
|
|
begin
|
|
|
|
unless ENV['force'] == 'yes'
|
|
|
|
warning = <<-MSG.strip_heredoc
|
|
|
|
Before restoring the database, we will remove all existing
|
|
|
|
tables to avoid future upgrade problems. Be aware that if you have
|
|
|
|
custom tables in the GitLab database these tables and all data will be
|
|
|
|
removed.
|
|
|
|
MSG
|
|
|
|
puts warning.color(:red)
|
|
|
|
ask_to_continue
|
|
|
|
puts 'Removing all tables. Press `Ctrl-C` within 5 seconds to abort'.color(:yellow)
|
|
|
|
sleep(5)
|
|
|
|
end
|
2018-01-11 11:34:01 -05:00
|
|
|
|
2017-11-07 10:10:57 -05:00
|
|
|
# Drop all tables Load the schema to ensure we don't have any newer tables
|
|
|
|
# hanging out from a failed upgrade
|
|
|
|
$progress.puts 'Cleaning the database ... '.color(:blue)
|
|
|
|
Rake::Task['gitlab:db:drop_tables'].invoke
|
|
|
|
$progress.puts 'done'.color(:green)
|
|
|
|
Rake::Task['gitlab:backup:db:restore'].invoke
|
|
|
|
rescue Gitlab::TaskAbortedByUserError
|
|
|
|
puts "Quitting...".color(:red)
|
|
|
|
exit 1
|
2016-03-08 17:52:48 -05:00
|
|
|
end
|
|
|
|
end
|
2016-10-20 10:33:12 -04:00
|
|
|
|
2016-03-08 17:52:48 -05:00
|
|
|
Rake::Task['gitlab:backup:repo:restore'].invoke unless backup.skipped?('repositories')
|
|
|
|
Rake::Task['gitlab:backup:uploads:restore'].invoke unless backup.skipped?('uploads')
|
|
|
|
Rake::Task['gitlab:backup:builds:restore'].invoke unless backup.skipped?('builds')
|
|
|
|
Rake::Task['gitlab:backup:artifacts:restore'].invoke unless backup.skipped?('artifacts')
|
2016-06-05 14:09:47 -04:00
|
|
|
Rake::Task["gitlab:backup:pages:restore"].invoke unless backup.skipped?('pages')
|
2016-03-08 17:52:48 -05:00
|
|
|
Rake::Task['gitlab:backup:lfs:restore'].invoke unless backup.skipped?('lfs')
|
2016-05-16 18:17:57 -04:00
|
|
|
Rake::Task['gitlab:backup:registry:restore'].invoke unless backup.skipped?('registry')
|
2016-03-08 17:52:48 -05:00
|
|
|
Rake::Task['gitlab:shell:setup'].invoke
|
2016-10-20 10:33:12 -04:00
|
|
|
Rake::Task['cache:clear'].invoke
|
2012-07-09 17:45:43 -04:00
|
|
|
|
2013-08-05 05:26:33 -04:00
|
|
|
backup.cleanup
|
2012-07-09 17:45:43 -04:00
|
|
|
end
|
|
|
|
|
2012-12-20 14:17:09 -05:00
|
|
|
namespace :repo do
|
2018-01-24 03:12:33 -05:00
|
|
|
task create: :gitlab_environment do
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "Dumping repositories ...".color(:blue)
|
2015-03-27 09:18:59 -04:00
|
|
|
|
|
|
|
if ENV["SKIP"] && ENV["SKIP"].include?("repositories")
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "[SKIPPED]".color(:cyan)
|
2015-03-27 09:18:59 -04:00
|
|
|
else
|
|
|
|
Backup::Repository.new.dump
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "done".color(:green)
|
2015-03-27 09:18:59 -04:00
|
|
|
end
|
2012-07-09 17:45:43 -04:00
|
|
|
end
|
|
|
|
|
2018-01-24 03:12:33 -05:00
|
|
|
task restore: :gitlab_environment do
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "Restoring repositories ...".color(:blue)
|
2013-04-05 12:01:19 -04:00
|
|
|
Backup::Repository.new.restore
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "done".color(:green)
|
2012-07-09 17:45:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-20 14:17:09 -05:00
|
|
|
namespace :db do
|
2018-01-24 03:12:33 -05:00
|
|
|
task create: :gitlab_environment do
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "Dumping database ... ".color(:blue)
|
2015-03-27 09:18:59 -04:00
|
|
|
|
|
|
|
if ENV["SKIP"] && ENV["SKIP"].include?("db")
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "[SKIPPED]".color(:cyan)
|
2015-03-27 09:18:59 -04:00
|
|
|
else
|
|
|
|
Backup::Database.new.dump
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "done".color(:green)
|
2015-03-27 09:18:59 -04:00
|
|
|
end
|
2012-07-09 17:45:43 -04:00
|
|
|
end
|
|
|
|
|
2018-01-24 03:12:33 -05:00
|
|
|
task restore: :gitlab_environment do
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "Restoring database ... ".color(:blue)
|
2013-04-05 12:01:19 -04:00
|
|
|
Backup::Database.new.restore
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "done".color(:green)
|
2012-07-09 17:45:43 -04:00
|
|
|
end
|
|
|
|
end
|
2013-04-10 08:41:47 -04:00
|
|
|
|
2015-09-15 04:24:30 -04:00
|
|
|
namespace :builds do
|
2018-01-24 03:12:33 -05:00
|
|
|
task create: :gitlab_environment do
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "Dumping builds ... ".color(:blue)
|
2015-09-15 04:24:30 -04:00
|
|
|
|
|
|
|
if ENV["SKIP"] && ENV["SKIP"].include?("builds")
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "[SKIPPED]".color(:cyan)
|
2015-09-15 04:24:30 -04:00
|
|
|
else
|
|
|
|
Backup::Builds.new.dump
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "done".color(:green)
|
2015-09-15 04:24:30 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-24 03:12:33 -05:00
|
|
|
task restore: :gitlab_environment do
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "Restoring builds ... ".color(:blue)
|
2015-09-15 04:24:30 -04:00
|
|
|
Backup::Builds.new.restore
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "done".color(:green)
|
2015-09-15 04:24:30 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-04-10 08:41:47 -04:00
|
|
|
namespace :uploads do
|
2018-01-24 03:12:33 -05:00
|
|
|
task create: :gitlab_environment do
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "Dumping uploads ... ".color(:blue)
|
2015-03-27 09:18:59 -04:00
|
|
|
|
|
|
|
if ENV["SKIP"] && ENV["SKIP"].include?("uploads")
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "[SKIPPED]".color(:cyan)
|
2015-03-27 09:18:59 -04:00
|
|
|
else
|
|
|
|
Backup::Uploads.new.dump
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "done".color(:green)
|
2015-03-27 09:18:59 -04:00
|
|
|
end
|
2013-04-10 08:41:47 -04:00
|
|
|
end
|
|
|
|
|
2018-01-24 03:12:33 -05:00
|
|
|
task restore: :gitlab_environment do
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "Restoring uploads ... ".color(:blue)
|
2013-04-10 08:41:47 -04:00
|
|
|
Backup::Uploads.new.restore
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "done".color(:green)
|
2014-11-20 09:46:04 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-10-12 17:47:32 -04:00
|
|
|
namespace :artifacts do
|
2018-01-24 03:12:33 -05:00
|
|
|
task create: :gitlab_environment do
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "Dumping artifacts ... ".color(:blue)
|
2015-10-12 17:47:32 -04:00
|
|
|
|
|
|
|
if ENV["SKIP"] && ENV["SKIP"].include?("artifacts")
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "[SKIPPED]".color(:cyan)
|
2015-10-12 17:47:32 -04:00
|
|
|
else
|
|
|
|
Backup::Artifacts.new.dump
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "done".color(:green)
|
2015-10-12 17:47:32 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-24 03:12:33 -05:00
|
|
|
task restore: :gitlab_environment do
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "Restoring artifacts ... ".color(:blue)
|
2015-10-12 17:47:32 -04:00
|
|
|
Backup::Artifacts.new.restore
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "done".color(:green)
|
2015-10-12 17:47:32 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-11-03 15:28:07 -05:00
|
|
|
namespace :pages do
|
2018-01-24 03:12:33 -05:00
|
|
|
task create: :gitlab_environment do
|
2016-06-05 14:09:47 -04:00
|
|
|
$progress.puts "Dumping pages ... ".color(:blue)
|
2015-11-03 15:28:07 -05:00
|
|
|
|
|
|
|
if ENV["SKIP"] && ENV["SKIP"].include?("pages")
|
2016-06-05 14:09:47 -04:00
|
|
|
$progress.puts "[SKIPPED]".color(:cyan)
|
2015-11-03 15:28:07 -05:00
|
|
|
else
|
|
|
|
Backup::Pages.new.dump
|
2016-06-05 14:09:47 -04:00
|
|
|
$progress.puts "done".color(:green)
|
2015-11-03 15:28:07 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-24 03:12:33 -05:00
|
|
|
task restore: :gitlab_environment do
|
2016-06-05 14:09:47 -04:00
|
|
|
$progress.puts "Restoring pages ... ".color(:blue)
|
2015-11-03 15:28:07 -05:00
|
|
|
Backup::Pages.new.restore
|
2016-06-05 14:09:47 -04:00
|
|
|
$progress.puts "done".color(:green)
|
2015-11-03 15:28:07 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-11-18 05:39:26 -05:00
|
|
|
namespace :lfs do
|
2018-01-24 03:12:33 -05:00
|
|
|
task create: :gitlab_environment do
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "Dumping lfs objects ... ".color(:blue)
|
2015-11-18 05:39:26 -05:00
|
|
|
|
|
|
|
if ENV["SKIP"] && ENV["SKIP"].include?("lfs")
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "[SKIPPED]".color(:cyan)
|
2015-11-18 05:39:26 -05:00
|
|
|
else
|
|
|
|
Backup::Lfs.new.dump
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "done".color(:green)
|
2015-11-18 05:39:26 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-24 03:12:33 -05:00
|
|
|
task restore: :gitlab_environment do
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "Restoring lfs objects ... ".color(:blue)
|
2015-11-18 05:39:26 -05:00
|
|
|
Backup::Lfs.new.restore
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "done".color(:green)
|
2015-11-18 05:39:26 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-16 18:17:57 -04:00
|
|
|
namespace :registry do
|
2018-01-24 03:12:33 -05:00
|
|
|
task create: :gitlab_environment do
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "Dumping container registry images ... ".color(:blue)
|
2016-05-16 18:17:57 -04:00
|
|
|
|
2016-05-23 11:17:07 -04:00
|
|
|
if Gitlab.config.registry.enabled
|
|
|
|
if ENV["SKIP"] && ENV["SKIP"].include?("registry")
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "[SKIPPED]".color(:cyan)
|
2016-05-23 11:17:07 -04:00
|
|
|
else
|
|
|
|
Backup::Registry.new.dump
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "done".color(:green)
|
2016-05-23 11:17:07 -04:00
|
|
|
end
|
2016-05-16 18:17:57 -04:00
|
|
|
else
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "[DISABLED]".color(:cyan)
|
2016-05-16 18:17:57 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-24 03:12:33 -05:00
|
|
|
task restore: :gitlab_environment do
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "Restoring container registry images ... ".color(:blue)
|
2018-01-11 11:34:01 -05:00
|
|
|
|
2016-05-23 11:17:07 -04:00
|
|
|
if Gitlab.config.registry.enabled
|
|
|
|
Backup::Registry.new.restore
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "done".color(:green)
|
2016-05-23 11:17:07 -04:00
|
|
|
else
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "[DISABLED]".color(:cyan)
|
2016-05-23 11:17:07 -04:00
|
|
|
end
|
2016-05-16 18:17:57 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-11-20 09:46:04 -05:00
|
|
|
def configure_cron_mode
|
|
|
|
if ENV['CRON']
|
2014-11-20 09:54:39 -05:00
|
|
|
# We need an object we can say 'puts' and 'print' to; let's use a
|
|
|
|
# StringIO.
|
2014-11-20 09:46:04 -05:00
|
|
|
require 'stringio'
|
|
|
|
$progress = StringIO.new
|
|
|
|
else
|
|
|
|
$progress = $stdout
|
2013-04-10 08:41:47 -04:00
|
|
|
end
|
|
|
|
end
|
2012-12-20 14:17:09 -05:00
|
|
|
end # namespace end: backup
|
2012-07-09 17:45:43 -04:00
|
|
|
end # namespace end: gitlab
|