debian-mirror-gitlab/lib/tasks/gitlab/backup.rake

107 lines
2.9 KiB
Ruby
Raw Normal View History

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
backup = Backup::Manager.new
backup.pack
backup.cleanup
backup.remove_old
end
# Restore backup of GitLab system
2015-09-11 14:41:01 +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
2015-04-26 12:48:37 +05:30
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")
2014-09-02 18:07:02 +05:30
Rake::Task["gitlab:shell:setup"].invoke
backup.cleanup
end
namespace :repo do
task create: :environment do
2015-04-26 12:48:37 +05:30
$progress.puts "Dumping repositories ...".blue
if ENV["SKIP"] && ENV["SKIP"].include?("repositories")
$progress.puts "[SKIPPED]".cyan
else
Backup::Repository.new.dump
$progress.puts "done".green
end
2014-09-02 18:07:02 +05:30
end
task restore: :environment do
2015-04-26 12:48:37 +05:30
$progress.puts "Restoring repositories ...".blue
2014-09-02 18:07:02 +05:30
Backup::Repository.new.restore
2015-04-26 12:48:37 +05:30
$progress.puts "done".green
2014-09-02 18:07:02 +05:30
end
end
namespace :db do
task create: :environment do
2015-04-26 12:48:37 +05:30
$progress.puts "Dumping database ... ".blue
if ENV["SKIP"] && ENV["SKIP"].include?("db")
$progress.puts "[SKIPPED]".cyan
else
Backup::Database.new.dump
$progress.puts "done".green
end
2014-09-02 18:07:02 +05:30
end
task restore: :environment do
2015-04-26 12:48:37 +05:30
$progress.puts "Restoring database ... ".blue
2014-09-02 18:07:02 +05:30
Backup::Database.new.restore
2015-04-26 12:48:37 +05:30
$progress.puts "done".green
2014-09-02 18:07:02 +05:30
end
end
namespace :uploads do
task create: :environment do
2015-04-26 12:48:37 +05:30
$progress.puts "Dumping uploads ... ".blue
if ENV["SKIP"] && ENV["SKIP"].include?("uploads")
$progress.puts "[SKIPPED]".cyan
else
Backup::Uploads.new.dump
$progress.puts "done".green
end
2014-09-02 18:07:02 +05:30
end
task restore: :environment do
2015-04-26 12:48:37 +05:30
$progress.puts "Restoring uploads ... ".blue
2014-09-02 18:07:02 +05:30
Backup::Uploads.new.restore
2015-04-26 12:48:37 +05:30
$progress.puts "done".green
end
end
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