diff options
author | Valery Sizov <vsv2711@gmail.com> | 2015-05-06 18:27:00 +0300 |
---|---|---|
committer | Valery Sizov <vsv2711@gmail.com> | 2015-05-06 18:27:00 +0300 |
commit | 24a1c4789a2d04d26a4100066433d966e4ad5407 (patch) | |
tree | d58cd58c53795b160e5c1f544aca3e57b4b8fb50 /lib/tasks/backup.rake | |
parent | afcdd6f1030880ac107afefde02cd3c03f364195 (diff) | |
download | gitlab-ci-24a1c4789a2d04d26a4100066433d966e4ad5407.tar.gz |
backup/restore rake task
Diffstat (limited to 'lib/tasks/backup.rake')
-rw-r--r-- | lib/tasks/backup.rake | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/tasks/backup.rake b/lib/tasks/backup.rake new file mode 100644 index 0000000..84f9bcd --- /dev/null +++ b/lib/tasks/backup.rake @@ -0,0 +1,43 @@ +namespace :backup do + + desc "GITLAB | Create a backup of the GitLab CI database" + task create: :environment do + configure_cron_mode + + $progress.puts "Dumping database ... ".blue + + Backup::Database.new.dump + $progress.puts "done".green + + backup = Backup::Manager.new + backup.pack + backup.cleanup + backup.remove_old + end + + desc "GITLAB | Restore a previously created backup" + task restore: :environment do + configure_cron_mode + + backup = Backup::Manager.new + backup.unpack + + $progress.puts "Restoring database ... ".blue + Backup::Database.new.restore + $progress.puts "done".green + + backup.cleanup + 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 + end + end +end + |