gitlab-org--gitlab-foss/lib/tasks/gitlab/backup.rake

107 lines
2.9 KiB
Ruby
Raw Normal View History

require 'active_record/fixtures'
namespace :gitlab do
namespace :backup do
2012-09-26 11:18:10 +00:00
# Create backup of GitLab system
desc "GitLab | Create a backup of the GitLab system"
task create: :environment do
2012-12-23 20:15:25 +00:00
warn_user_is_not_gitlab
configure_cron_mode
2012-12-23 20:15:25 +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
backup = Backup::Manager.new
backup.pack
backup.cleanup
backup.remove_old
end
2012-09-26 11:18:10 +00:00
# Restore backup of GitLab system
desc "GitLab | Restore a previously created backup"
task restore: :environment do
2012-12-23 20:15:25 +00:00
warn_user_is_not_gitlab
configure_cron_mode
2012-12-23 20:15:25 +00:00
backup = Backup::Manager.new
backup.unpack
2015-03-27 13:18:59 +00:00
Rake::Task["gitlab:backup:db:restore"].invoke unless backup.skipped?("db")
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:shell:setup"].invoke
backup.cleanup
end
namespace :repo do
task create: :environment do
$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
end
task restore: :environment do
$progress.puts "Restoring repositories ...".blue
2013-04-05 16:01:19 +00:00
Backup::Repository.new.restore
$progress.puts "done".green
end
end
namespace :db do
task create: :environment do
$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
end
task restore: :environment do
$progress.puts "Restoring database ... ".blue
2013-04-05 16:01:19 +00:00
Backup::Database.new.restore
$progress.puts "done".green
end
end
2013-04-10 12:41:47 +00:00
namespace :uploads do
task create: :environment do
$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
task restore: :environment do
$progress.puts "Restoring uploads ... ".blue
2013-04-10 12:41:47 +00:00
Backup::Uploads.new.restore
$progress.puts "done".green
end
end
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.
require 'stringio'
$progress = StringIO.new
else
$progress = $stdout
2013-04-10 12:41:47 +00:00
end
end
end # namespace end: backup
end # namespace end: gitlab