2012-07-09 21:45:43 +00:00
|
|
|
require 'active_record/fixtures'
|
|
|
|
|
|
|
|
namespace :gitlab do
|
2012-12-20 19:17:09 +00:00
|
|
|
namespace :backup do
|
2012-09-26 11:18:10 +00:00
|
|
|
# Create backup of GitLab system
|
2015-06-23 14:52:40 +00:00
|
|
|
desc "GitLab | Create a backup of the GitLab system"
|
2013-05-05 14:01:10 +00:00
|
|
|
task create: :environment do
|
2012-12-23 20:15:25 +00:00
|
|
|
warn_user_is_not_gitlab
|
2014-11-20 14:46:04 +00:00
|
|
|
configure_cron_mode
|
2012-12-23 20:15:25 +00:00
|
|
|
|
2012-12-20 19:17:09 +00:00
|
|
|
Rake::Task["gitlab:backup:db:create"].invoke
|
|
|
|
Rake::Task["gitlab:backup:repo:create"].invoke
|
2013-04-10 12:41:47 +00:00
|
|
|
Rake::Task["gitlab:backup:uploads:create"].invoke
|
2015-09-15 08:24:30 +00:00
|
|
|
Rake::Task["gitlab:backup:builds:create"].invoke
|
2015-10-12 21:47:32 +00:00
|
|
|
Rake::Task["gitlab:backup:artifacts:create"].invoke
|
2015-11-18 10:39:26 +00:00
|
|
|
Rake::Task["gitlab:backup:lfs:create"].invoke
|
2016-05-16 22:17:57 +00:00
|
|
|
Rake::Task["gitlab:backup:registry:create"].invoke
|
2012-07-09 21:45:43 +00:00
|
|
|
|
2013-08-05 09:26:33 +00:00
|
|
|
backup = Backup::Manager.new
|
|
|
|
backup.pack
|
|
|
|
backup.cleanup
|
|
|
|
backup.remove_old
|
2012-07-09 21:45:43 +00:00
|
|
|
end
|
|
|
|
|
2012-09-26 11:18:10 +00:00
|
|
|
# Restore backup of GitLab system
|
2016-03-08 22:52:48 +00:00
|
|
|
desc 'GitLab | Restore a previously created backup'
|
2013-05-05 14:01:10 +00:00
|
|
|
task restore: :environment do
|
2012-12-23 20:15:25 +00:00
|
|
|
warn_user_is_not_gitlab
|
2014-11-20 14:46:04 +00:00
|
|
|
configure_cron_mode
|
2012-12-23 20:15:25 +00:00
|
|
|
|
2013-08-05 09:26:33 +00:00
|
|
|
backup = Backup::Manager.new
|
|
|
|
backup.unpack
|
2012-07-09 21:45:43 +00:00
|
|
|
|
2016-03-08 22:52:48 +00:00
|
|
|
unless backup.skipped?('db')
|
|
|
|
unless ENV['force'] == 'yes'
|
|
|
|
warning = warning = <<-MSG.strip_heredoc
|
|
|
|
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
|
|
|
|
ask_to_continue
|
|
|
|
puts 'Removing all tables. Press `Ctrl-C` within 5 seconds to abort'.yellow
|
|
|
|
sleep(5)
|
|
|
|
end
|
|
|
|
# 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 ... '.blue
|
|
|
|
Rake::Task['gitlab:db:drop_tables'].invoke
|
|
|
|
$progress.puts 'done'.green
|
|
|
|
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 22:17:57 +00:00
|
|
|
Rake::Task['gitlab:backup:registry:restore'].invoke unless backup.skipped?('registry')
|
2016-03-08 22:52:48 +00:00
|
|
|
Rake::Task['gitlab:shell:setup'].invoke
|
2012-07-09 21:45:43 +00:00
|
|
|
|
2013-08-05 09:26:33 +00:00
|
|
|
backup.cleanup
|
2012-07-09 21:45:43 +00:00
|
|
|
end
|
|
|
|
|
2012-12-20 19:17:09 +00:00
|
|
|
namespace :repo do
|
2013-05-05 14:01:10 +00:00
|
|
|
task create: :environment do
|
2014-11-20 14:46:04 +00:00
|
|
|
$progress.puts "Dumping repositories ...".blue
|
2015-03-27 13:18:59 +00:00
|
|
|
|
|
|
|
if ENV["SKIP"] && ENV["SKIP"].include?("repositories")
|
|
|
|
$progress.puts "[SKIPPED]".cyan
|
|
|
|
else
|
|
|
|
Backup::Repository.new.dump
|
|
|
|
$progress.puts "done".green
|
|
|
|
end
|
2012-07-09 21:45:43 +00:00
|
|
|
end
|
|
|
|
|
2013-05-05 14:01:10 +00:00
|
|
|
task restore: :environment do
|
2014-11-20 14:46:04 +00:00
|
|
|
$progress.puts "Restoring repositories ...".blue
|
2013-04-05 16:01:19 +00:00
|
|
|
Backup::Repository.new.restore
|
2014-11-20 14:46:04 +00:00
|
|
|
$progress.puts "done".green
|
2012-07-09 21:45:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-20 19:17:09 +00:00
|
|
|
namespace :db do
|
2013-05-05 14:01:10 +00:00
|
|
|
task create: :environment do
|
2014-11-20 14:46:04 +00:00
|
|
|
$progress.puts "Dumping database ... ".blue
|
2015-03-27 13:18:59 +00:00
|
|
|
|
|
|
|
if ENV["SKIP"] && ENV["SKIP"].include?("db")
|
|
|
|
$progress.puts "[SKIPPED]".cyan
|
|
|
|
else
|
|
|
|
Backup::Database.new.dump
|
|
|
|
$progress.puts "done".green
|
|
|
|
end
|
2012-07-09 21:45:43 +00:00
|
|
|
end
|
|
|
|
|
2013-05-05 14:01:10 +00:00
|
|
|
task restore: :environment do
|
2014-11-20 14:46:04 +00:00
|
|
|
$progress.puts "Restoring database ... ".blue
|
2013-04-05 16:01:19 +00:00
|
|
|
Backup::Database.new.restore
|
2014-11-20 14:46:04 +00:00
|
|
|
$progress.puts "done".green
|
2012-07-09 21:45:43 +00:00
|
|
|
end
|
|
|
|
end
|
2013-04-10 12:41:47 +00:00
|
|
|
|
2015-09-15 08:24:30 +00:00
|
|
|
namespace :builds do
|
|
|
|
task create: :environment do
|
|
|
|
$progress.puts "Dumping builds ... ".blue
|
|
|
|
|
|
|
|
if ENV["SKIP"] && ENV["SKIP"].include?("builds")
|
|
|
|
$progress.puts "[SKIPPED]".cyan
|
|
|
|
else
|
|
|
|
Backup::Builds.new.dump
|
|
|
|
$progress.puts "done".green
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
task restore: :environment do
|
|
|
|
$progress.puts "Restoring builds ... ".blue
|
|
|
|
Backup::Builds.new.restore
|
|
|
|
$progress.puts "done".green
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-04-10 12:41:47 +00:00
|
|
|
namespace :uploads do
|
2013-05-05 14:01:10 +00:00
|
|
|
task create: :environment do
|
2014-11-20 14:46:04 +00:00
|
|
|
$progress.puts "Dumping uploads ... ".blue
|
2015-03-27 13:18:59 +00:00
|
|
|
|
|
|
|
if ENV["SKIP"] && ENV["SKIP"].include?("uploads")
|
|
|
|
$progress.puts "[SKIPPED]".cyan
|
|
|
|
else
|
|
|
|
Backup::Uploads.new.dump
|
|
|
|
$progress.puts "done".green
|
|
|
|
end
|
2013-04-10 12:41:47 +00:00
|
|
|
end
|
|
|
|
|
2013-05-05 14:01:10 +00:00
|
|
|
task restore: :environment do
|
2014-11-20 14:46:04 +00:00
|
|
|
$progress.puts "Restoring uploads ... ".blue
|
2013-04-10 12:41:47 +00:00
|
|
|
Backup::Uploads.new.restore
|
2014-11-20 14:46:04 +00:00
|
|
|
$progress.puts "done".green
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-10-12 21:47:32 +00:00
|
|
|
namespace :artifacts do
|
|
|
|
task create: :environment do
|
|
|
|
$progress.puts "Dumping artifacts ... ".blue
|
|
|
|
|
|
|
|
if ENV["SKIP"] && ENV["SKIP"].include?("artifacts")
|
|
|
|
$progress.puts "[SKIPPED]".cyan
|
|
|
|
else
|
|
|
|
Backup::Artifacts.new.dump
|
|
|
|
$progress.puts "done".green
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
task restore: :environment do
|
|
|
|
$progress.puts "Restoring artifacts ... ".blue
|
|
|
|
Backup::Artifacts.new.restore
|
|
|
|
$progress.puts "done".green
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-11-18 10:39:26 +00:00
|
|
|
namespace :lfs do
|
|
|
|
task create: :environment do
|
|
|
|
$progress.puts "Dumping lfs objects ... ".blue
|
|
|
|
|
|
|
|
if ENV["SKIP"] && ENV["SKIP"].include?("lfs")
|
|
|
|
$progress.puts "[SKIPPED]".cyan
|
|
|
|
else
|
|
|
|
Backup::Lfs.new.dump
|
|
|
|
$progress.puts "done".green
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
task restore: :environment do
|
|
|
|
$progress.puts "Restoring lfs objects ... ".blue
|
|
|
|
Backup::Lfs.new.restore
|
|
|
|
$progress.puts "done".green
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-16 22:17:57 +00:00
|
|
|
namespace :registry do
|
|
|
|
task create: :environment do
|
|
|
|
$progress.puts "Dumping container registry images ... ".blue
|
|
|
|
|
2016-05-23 15:17:07 +00:00
|
|
|
if Gitlab.config.registry.enabled
|
|
|
|
if ENV["SKIP"] && ENV["SKIP"].include?("registry")
|
|
|
|
$progress.puts "[SKIPPED]".cyan
|
|
|
|
else
|
|
|
|
Backup::Registry.new.dump
|
|
|
|
$progress.puts "done".green
|
|
|
|
end
|
2016-05-16 22:17:57 +00:00
|
|
|
else
|
2016-05-23 15:17:07 +00:00
|
|
|
$progress.puts "[DISABLED]".cyan
|
2016-05-16 22:17:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
task restore: :environment do
|
|
|
|
$progress.puts "Restoring container registry images ... ".blue
|
2016-05-23 15:17:07 +00:00
|
|
|
if Gitlab.config.registry.enabled
|
|
|
|
Backup::Registry.new.restore
|
|
|
|
$progress.puts "done".green
|
|
|
|
else
|
|
|
|
$progress.puts "[DISABLED]".cyan
|
|
|
|
end
|
2016-05-16 22:17:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-11-20 14:46:04 +00:00
|
|
|
def configure_cron_mode
|
|
|
|
if ENV['CRON']
|
2014-11-20 14:54:39 +00:00
|
|
|
# We need an object we can say 'puts' and 'print' to; let's use a
|
|
|
|
# StringIO.
|
2014-11-20 14:46:04 +00:00
|
|
|
require 'stringio'
|
|
|
|
$progress = StringIO.new
|
|
|
|
else
|
|
|
|
$progress = $stdout
|
2013-04-10 12:41:47 +00:00
|
|
|
end
|
|
|
|
end
|
2012-12-20 19:17:09 +00:00
|
|
|
end # namespace end: backup
|
2012-07-09 21:45:43 +00:00
|
|
|
end # namespace end: gitlab
|