Welcome to mirror list, hosted at ThFree Co, Russian Federation.

backup.rake « ci « tasks « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1cb2e43f8757550d1218e7cd83a5e4a25be9b61b (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
namespace :ci do
  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
      Ci::Backup::Database.new.dump
      $progress.puts "done".green

      $progress.puts "Dumping builds ... ".blue
      Ci::Backup::Builds.new.dump
      $progress.puts "done".green

      backup = Ci::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 = Ci::Backup::Manager.new
      backup.unpack

      $progress.puts "Restoring database ... ".blue
      Ci::Backup::Database.new.restore
      $progress.puts "done".green

      $progress.puts "Restoring builds ... ".blue
      Ci::Backup::Builds.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

  # Disable colors for CRON
  unless STDOUT.isatty
    module Colored
      extend self

      def colorize(string, options={})
        string
      end
    end
  end
end