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
|
|
|
|
|
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
|
|
|
|
2018-05-24 10:58:25 -04:00
|
|
|
backup = Backup::Manager.new(progress)
|
2013-08-05 05:26:33 -04:00
|
|
|
backup.pack
|
|
|
|
backup.cleanup
|
|
|
|
backup.remove_old
|
2019-05-07 15:46:39 -04:00
|
|
|
|
|
|
|
puts "Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data \n" \
|
|
|
|
"and are not included in this backup. You will need these files to restore a backup.\n" \
|
|
|
|
"Please back them up manually.".color(:red)
|
|
|
|
puts "Backup task is done."
|
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
|
|
|
|
|
2018-05-24 10:58:25 -04:00
|
|
|
backup = Backup::Manager.new(progress)
|
2013-08-05 05:26:33 -04:00
|
|
|
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
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time 'Cleaning the database ... '.color(:blue)
|
2017-11-07 10:10:57 -05:00
|
|
|
Rake::Task['gitlab:db:drop_tables'].invoke
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time 'done'.color(:green)
|
2017-11-07 10:10:57 -05:00
|
|
|
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')
|
2019-02-20 10:10:57 -05: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
|
2019-05-07 15:46:39 -04:00
|
|
|
puts "Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data \n" \
|
|
|
|
"and are not included in this backup. You will need to restore these files manually.".color(:red)
|
|
|
|
puts "Restore task is done."
|
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
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "Dumping repositories ...".color(:blue)
|
2015-03-27 09:18:59 -04:00
|
|
|
|
|
|
|
if ENV["SKIP"] && ENV["SKIP"].include?("repositories")
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "[SKIPPED]".color(:cyan)
|
2015-03-27 09:18:59 -04:00
|
|
|
else
|
2018-05-24 10:58:25 -04:00
|
|
|
Backup::Repository.new(progress).dump
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "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
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "Restoring repositories ...".color(:blue)
|
2018-05-24 10:58:25 -04:00
|
|
|
Backup::Repository.new(progress).restore
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "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
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "Dumping database ... ".color(:blue)
|
2015-03-27 09:18:59 -04:00
|
|
|
|
|
|
|
if ENV["SKIP"] && ENV["SKIP"].include?("db")
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "[SKIPPED]".color(:cyan)
|
2015-03-27 09:18:59 -04:00
|
|
|
else
|
2018-05-24 10:58:25 -04:00
|
|
|
Backup::Database.new(progress).dump
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "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
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "Restoring database ... ".color(:blue)
|
2018-05-24 10:58:25 -04:00
|
|
|
Backup::Database.new(progress).restore
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "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
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "Dumping builds ... ".color(:blue)
|
2015-09-15 04:24:30 -04:00
|
|
|
|
|
|
|
if ENV["SKIP"] && ENV["SKIP"].include?("builds")
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "[SKIPPED]".color(:cyan)
|
2015-09-15 04:24:30 -04:00
|
|
|
else
|
2018-05-24 10:58:25 -04:00
|
|
|
Backup::Builds.new(progress).dump
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "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
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "Restoring builds ... ".color(:blue)
|
2018-05-24 10:58:25 -04:00
|
|
|
Backup::Builds.new(progress).restore
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "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
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "Dumping uploads ... ".color(:blue)
|
2015-03-27 09:18:59 -04:00
|
|
|
|
|
|
|
if ENV["SKIP"] && ENV["SKIP"].include?("uploads")
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "[SKIPPED]".color(:cyan)
|
2015-03-27 09:18:59 -04:00
|
|
|
else
|
2018-05-24 10:58:25 -04:00
|
|
|
Backup::Uploads.new(progress).dump
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "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
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "Restoring uploads ... ".color(:blue)
|
2018-05-24 10:58:25 -04:00
|
|
|
Backup::Uploads.new(progress).restore
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "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
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "Dumping artifacts ... ".color(:blue)
|
2015-10-12 17:47:32 -04:00
|
|
|
|
|
|
|
if ENV["SKIP"] && ENV["SKIP"].include?("artifacts")
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "[SKIPPED]".color(:cyan)
|
2015-10-12 17:47:32 -04:00
|
|
|
else
|
2018-05-24 10:58:25 -04:00
|
|
|
Backup::Artifacts.new(progress).dump
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "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
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "Restoring artifacts ... ".color(:blue)
|
2018-05-24 10:58:25 -04:00
|
|
|
Backup::Artifacts.new(progress).restore
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "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
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "Dumping pages ... ".color(:blue)
|
2015-11-03 15:28:07 -05:00
|
|
|
|
|
|
|
if ENV["SKIP"] && ENV["SKIP"].include?("pages")
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "[SKIPPED]".color(:cyan)
|
2015-11-03 15:28:07 -05:00
|
|
|
else
|
2018-05-24 10:58:25 -04:00
|
|
|
Backup::Pages.new(progress).dump
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "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
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "Restoring pages ... ".color(:blue)
|
2018-05-24 10:58:25 -04:00
|
|
|
Backup::Pages.new(progress).restore
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "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
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "Dumping lfs objects ... ".color(:blue)
|
2015-11-18 05:39:26 -05:00
|
|
|
|
|
|
|
if ENV["SKIP"] && ENV["SKIP"].include?("lfs")
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "[SKIPPED]".color(:cyan)
|
2015-11-18 05:39:26 -05:00
|
|
|
else
|
2018-05-24 10:58:25 -04:00
|
|
|
Backup::Lfs.new(progress).dump
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "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
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "Restoring lfs objects ... ".color(:blue)
|
2018-05-24 10:58:25 -04:00
|
|
|
Backup::Lfs.new(progress).restore
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "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
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "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")
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "[SKIPPED]".color(:cyan)
|
2016-05-23 11:17:07 -04:00
|
|
|
else
|
2018-05-24 10:58:25 -04:00
|
|
|
Backup::Registry.new(progress).dump
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "done".color(:green)
|
2016-05-23 11:17:07 -04:00
|
|
|
end
|
2016-05-16 18:17:57 -04:00
|
|
|
else
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "[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
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "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
|
2018-05-24 10:58:25 -04:00
|
|
|
Backup::Registry.new(progress).restore
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "done".color(:green)
|
2016-05-23 11:17:07 -04:00
|
|
|
else
|
2018-06-03 17:40:49 -04:00
|
|
|
puts_time "[DISABLED]".color(:cyan)
|
2016-05-23 11:17:07 -04:00
|
|
|
end
|
2016-05-16 18:17:57 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-03 17:40:49 -04:00
|
|
|
def puts_time(msg)
|
|
|
|
progress.puts "#{Time.now} -- #{msg}"
|
|
|
|
end
|
|
|
|
|
2018-05-24 10:58:25 -04:00
|
|
|
def progress
|
2014-11-20 09:46:04 -05:00
|
|
|
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'
|
2018-05-24 10:58:25 -04:00
|
|
|
StringIO.new
|
2014-11-20 09:46:04 -05:00
|
|
|
else
|
2018-05-24 10:58:25 -04:00
|
|
|
$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
|