odania_ops 0.0.5 → 0.0.6
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/Gemfile.lock +14 -3
- data/lib/odania_ops/cli/backup.rb +52 -0
- data/lib/odania_ops/cli/docker.rb +4 -3
- data/lib/odania_ops/cli/node.rb +20 -0
- data/lib/odania_ops/helper/backup.rb +10 -0
- data/lib/odania_ops/helper/config.rb +6 -2
- data/lib/odania_ops/helper/docker.rb +5 -5
- data/lib/odania_ops/implementations/backup/mongodb.rb +9 -0
- data/lib/odania_ops/implementations/backup/mysql.rb +24 -0
- data/lib/odania_ops/implementations/backup/postgres.rb +9 -0
- data/lib/odania_ops/implementations/backup/rsync.rb +9 -0
- data/lib/odania_ops/version.rb +1 -1
- data/lib/odania_ops.rb +20 -0
- data/odania_ops.gemspec +2 -0
- data/templates/backup/mysql.rb.erb +24 -0
- metadata +39 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27bedf19aac7aa4c2167f33d7b57d03559503203
|
4
|
+
data.tar.gz: 5c8fddfd1d0e66be797cad0e2fc79b00c66c20c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f26ec148dd4a29a41041dfc3da16a87c43f4b8e0a9114fd245295e92d9ae82a99c3cbc4d55752a83b42bb6f44ae0edf331170c29b429684278083193c19391d6
|
7
|
+
data.tar.gz: 424639eb2f838cb2c486ae5d602d88278e22e0c000483b337a19ecabd497e453d8efc93638ee035a621489e95bfd4554129e875e1d1cc5b2667ab5b070a413b1
|
data/Gemfile.lock
CHANGED
@@ -1,34 +1,45 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
odania_ops (0.0.
|
4
|
+
odania_ops (0.0.6)
|
5
5
|
activesupport
|
6
6
|
deep_merge
|
7
7
|
docker-api
|
8
|
+
erubis
|
8
9
|
httparty
|
10
|
+
sshkit
|
9
11
|
thor
|
10
12
|
|
11
13
|
GEM
|
12
14
|
remote: https://rubygems.org/
|
13
15
|
specs:
|
14
|
-
activesupport (4.2.5)
|
16
|
+
activesupport (4.2.5.1)
|
15
17
|
i18n (~> 0.7)
|
16
18
|
json (~> 1.7, >= 1.7.7)
|
17
19
|
minitest (~> 5.1)
|
18
20
|
thread_safe (~> 0.3, >= 0.3.4)
|
19
21
|
tzinfo (~> 1.1)
|
22
|
+
colorize (0.7.7)
|
20
23
|
deep_merge (1.0.1)
|
21
24
|
docker-api (1.24.1)
|
22
25
|
excon (>= 0.38.0)
|
23
26
|
json
|
27
|
+
erubis (2.7.0)
|
24
28
|
excon (0.45.4)
|
25
29
|
httparty (0.13.7)
|
26
30
|
json (~> 1.8)
|
27
31
|
multi_xml (>= 0.5.2)
|
28
32
|
i18n (0.7.0)
|
29
33
|
json (1.8.3)
|
30
|
-
minitest (5.8.
|
34
|
+
minitest (5.8.4)
|
31
35
|
multi_xml (0.5.5)
|
36
|
+
net-scp (1.2.1)
|
37
|
+
net-ssh (>= 2.6.5)
|
38
|
+
net-ssh (3.0.2)
|
39
|
+
sshkit (1.7.1)
|
40
|
+
colorize (>= 0.7.0)
|
41
|
+
net-scp (>= 1.1.2)
|
42
|
+
net-ssh (>= 2.8.0)
|
32
43
|
thor (0.19.1)
|
33
44
|
thread_safe (0.3.5)
|
34
45
|
tzinfo (1.2.2)
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module OdaniaOps
|
2
|
+
module Cli
|
3
|
+
class Backup < Thor
|
4
|
+
desc 'execute <options>', 'Executes a backup'
|
5
|
+
option :type, :type => :string, :required => true
|
6
|
+
option :host, :type => :string, :required => true
|
7
|
+
option :host_user, :type => :string, :required => true
|
8
|
+
option :target_host, :type => :string, :required => true
|
9
|
+
option :target_type, :type => :string, :required => true
|
10
|
+
option :target_user, :type => :string, :required => true
|
11
|
+
option :target_password, :type => :string, :required => true
|
12
|
+
option :jumpbox, :type => :string
|
13
|
+
|
14
|
+
def execute(opts=nil)
|
15
|
+
@type = options[:type]
|
16
|
+
$logger.info "Starting backup [#{@type}] #{options[:host]} -> [#{options[:target_type]}] #{options[:target_host]} (Jumpbox: #{options[:jumpbox]})"
|
17
|
+
opts = opts.nil? ? {} : JSON.parse(opts)
|
18
|
+
|
19
|
+
# Detect implementation
|
20
|
+
backup_script_file = "/tmp/#{Time.now.to_i}_backup.rb"
|
21
|
+
clazz = "OdaniaOps::Implementations::Backup::#{@type}".constantize.new options[:host], opts
|
22
|
+
clazz.write backup_script_file
|
23
|
+
|
24
|
+
set_jump_host(options[:jumpbox]) unless options[:jumpbox].nil?
|
25
|
+
|
26
|
+
server_host = options[:host_user].nil? ? options[:host] : "#{options[:host_user]}@#{options[:host]}"
|
27
|
+
on server_host, in: :sequence do |host|
|
28
|
+
within '/tmp' do
|
29
|
+
server_backup_file = "/tmp/#{@type}_backup.rb"
|
30
|
+
upload! backup_script_file, server_backup_file
|
31
|
+
result = capture "sudo #{server_backup_file}"
|
32
|
+
$logger.info result
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
$logger.info "Finished backup [#{@type}] #{options[:host]} -> [#{options[:target_type]}] #{options[:target_host]} (Jumpbox: #{options[:jumpbox]})"
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def set_jump_host(host)
|
42
|
+
SSHKit::Backend::Netssh.configure do |ssh|
|
43
|
+
ssh.ssh_options = {
|
44
|
+
forward_agent: true,
|
45
|
+
auth_methods: %w(publickey),
|
46
|
+
proxy: Net::SSH::Proxy::Command.new("ssh #{host} -W %h:%p")
|
47
|
+
}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -18,10 +18,11 @@ module OdaniaOps
|
|
18
18
|
|
19
19
|
$logger.info "Tagging #{build_tag} as latest"
|
20
20
|
OdaniaOps::Helper::Docker.remote_tag "#{image_name}:#{build_tag}"
|
21
|
-
OdaniaOps::Helper::Docker.remote_tag "#{image_name}:#{build_tag}", "#{image_name}:latest"
|
21
|
+
OdaniaOps::Helper::Docker.remote_tag "#{image_name}:#{build_tag}", "#{image_name}:latest"
|
22
22
|
|
23
23
|
$logger.info "Pushing #{build_tag}"
|
24
|
-
OdaniaOps::Helper::Docker.push image_name
|
24
|
+
OdaniaOps::Helper::Docker.push image_name, build_tag
|
25
|
+
OdaniaOps::Helper::Docker.push image_name, 'latest'
|
25
26
|
end
|
26
27
|
|
27
28
|
desc 'base_image_check <folder>', 'Searches for all Dockerfiles under <folder> and looks for the base image'
|
@@ -97,4 +98,4 @@ module OdaniaOps
|
|
97
98
|
end
|
98
99
|
end
|
99
100
|
end
|
100
|
-
end
|
101
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module OdaniaOps
|
2
|
+
module Cli
|
3
|
+
class Node < Thor
|
4
|
+
desc 'exec <command>', 'Run command on nodes'
|
5
|
+
option :hosts, :type => :string, :aliases => [:h], :required => true
|
6
|
+
option :process, :type => :string, :default => :sequence, :banner => 'Process in sequence or parallel'
|
7
|
+
def exec(*args)
|
8
|
+
command = args.join(' ')
|
9
|
+
on options[:hosts].split(','), in: options[:process].to_sym do |host|
|
10
|
+
within '/tmp' do
|
11
|
+
result = capture command
|
12
|
+
result.split("\n").each do |line|
|
13
|
+
info "#{host}: #{line}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -10,6 +10,9 @@ module OdaniaOps
|
|
10
10
|
config_file = retrieve_config_folder folder
|
11
11
|
end
|
12
12
|
|
13
|
+
$config = {}
|
14
|
+
return unless File.exists? config_file
|
15
|
+
|
13
16
|
$logger.debug "Loading config file #{config_file}"
|
14
17
|
$config = YAML.load_file(config_file)
|
15
18
|
$logger.debug $config.inspect
|
@@ -29,9 +32,10 @@ module OdaniaOps
|
|
29
32
|
folder = next_folder
|
30
33
|
end
|
31
34
|
|
32
|
-
|
35
|
+
$logger.error "No configuration found! Looking in #{start_folder} and above."
|
36
|
+
''
|
33
37
|
end
|
34
38
|
end
|
35
39
|
end
|
36
40
|
end
|
37
|
-
end
|
41
|
+
end
|
@@ -8,14 +8,14 @@ module OdaniaOps
|
|
8
8
|
data['tags']
|
9
9
|
end
|
10
10
|
|
11
|
-
def remote_tag(image_name_and_tag, target_image_name_and_tag=nil
|
11
|
+
def remote_tag(image_name_and_tag, target_image_name_and_tag=nil)
|
12
12
|
target_image_name_and_tag = image_name_and_tag if target_image_name_and_tag.nil?
|
13
|
-
|
14
|
-
OdaniaOps::Helper::Shell.execute("docker tag #{opts} #{image_name_and_tag} #{registry_name}/#{target_image_name_and_tag}")
|
13
|
+
OdaniaOps::Helper::Shell.execute("docker tag #{image_name_and_tag} #{registry_name}/#{target_image_name_and_tag}")
|
15
14
|
end
|
16
15
|
|
17
|
-
def push(image_name)
|
18
|
-
|
16
|
+
def push(image_name, tag=nil)
|
17
|
+
tag = ":#{tag}" unless tag.nil? or tag.empty?
|
18
|
+
OdaniaOps::Helper::Shell.execute("docker push #{registry_name}/#{image_name}#{tag}")
|
19
19
|
end
|
20
20
|
|
21
21
|
def login
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module OdaniaOps
|
2
|
+
module Implementations
|
3
|
+
module Backup
|
4
|
+
class Mysql
|
5
|
+
attr_accessor :template, :host, :opts
|
6
|
+
|
7
|
+
def initialize(host, opts)
|
8
|
+
self.host = host
|
9
|
+
self.opts = opts
|
10
|
+
self.template = File.new(File.join(BASE_DIR, 'templates', 'backup', 'mysql.rb.erb')).read
|
11
|
+
end
|
12
|
+
|
13
|
+
def render
|
14
|
+
Erubis::Eruby.new(self.template).result(binding)
|
15
|
+
end
|
16
|
+
|
17
|
+
def write(target_file)
|
18
|
+
File.write(target_file, self.render)
|
19
|
+
`chmod +x #{target_file}`
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/odania_ops/version.rb
CHANGED
data/lib/odania_ops.rb
CHANGED
@@ -4,14 +4,28 @@ require 'httparty'
|
|
4
4
|
require 'logger'
|
5
5
|
require 'yaml'
|
6
6
|
require 'deep_merge/rails_compat'
|
7
|
+
require 'erubis'
|
7
8
|
require 'active_support/all'
|
8
9
|
require 'docker-api'
|
9
10
|
|
11
|
+
require 'net/ssh/proxy/command'
|
12
|
+
require 'sshkit'
|
13
|
+
require 'sshkit/dsl'
|
14
|
+
|
15
|
+
BASE_DIR = File.absolute_path File.join(File.dirname(__FILE__), '..') unless defined? BASE_DIR
|
16
|
+
|
17
|
+
require_relative 'odania_ops/cli/backup'
|
10
18
|
require_relative 'odania_ops/cli/config'
|
11
19
|
require_relative 'odania_ops/cli/docker'
|
20
|
+
require_relative 'odania_ops/cli/node'
|
21
|
+
require_relative 'odania_ops/helper/backup'
|
12
22
|
require_relative 'odania_ops/helper/config'
|
13
23
|
require_relative 'odania_ops/helper/docker'
|
14
24
|
require_relative 'odania_ops/helper/shell'
|
25
|
+
require_relative 'odania_ops/implementations/backup/mongodb'
|
26
|
+
require_relative 'odania_ops/implementations/backup/mysql'
|
27
|
+
require_relative 'odania_ops/implementations/backup/postgres'
|
28
|
+
require_relative 'odania_ops/implementations/backup/rsync'
|
15
29
|
|
16
30
|
# Setup logger
|
17
31
|
$logger = Logger.new(STDOUT)
|
@@ -31,11 +45,17 @@ module OdaniaOps
|
|
31
45
|
$logger.level = "Logger::#{options['log_level']}".constantize
|
32
46
|
end
|
33
47
|
|
48
|
+
desc 'backup', 'Backup helper'
|
49
|
+
subcommand 'backup', Backup
|
50
|
+
|
34
51
|
desc 'docker', 'Docker helper'
|
35
52
|
subcommand 'docker', Docker
|
36
53
|
|
37
54
|
desc 'config', 'Manage configuration'
|
38
55
|
subcommand 'config', Config
|
56
|
+
|
57
|
+
desc 'node', 'Execute commands on nodes'
|
58
|
+
subcommand 'node', Node
|
39
59
|
end
|
40
60
|
end
|
41
61
|
end
|
data/odania_ops.gemspec
CHANGED
@@ -19,6 +19,8 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.add_dependency 'activesupport'
|
20
20
|
gem.add_dependency 'deep_merge'
|
21
21
|
gem.add_dependency 'docker-api'
|
22
|
+
gem.add_dependency 'erubis'
|
22
23
|
gem.add_dependency 'httparty'
|
23
24
|
gem.add_dependency 'thor'
|
25
|
+
gem.add_dependency 'sshkit'
|
24
26
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
# Config
|
5
|
+
mysql_user = '<%= opts['user'] %>'
|
6
|
+
mysql_pass = '<%= opts['password'] %>'
|
7
|
+
mysql_host = '127.0.0.1'
|
8
|
+
|
9
|
+
# Backup folder
|
10
|
+
backup_dir = '/media/backup/<%= host %>/mysql'
|
11
|
+
|
12
|
+
# Create folder if needed
|
13
|
+
FileUtils.mkdir_p backup_dir unless File.directory? backup_dir
|
14
|
+
|
15
|
+
# Backup MySql
|
16
|
+
result = ` mysql -u #{mysql_user} -p#{mysql_pass} -h #{mysql_host} --silent -N -e 'show databases'`.split("\n")
|
17
|
+
result.each do |db_name|
|
18
|
+
db_name = db_name.strip
|
19
|
+
next if %w(information_schema performance_schema).include? db_name
|
20
|
+
|
21
|
+
filename = "#{backup_dir}/#{db_name}.mysql.sql.gz"
|
22
|
+
puts "Backing up #{db_name} to #{filename}"
|
23
|
+
` mysqldump -u #{mysql_user} -p#{mysql_pass} -h #{mysql_host} -e --opt -c #{db_name} | gzip -c > #{filename}`
|
24
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: odania_ops
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Petersen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: erubis
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: httparty
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +94,20 @@ dependencies:
|
|
80
94
|
- - ">="
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sshkit
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
83
111
|
description: Ops tools for managing servers
|
84
112
|
email:
|
85
113
|
- mike@odania-it.com
|
@@ -98,13 +126,21 @@ files:
|
|
98
126
|
- bin/odania-ops
|
99
127
|
- bin/ops
|
100
128
|
- lib/odania_ops.rb
|
129
|
+
- lib/odania_ops/cli/backup.rb
|
101
130
|
- lib/odania_ops/cli/config.rb
|
102
131
|
- lib/odania_ops/cli/docker.rb
|
132
|
+
- lib/odania_ops/cli/node.rb
|
133
|
+
- lib/odania_ops/helper/backup.rb
|
103
134
|
- lib/odania_ops/helper/config.rb
|
104
135
|
- lib/odania_ops/helper/docker.rb
|
105
136
|
- lib/odania_ops/helper/shell.rb
|
137
|
+
- lib/odania_ops/implementations/backup/mongodb.rb
|
138
|
+
- lib/odania_ops/implementations/backup/mysql.rb
|
139
|
+
- lib/odania_ops/implementations/backup/postgres.rb
|
140
|
+
- lib/odania_ops/implementations/backup/rsync.rb
|
106
141
|
- lib/odania_ops/version.rb
|
107
142
|
- odania_ops.gemspec
|
143
|
+
- templates/backup/mysql.rb.erb
|
108
144
|
homepage: http://www.odania.com/ops-tools
|
109
145
|
licenses:
|
110
146
|
- MIT
|
@@ -125,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
161
|
version: '0'
|
126
162
|
requirements: []
|
127
163
|
rubyforge_project:
|
128
|
-
rubygems_version: 2.
|
164
|
+
rubygems_version: 2.6.7
|
129
165
|
signing_key:
|
130
166
|
specification_version: 4
|
131
167
|
summary: Ops tools for managing servers
|