central_config_backup_job 1.0.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 +7 -0
- data/.gitignore +18 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +28 -0
- data/Rakefile +1 -0
- data/central_config_backup_job.gemspec +23 -0
- data/lib/central_config_backup_job.rb +95 -0
- data/lib/central_config_backup_job/version.rb +3 -0
- data/lib/conf.yml +0 -0
- data/lib/conf_backup.yml +0 -0
- metadata +82 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 53cc3964de971b76d351fafff894e007597011e2
|
4
|
+
data.tar.gz: c4f6920a2ac4f8a3f5db50a2c39bb1a55fba6ac8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0f200a66d1ab95ff437a716417cf4cfb1105ce4a941eaf332b189be8e5f5c2033e9fac127a95480310e4b9eda0a9963147de8f44e5f28f8bbe1351aeb775e2b3
|
7
|
+
data.tar.gz: c13eb1bea4040e5e4334ce48797d53726ee7c84e455fd7d1154a71e70cb4763641a7b003ba6327a97ea2942b6564e235d745ca2b99638bb57976bb0c0f992e70
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Roy Libman
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# CentralConfigBackupJob
|
2
|
+
|
3
|
+
This is a simple backup cron script to backup etcd contents into an Azure blob storage every X minutes.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
gem 'central_config_backup_job'
|
8
|
+
|
9
|
+
And then execute:
|
10
|
+
|
11
|
+
$ bundle
|
12
|
+
|
13
|
+
Or install it yourself as:
|
14
|
+
|
15
|
+
$ gem install central_config_backup_job
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
In "lib\conf.yml" update Etcd's IP/Port and also Azure's storage accounts name and key.
|
20
|
+
Run lib\central_config_backup_job.rb" as a cron every 5 minutes (or as decided otherwise) and that's it.
|
21
|
+
|
22
|
+
## Contributing
|
23
|
+
|
24
|
+
1. Fork it ( http://github.com/<my-github-username>/central_config_backup_job/fork )
|
25
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
26
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
27
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
28
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'central_config_backup_job/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "central_config_backup_job"
|
8
|
+
spec.version = CentralConfigBackupJob::VERSION
|
9
|
+
spec.authors = ["Roy Libman"]
|
10
|
+
spec.email = ["roeylibman@gmail.com"]
|
11
|
+
spec.summary = "Add support for authentication"
|
12
|
+
spec.description = "Add support for authentication"
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'date'
|
3
|
+
require 'json'
|
4
|
+
require 'net/http'
|
5
|
+
require 'azure'
|
6
|
+
require 'yaml'
|
7
|
+
require 'logstash-logger'
|
8
|
+
require 'socket'
|
9
|
+
|
10
|
+
module CentralConfigBackupJob
|
11
|
+
begin
|
12
|
+
file_logger = LogStashLogger.new(type: :file, path: '/var/log/central_config_backup/production.log', sync: true)
|
13
|
+
|
14
|
+
#General params
|
15
|
+
puts File.expand_path('../conf.yml', __FILE__)
|
16
|
+
conf_file = File.expand_path('../conf.yml', __FILE__)
|
17
|
+
conf = YAML.load_file(conf_file)
|
18
|
+
|
19
|
+
current_datetime = Time.now.utc
|
20
|
+
current_datetime_s = current_datetime.strftime('%Y-%m-%dT%H:%M:%S.%L')
|
21
|
+
current_date_s = current_datetime.strftime('%Y-%m-%d')
|
22
|
+
file_name = "#{Socket.gethostname.downcase.encode('utf-8')}-config-#{current_datetime_s}.json"
|
23
|
+
container_name = 'ccmbackupblob'
|
24
|
+
table_name = 'ccmbackuptable'
|
25
|
+
|
26
|
+
|
27
|
+
#Config azure blob and table
|
28
|
+
puts conf[:azure][:storage_account_name]
|
29
|
+
#puts conf[:azure][:storage_access_key]
|
30
|
+
|
31
|
+
Azure.config.storage_account_name = conf[:azure][:storage_account_name]
|
32
|
+
Azure.config.storage_access_key = conf[:azure][:storage_access_key]
|
33
|
+
|
34
|
+
azure_blob_service = Azure::Blob::BlobService.new
|
35
|
+
begin
|
36
|
+
container = azure_blob_service.get_container_acl(container_name)
|
37
|
+
container = container[0]
|
38
|
+
rescue
|
39
|
+
begin
|
40
|
+
container = azure_blob_service.create_container(container_name)
|
41
|
+
rescue
|
42
|
+
puts $!
|
43
|
+
file_logger.error '{"message": "Backup Failed - Problem initializing azure blob service "}'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
azure_table_service = Azure::Table::TableService.new
|
48
|
+
|
49
|
+
begin
|
50
|
+
azure_table_service.get_table(table_name)
|
51
|
+
rescue
|
52
|
+
begin
|
53
|
+
azure_table_service.create_table(table_name)
|
54
|
+
rescue
|
55
|
+
puts $!
|
56
|
+
file_logger.error '{"message": "Backup Failed - Problem initializing azure table service "}'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
recovery_status = URI.parse("http://#{conf[:etcd][:host]}:#{conf[:etcd][:port]}/v2/keys/keys/CentralConfigStatus")
|
61
|
+
http = Net::HTTP.new(recovery_status.host, recovery_status.port)
|
62
|
+
request = Net::HTTP::Get.new(recovery_status.request_uri)
|
63
|
+
request.basic_auth("#{conf[:etcd][:user]}", "#{conf[:etcd][:pass]}")
|
64
|
+
recovery_status = http.request(request)
|
65
|
+
|
66
|
+
recovery_status = JSON.parse(recovery_status.body)
|
67
|
+
if recovery_status['node'].nil? || recovery_status['node']['value'] != "Normal"
|
68
|
+
file_logger.error '{"message": "Backup Failed - Etcd status is currently in recovery "}'
|
69
|
+
throw 'Etcd status is currently in recovery'
|
70
|
+
end
|
71
|
+
|
72
|
+
#Etcd call
|
73
|
+
url = URI.parse("http://#{conf[:etcd][:host]}:#{conf[:etcd][:port]}/v2/keys/?recursive=true")
|
74
|
+
http = Net::HTTP.new(url.host, url.port)
|
75
|
+
request = Net::HTTP::Get.new(url.request_uri)
|
76
|
+
request.basic_auth("#{conf[:etcd][:user]}", "#{conf[:etcd][:pass]}")
|
77
|
+
res = http.request(request)
|
78
|
+
res.is_a?(Net::HTTPSuccess) ? (puts res.inspect) : (puts res.inspect;Exit 1)
|
79
|
+
config_copy_json = JSON.parse(res.body).to_json
|
80
|
+
|
81
|
+
#Insert config file into blob storage
|
82
|
+
azure_blob_service.create_block_blob(container.name, file_name, config_copy_json)
|
83
|
+
|
84
|
+
#Insert config metadata into table storage
|
85
|
+
entity = { "content" => current_datetime_s, PartitionKey: current_date_s, RowKey: file_name }
|
86
|
+
azure_table_service.insert_entity(table_name, entity)
|
87
|
+
|
88
|
+
file_logger.info "Backup was successfull for #{file_name}"
|
89
|
+
|
90
|
+
rescue => e
|
91
|
+
file_logger.error "{\"message\": \"Backup Failed. #{e}\"}"
|
92
|
+
throw "Backup Failed. #{e}"
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
data/lib/conf.yml
ADDED
File without changes
|
data/lib/conf_backup.yml
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: central_config_backup_job
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Roy Libman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-08-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Add support for authentication
|
42
|
+
email:
|
43
|
+
- roeylibman@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- central_config_backup_job.gemspec
|
54
|
+
- lib/central_config_backup_job.rb
|
55
|
+
- lib/central_config_backup_job/version.rb
|
56
|
+
- lib/conf.yml
|
57
|
+
- lib/conf_backup.yml
|
58
|
+
homepage: ''
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.5.1
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: Add support for authentication
|
82
|
+
test_files: []
|