summaryrefslogtreecommitdiff
path: root/lib/tasks/backup.rake
blob: 84f9bcd25726b8155934d40f7b14c1f92738c071 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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