Class: Dbtools::Backup

Inherits:
Thor
  • Object
show all
Defined in:
lib/tasks/backup.rb

Instance Method Summary collapse

Instance Method Details

#blazegraph(url) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/tasks/backup.rb', line 86

def blazegraph(url)
  if !options[:googledrive] && !options[:aws_s3]
    STDERR.puts "You must choose either Google Drive or AWS S3 as backup location. " +
                    "Pass --googledrive or --aws_s3 as an argument."
    return
  end
  if options[:aws_s3]
    STDERR.puts "Bucket and key must be specified. Use the arguments --bucket= and --key=." if options[:bucket].nil? || options[:key].nil?
    return
  end

  filename = File.join(Dir.pwd, options[:filename])
  begin
    invoke "dbtools:dump:blazegraph", [url, filename], :compress => true
    invoke "dbtools:google_drive:upload", [filename], :folder => options[:folder]
    invoke "dbtools:aws:upload_to_s3", [filename, options[:bucket], options[:key]] if options[:aws_s3]
  ensure
    File.delete(filename) if File.exists?(filename)
  end
end

#rdf(sparql_endpoint) ⇒ Object



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
63
64
65
# File 'lib/tasks/backup.rb', line 34

def rdf(sparql_endpoint)
  if !options[:googledrive] && !options[:aws_s3]
    error_message = "You must choose either Google Drive or AWS S3 as backup location. " +
        "Pass --googledrive or --aws_s3 as an argument."
    STDERR.puts error_message
    `sudo /usr/local/bin/geophy-nagios-report -s blazegraph-backup -m "#{error_message}" -c "#{$PROGRAM_NAME}" ERROR` if options[:nagios]
    return
  end

  if options[:aws_s3]
    if options[:bucket].nil? || options[:key].nil?
      error_message = "Bucket and key must be specified. Use the arguments --bucket= and --key="
      STDERR.puts error_message
      `sudo /usr/local/bin/geophy-nagios-report -s blazegraph-backup -m "#{error_message}" -c "#{$PROGRAM_NAME}" ERROR` if options[:nagios]
      return
    end
  end

  filename = options[:filename]
  tempfile = Tempfile.new(['backup', '.nt.gz'])
  begin
    invoke "dbtools:dump:rdf", [sparql_endpoint, tempfile.path], :compress => true
    invoke "dbtools:google_drive:upload", [tempfile.path], :filename => filename, :folder => options[:folder] if options[:googledrive]
    invoke "dbtools:aws:upload_to_s3", [tempfile.path, options[:bucket], options[:key]], :attributes => false if options[:aws_s3]
    `sudo /usr/local/bin/geophy-nagios-report -s blazegraph-backup -m "Backup successful" -c "#{$PROGRAM_NAME}" OK` if options[:nagios]
  rescue Exception => e
    `sudo /usr/local/bin/geophy-nagios-report -s blazegraph-backup -m "#{e.message}" -c "#{$PROGRAM_NAME}" ERROR` if options[:nagios]
  ensure
    tempfile.close
    tempfile.unlink
  end
end