2014-09-02 18:07:02 +05:30
|
|
|
require 'active_record/fixtures'
|
|
|
|
|
|
|
|
namespace :gitlab do
|
|
|
|
namespace :backup do
|
|
|
|
# Create backup of GitLab system
|
2015-09-11 14:41:01 +05:30
|
|
|
desc "GitLab | Create a backup of the GitLab system"
|
2014-09-02 18:07:02 +05:30
|
|
|
task create: :environment do
|
|
|
|
warn_user_is_not_gitlab
|
2015-04-26 12:48:37 +05:30
|
|
|
configure_cron_mode
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
Rake::Task["gitlab:backup:db:create"].invoke
|
|
|
|
Rake::Task["gitlab:backup:repo:create"].invoke
|
|
|
|
Rake::Task["gitlab:backup:uploads:create"].invoke
|
2015-09-25 12:07:36 +05:30
|
|
|
Rake::Task["gitlab:backup:builds:create"].invoke
|
2015-11-26 14:37:03 +05:30
|
|
|
Rake::Task["gitlab:backup:artifacts:create"].invoke
|
|
|
|
Rake::Task["gitlab:backup:lfs:create"].invoke
|
2016-06-02 11:05:42 +05:30
|
|
|
Rake::Task["gitlab:backup:registry:create"].invoke
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
backup = Backup::Manager.new
|
|
|
|
backup.pack
|
|
|
|
backup.cleanup
|
|
|
|
backup.remove_old
|
|
|
|
end
|
|
|
|
|
|
|
|
# Restore backup of GitLab system
|
2016-06-02 11:05:42 +05:30
|
|
|
desc 'GitLab | Restore a previously created backup'
|
2014-09-02 18:07:02 +05:30
|
|
|
task restore: :environment do
|
|
|
|
warn_user_is_not_gitlab
|
2015-04-26 12:48:37 +05:30
|
|
|
configure_cron_mode
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
backup = Backup::Manager.new
|
|
|
|
backup.unpack
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
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
|
2016-06-16 23:09:34 +05:30
|
|
|
puts 'Removing all tables. Press `Ctrl-C` within 5 seconds to abort'.color(:yellow)
|
2016-06-02 11:05:42 +05:30
|
|
|
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-16 23:09:34 +05:30
|
|
|
$progress.puts 'Cleaning the database ... '.color(:blue)
|
2016-06-02 11:05:42 +05:30
|
|
|
Rake::Task['gitlab:db:drop_tables'].invoke
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts 'done'.color(:green)
|
2016-06-02 11:05:42 +05:30
|
|
|
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')
|
|
|
|
Rake::Task['gitlab:backup:registry:restore'].invoke unless backup.skipped?('registry')
|
|
|
|
Rake::Task['gitlab:shell:setup'].invoke
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
backup.cleanup
|
|
|
|
end
|
|
|
|
|
|
|
|
namespace :repo do
|
|
|
|
task create: :environment do
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "Dumping repositories ...".color(:blue)
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
if ENV["SKIP"] && ENV["SKIP"].include?("repositories")
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "[SKIPPED]".color(:cyan)
|
2015-04-26 12:48:37 +05:30
|
|
|
else
|
|
|
|
Backup::Repository.new.dump
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "done".color(:green)
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
task restore: :environment do
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "Restoring repositories ...".color(:blue)
|
2014-09-02 18:07:02 +05:30
|
|
|
Backup::Repository.new.restore
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "done".color(:green)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
namespace :db do
|
|
|
|
task create: :environment do
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "Dumping database ... ".color(:blue)
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
if ENV["SKIP"] && ENV["SKIP"].include?("db")
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "[SKIPPED]".color(:cyan)
|
2015-04-26 12:48:37 +05:30
|
|
|
else
|
|
|
|
Backup::Database.new.dump
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "done".color(:green)
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
task restore: :environment do
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "Restoring database ... ".color(:blue)
|
2014-09-02 18:07:02 +05:30
|
|
|
Backup::Database.new.restore
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "done".color(:green)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-25 12:07:36 +05:30
|
|
|
namespace :builds do
|
|
|
|
task create: :environment do
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "Dumping builds ... ".color(:blue)
|
2015-09-25 12:07:36 +05:30
|
|
|
|
|
|
|
if ENV["SKIP"] && ENV["SKIP"].include?("builds")
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "[SKIPPED]".color(:cyan)
|
2015-09-25 12:07:36 +05:30
|
|
|
else
|
|
|
|
Backup::Builds.new.dump
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "done".color(:green)
|
2015-09-25 12:07:36 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
task restore: :environment do
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "Restoring builds ... ".color(:blue)
|
2015-09-25 12:07:36 +05:30
|
|
|
Backup::Builds.new.restore
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "done".color(:green)
|
2015-09-25 12:07:36 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
namespace :uploads do
|
|
|
|
task create: :environment do
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "Dumping uploads ... ".color(:blue)
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
if ENV["SKIP"] && ENV["SKIP"].include?("uploads")
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "[SKIPPED]".color(:cyan)
|
2015-04-26 12:48:37 +05:30
|
|
|
else
|
|
|
|
Backup::Uploads.new.dump
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "done".color(:green)
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
task restore: :environment do
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "Restoring uploads ... ".color(:blue)
|
2014-09-02 18:07:02 +05:30
|
|
|
Backup::Uploads.new.restore
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "done".color(:green)
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-11-26 14:37:03 +05:30
|
|
|
namespace :artifacts do
|
|
|
|
task create: :environment do
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "Dumping artifacts ... ".color(:blue)
|
2015-11-26 14:37:03 +05:30
|
|
|
|
|
|
|
if ENV["SKIP"] && ENV["SKIP"].include?("artifacts")
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "[SKIPPED]".color(:cyan)
|
2015-11-26 14:37:03 +05:30
|
|
|
else
|
|
|
|
Backup::Artifacts.new.dump
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "done".color(:green)
|
2015-11-26 14:37:03 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
task restore: :environment do
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "Restoring artifacts ... ".color(:blue)
|
2015-11-26 14:37:03 +05:30
|
|
|
Backup::Artifacts.new.restore
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "done".color(:green)
|
2015-11-26 14:37:03 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
namespace :lfs do
|
|
|
|
task create: :environment do
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "Dumping lfs objects ... ".color(:blue)
|
2015-11-26 14:37:03 +05:30
|
|
|
|
|
|
|
if ENV["SKIP"] && ENV["SKIP"].include?("lfs")
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "[SKIPPED]".color(:cyan)
|
2015-11-26 14:37:03 +05:30
|
|
|
else
|
|
|
|
Backup::Lfs.new.dump
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "done".color(:green)
|
2015-11-26 14:37:03 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
task restore: :environment do
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "Restoring lfs objects ... ".color(:blue)
|
2015-11-26 14:37:03 +05:30
|
|
|
Backup::Lfs.new.restore
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "done".color(:green)
|
2015-11-26 14:37:03 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
namespace :registry do
|
|
|
|
task create: :environment do
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "Dumping container registry images ... ".color(:blue)
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
if Gitlab.config.registry.enabled
|
|
|
|
if ENV["SKIP"] && ENV["SKIP"].include?("registry")
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "[SKIPPED]".color(:cyan)
|
2016-06-02 11:05:42 +05:30
|
|
|
else
|
|
|
|
Backup::Registry.new.dump
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "done".color(:green)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
else
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "[DISABLED]".color(:cyan)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
task restore: :environment do
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "Restoring container registry images ... ".color(:blue)
|
2016-06-02 11:05:42 +05:30
|
|
|
if Gitlab.config.registry.enabled
|
|
|
|
Backup::Registry.new.restore
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "done".color(:green)
|
2016-06-02 11:05:42 +05:30
|
|
|
else
|
2016-06-16 23:09:34 +05:30
|
|
|
$progress.puts "[DISABLED]".color(:cyan)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
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
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end # namespace end: backup
|
|
|
|
end # namespace end: gitlab
|