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"
|
2013-05-05 10:01:10 -04:00
|
|
|
task create: :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-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'
|
2013-05-05 10:01:10 -04:00
|
|
|
task restore: :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')
|
|
|
|
unless ENV['force'] == 'yes'
|
2016-06-28 16:51:50 -04:00
|
|
|
warning = <<-MSG.strip_heredoc
|
2016-03-08 17:52:48 -05:00
|
|
|
Before restoring the database we recommend removing 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
|
2016-06-28 16:51:50 -04:00
|
|
|
puts warning.color(:red)
|
2016-03-08 17:52:48 -05:00
|
|
|
ask_to_continue
|
2016-06-01 18:37:15 -04:00
|
|
|
puts 'Removing all tables. Press `Ctrl-C` within 5 seconds to abort'.color(:yellow)
|
2016-03-08 17:52:48 -05:00
|
|
|
sleep(5)
|
|
|
|
end
|
|
|
|
# Drop all tables Load the schema to ensure we don't have any newer tables
|
|
|
|
# hanging out from a failed upgrade
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts 'Cleaning the database ... '.color(:blue)
|
2016-03-08 17:52:48 -05:00
|
|
|
Rake::Task['gitlab:db:drop_tables'].invoke
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts 'done'.color(:green)
|
2016-03-08 17:52:48 -05:00
|
|
|
Rake::Task['gitlab:backup:db:restore'].invoke
|
|
|
|
end
|
|
|
|
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')
|
|
|
|
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
|
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
|
2013-05-05 10:01:10 -04:00
|
|
|
task create: :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
|
|
|
|
|
2013-05-05 10:01:10 -04:00
|
|
|
task restore: :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
|
2013-05-05 10:01:10 -04:00
|
|
|
task create: :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
|
|
|
|
|
2013-05-05 10:01:10 -04:00
|
|
|
task restore: :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
|
|
|
|
task create: :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
|
|
|
|
|
|
|
|
task restore: :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
|
2013-05-05 10:01:10 -04:00
|
|
|
task create: :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
|
|
|
|
|
2013-05-05 10:01:10 -04:00
|
|
|
task restore: :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
|
|
|
|
task create: :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
|
|
|
|
|
|
|
|
task restore: :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-18 05:39:26 -05:00
|
|
|
namespace :lfs do
|
|
|
|
task create: :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
|
|
|
|
|
|
|
|
task restore: :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
|
|
|
|
task create: :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
|
|
|
|
|
|
|
|
task restore: :environment do
|
2016-06-01 18:37:15 -04:00
|
|
|
$progress.puts "Restoring container registry images ... ".color(:blue)
|
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
|