Class: Backups::Base
Constant Summary
collapse
- ALL_DATABASES =
"all-databases"
Constants included
from Loader
Loader::CONFIG_ENV, Loader::CONFIG_SYSTEM, Loader::CONFIG_USER
Instance Method Summary
collapse
Methods included from Loader
#load_configs
Methods included from System
#delete, #delete_dir, #exec, #get_latest_s3, #mkdir, #nuke_dir, #write
Constructor Details
#initialize(config) ⇒ Base
Returns a new instance of Base.
9
10
11
|
# File 'lib/backups/base.rb', line 9
def initialize config
@config = config
end
|
Instance Method Details
#compress(source, dest, secret) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/backups/base.rb', line 28
def compress source, dest, secret
if source.kind_of? Array
dir = File.dirname(source[0])
base = source.map {|v| File.basename(v)}.join(' ')
else
dir = File.dirname(source)
base = File.basename(source)
end
commands = []
commands << "cd #{dir} && zip"
commands << "--password #{secret}" if secret
commands << "-r #{dest} #{base}"
exec commands.join(' ')
end
|
#get_date_path ⇒ Object
19
20
21
|
# File 'lib/backups/base.rb', line 19
def get_date_path
Time.now.strftime('%Y/%m/%d')
end
|
#get_prefix ⇒ Object
23
24
25
26
|
# File 'lib/backups/base.rb', line 23
def get_prefix
return @options['s3']['prefix'] if @options['s3']['prefix']
return @config["_name"]
end
|
#get_timestamp ⇒ Object
13
14
15
16
17
|
# File 'lib/backups/base.rb', line 13
def get_timestamp
now = Time.new
now = now.utc if now.utc?
now.iso8601.gsub(':', '-')
end
|
#send_to_s3(bucket, path, filename, options = nil) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/backups/base.rb', line 45
def send_to_s3 bucket, path, filename, options = nil
dest = "s3://#{bucket}/#{path}"
$LOGGER.info "Sending to #{dest}"
exec "aws s3 cp #{filename} #{dest}/"
return unless options
tags = options.fetch('tags', {})
return unless tags.size > 0
key = "#{path}/#{File.basename(filename)}"
tag_s3_object bucket, key, tags
end
|
#tag_s3_object(bucket, key, tags) ⇒ Object
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/backups/base.rb', line 58
def tag_s3_object bucket, key, tags
tagSet = tags.map{ |k, v| "{Key=#{k},Value=#{v}}" }.join(",")
$LOGGER.info "Tagging s3://#{bucket}/#{key}"
$LOGGER.debug "Tagset: #{tagSet}"
exec "aws s3api put-object-tagging \
--bucket #{bucket} \
--key #{key} \
--tagging 'TagSet=[#{tagSet}]'"
end
|