app-tools 1.14.0 → 1.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/mongo-backup +131 -0
- data/lib/app_tools/version.rb +1 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e90602b475537f670818112d0eed0d7240265ed9
|
4
|
+
data.tar.gz: 9fbd170fa03fb0e83220ee3465c14d18e29c4364
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84bad9a3bdc3606ea2a507cb8dac4b96ba90dff0722c17495cc0ead37f38b79d51b1b5cd6efb70949812702e49b024dce2fb761f0ce2d41a351b923bdac85806
|
7
|
+
data.tar.gz: 0b01b302c49db8e84a57a1f289c1f7e8b46d6192b87596c46e4ff5d55720216958cab7750711a88748e5d0b970691030534e9770af15f950d5a5f29fbb4432fb
|
data/bin/mongo-backup
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'methadone'
|
5
|
+
require 'app_tools/version'
|
6
|
+
require 'fileutils'
|
7
|
+
require 'mongo'
|
8
|
+
|
9
|
+
module AppTools
|
10
|
+
module MongoBackup
|
11
|
+
include Methadone::Main
|
12
|
+
include Methadone::CLILogging
|
13
|
+
include Methadone::ExitNow
|
14
|
+
|
15
|
+
def self.find_tool(name, paths)
|
16
|
+
paths.each { |path|
|
17
|
+
full_path = File.join(path, name)
|
18
|
+
|
19
|
+
if File.exist?(full_path)
|
20
|
+
return full_path
|
21
|
+
end
|
22
|
+
}
|
23
|
+
raise "Unable to find tool '#{name}'"
|
24
|
+
end
|
25
|
+
|
26
|
+
main do
|
27
|
+
profile = options[:profile]
|
28
|
+
bucket_name = options[:bucket]
|
29
|
+
max_backups = options[:max].to_i
|
30
|
+
mongo_path = options[:mongo]
|
31
|
+
|
32
|
+
if profile.nil?
|
33
|
+
exit_now! "Must specify AWS profile"
|
34
|
+
end
|
35
|
+
|
36
|
+
if bucket_name.nil?
|
37
|
+
exit_now! "Must specify AWS bucket name"
|
38
|
+
end
|
39
|
+
|
40
|
+
if max_backups.nil? or max_backups == 0
|
41
|
+
max_backups = 20
|
42
|
+
puts "Max backups is #{max_backups}"
|
43
|
+
end
|
44
|
+
|
45
|
+
if mongo_path.nil?
|
46
|
+
exit_now! "Must specify a database to backup!"
|
47
|
+
end
|
48
|
+
|
49
|
+
mongo_uri = Mongo::URI.new(mongo_path)
|
50
|
+
database = mongo_uri.database
|
51
|
+
user = mongo_uri.credentials[:user]
|
52
|
+
password = mongo_uri.credentials[:password]
|
53
|
+
mongo_server = mongo_uri.servers[0]
|
54
|
+
|
55
|
+
mongodump_tool = find_tool('mongodump', ['/usr/bin', '/usr/local/bin'])
|
56
|
+
aws_tool = find_tool('aws', ['/usr/bin', '/usr/local/bin'])
|
57
|
+
scutil_tool = find_tool('scutil', ['/usr/sbin'])
|
58
|
+
tar_tool = find_tool('tar', ['/usr/bin'])
|
59
|
+
|
60
|
+
Dir.mktmpdir {|dump_dir_name|
|
61
|
+
local_host_name = `#{scutil_tool} --get LocalHostName`.strip
|
62
|
+
|
63
|
+
puts "Backing up mongodb://#{mongo_server}/#{database} from #{local_host_name}"
|
64
|
+
|
65
|
+
`#{mongodump_tool} -h #{mongo_server} -u #{user} -p #{password} -d #{database} -o #{dump_dir_name}`
|
66
|
+
|
67
|
+
if $? != 0
|
68
|
+
raise "Unable to create dump of mongodb://#{mongo_server}/#{database}"
|
69
|
+
end
|
70
|
+
|
71
|
+
date_time = DateTime.now.strftime("%Y%m%d-%H%M%SZ")
|
72
|
+
|
73
|
+
backup_filename = "#{local_host_name}-#{database}-#{date_time}.tar.gz"
|
74
|
+
|
75
|
+
`cd #{dump_dir_name}; #{tar_tool} -czvf #{backup_filename} #{database}/*`
|
76
|
+
|
77
|
+
if $? != 0
|
78
|
+
raise "Unable to create tar zip file '#{backup_filename}'"
|
79
|
+
end
|
80
|
+
|
81
|
+
`cd #{dump_dir_name}; #{aws_tool} s3 cp #{backup_filename} s3://#{bucket_name}/ --profile #{profile}`
|
82
|
+
|
83
|
+
if $? != 0
|
84
|
+
raise "Unable to upload '#{backup_filename}' to s3://#{bucket_name}/"
|
85
|
+
end
|
86
|
+
|
87
|
+
# Reduce backups to desired maximum
|
88
|
+
backup_filenames = `#{aws_tool} s3 ls s3://#{bucket_name} --profile #{profile}`.split('\n')
|
89
|
+
|
90
|
+
if $? != 0
|
91
|
+
raise "Unable to get list of existing backups from s3://#{bucket_name}"
|
92
|
+
end
|
93
|
+
|
94
|
+
# backup_filenames = %w(
|
95
|
+
# 'host-database-20160624-002055Z.tar.gz',
|
96
|
+
# 'host-database-20160620-002055Z.tar.gz',
|
97
|
+
# 'host-database-20160621-002055Z.tar.gz',
|
98
|
+
# 'host-database-20160708-002055Z.tar.gz',
|
99
|
+
# 'host-database-20160601-002055Z.tar.gz.save',
|
100
|
+
# )
|
101
|
+
backup_filenames.sort!
|
102
|
+
backup_filenames.delete_if { |f| f.match(/save/) }
|
103
|
+
num_backups_to_delete = backup_filenames.count - max_backups
|
104
|
+
|
105
|
+
if num_backups_to_delete > 0
|
106
|
+
(0...num_backups_to_delete).each { |i|
|
107
|
+
`#{aws_tool} s3 rm s3://#{bucket_name}/#{backup_filenames[i]} --profile #{profile}`
|
108
|
+
|
109
|
+
if $? != 0
|
110
|
+
puts "WARNING: Unable to delete s3://#{bucket_name}/#{backup_filenames[i]}"
|
111
|
+
end
|
112
|
+
}
|
113
|
+
end
|
114
|
+
}
|
115
|
+
|
116
|
+
puts "Backup completed successfully"
|
117
|
+
end
|
118
|
+
|
119
|
+
description 'mongo-backup - Perform backup for a MongoDB database'
|
120
|
+
version AppTools::VERSION
|
121
|
+
|
122
|
+
on("-p", "--profile PROFILE", "AWS profile")
|
123
|
+
on("-b", "--bucket BUCKET_NAME", "AWS bucket")
|
124
|
+
on("-n", "--max MAX_BACKUPS", "Maximum number of backups to keep")
|
125
|
+
on("-m", "--mongo MONGO_URI", "Full URI of MongoDB to backup")
|
126
|
+
|
127
|
+
use_log_level_option :toggle_debug_on_signal => 'USR1'
|
128
|
+
|
129
|
+
go!
|
130
|
+
end
|
131
|
+
end
|
data/lib/app_tools/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: app-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Lyon-Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '1.7'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: mongo
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '2.3'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '2.3'
|
125
139
|
description: |
|
126
140
|
Generate IPA files with correct Swift and symbol files for uploading to iTunesConnect.
|
127
141
|
Resign IPA files with correct certificate and provisioning profiles for distribution. Upload IPA files to iTunesConnect.
|
@@ -131,6 +145,7 @@ executables:
|
|
131
145
|
- app-tools
|
132
146
|
- gencov
|
133
147
|
- kcpass
|
148
|
+
- mongo-backup
|
134
149
|
- resignipa
|
135
150
|
- setsimkbd
|
136
151
|
- syncpp
|
@@ -142,6 +157,7 @@ files:
|
|
142
157
|
- bin/app-tools
|
143
158
|
- bin/gencov
|
144
159
|
- bin/kcpass
|
160
|
+
- bin/mongo-backup
|
145
161
|
- bin/resignipa
|
146
162
|
- bin/setsimkbd
|
147
163
|
- bin/syncpp
|