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
|