mikrotik-backup 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b93e44f47ccf7b94c5299f3d31fac447e7baf9b0
4
- data.tar.gz: dc642aa5811d8f1dcded8f641edb3ca1e2029312
3
+ metadata.gz: 96593143d646861c03ba188f955a05c94858800c
4
+ data.tar.gz: 546c4eb084bde83820b1c06ca6bb0f8eae5a9287
5
5
  SHA512:
6
- metadata.gz: e873503d5f54fae05ce646bb5a87e37039e0943e021150933edd1bda5ee82cbb0da9318c241c792863b0f4d73a351b1cdd1cf672573465d492e4a4a58ad044ee
7
- data.tar.gz: fc331b9138099b15c6043e8a3d929dd73047cffcd26ea9caf277c0cd76a7afaeb29db355494a58723e720d50d51a504931036b71fc5ab3e4843418fc241d7668
6
+ metadata.gz: 086ef209caca808523f1fc4209cd13193ca68b1a21d517690ccaacf5919486736afd85c64fa0c63aefeb702263d5ad9cb4bee97256bdf706e86967cea6deb3dc
7
+ data.tar.gz: 68e3b92844951dcfdeb6059d234274d4c28f878453469016ed3261e4372d7d284671fb8ccabe07073e2cf8637b7723a15143f78e1db5b47fb07e3bc493313c99
data/.gitignore CHANGED
@@ -1,16 +1,16 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- *.bundle
11
- *.so
12
- *.o
13
- *.a
14
- mkmf.log
15
- /.idea/
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ /.idea/
16
16
  *.gem
data/Gemfile CHANGED
@@ -1,8 +1,8 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in mikrotik_backup.gemspec
4
- gemspec
5
- # Add Net::SSH GEM
6
- gem 'net-ssh'
7
- # Add Net::SFTP GEM
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mikrotik_backup.gemspec
4
+ gemspec
5
+ # Add Net::SSH GEM
6
+ gem 'net-ssh'
7
+ # Add Net::SFTP GEM
8
8
  gem 'net-sftp'
@@ -1,22 +1,22 @@
1
- Copyright (c) 2015 POS_troi
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.
1
+ Copyright (c) 2015 POS_troi
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 CHANGED
@@ -1,75 +1,79 @@
1
- [![Gem Version](https://badge.fury.io/rb/mikrotik-backup.svg)](http://badge.fury.io/rb/mikrotik-backup)
2
-
3
- # Mikrotik Backup
4
-
5
- Backup MikroTik configuration using SSH and SFTP.
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'mikrotik-backup'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install mikrotik-backup
22
-
23
- ## Usage
24
-
25
- ```ruby
26
-
27
- require 'mikrotik-backup'
28
- #Config
29
- # name - associate host name (and name backup file)
30
- # host - host address
31
- # user - user name
32
- # password - user password
33
- # path - local folder for save backup file. "/var/backup/"
34
- config = [
35
- {name:'Router1', host: '10.10.10.1' , user:'admin' , password:'admin', path:'./'},
36
- {name:'Router2', host: '10.10.10.2' ,user:'admin' ,password:'admin', path: './'}
37
- ]
38
-
39
-
40
- backup = MTik_backup.new(config)
41
- # Logging
42
- backup.logger(Logger::ERROR)
43
- # Start backup and download
44
- backup.backup(true) # <-- "false" - enable only create backup and not download
45
- ```
46
- ### Logging
47
- ```ruby
48
- # Logging only Error, out to console
49
- logger
50
-
51
- # Full log out to console
52
- logger(Logger::DEBUG)
53
-
54
- # Full log out to file
55
- logger(Logger::DEBUG,'backup.log')
56
- ```
57
-
58
- ### Only Download backup (previously created)
59
- ```ruby
60
- config = [
61
- {name:'Router1', host: '10.10.10.1' , user:'admin' , password:'admin', path:'./'},
62
- {name:'Router2', host: '10.10.10.2' ,user:'admin' ,password:'admin', path: './'}
63
- ]
64
-
65
- backup = MTik_backup.new(config)
66
- backup.download
67
- ```
68
-
69
- ## Contributing
70
-
71
- 1. Fork it ( https://github.com/POStroi/ruby_mikrotik_backup/fork )
72
- 2. Create your feature branch (`git checkout -b my-new-feature`)
73
- 3. Commit your changes (`git commit -am 'Add some feature'`)
74
- 4. Push to the branch (`git push origin my-new-feature`)
75
- 5. Create a new Pull Request
1
+ [![Gem Version](https://badge.fury.io/rb/mikrotik-backup.svg)](http://badge.fury.io/rb/mikrotik-backup)
2
+
3
+ # Mikrotik Backup
4
+
5
+ Backup MikroTik configuration using SSH and SFTP.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'mikrotik-backup'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install mikrotik-backup
22
+
23
+ ## Usage
24
+
25
+ ### Backup only
26
+ ```ruby
27
+
28
+ require 'mikrotik-backup'
29
+
30
+ #Time format
31
+ time = Time.now.strftime("%d-%m-%Y")
32
+
33
+ #Config
34
+ # name - associate host name (and name backup file)
35
+ # host - host address
36
+ # user - user name
37
+ # password - user password
38
+ # path - local folder for save backup file. "/var/backup/"
39
+ # format - backup file format, 'binary' or 'script'
40
+ config = [
41
+ {name:"Router1-#{time}", host: '10.10.10.1', user:'admin', password:'admin', path:'./', format:'binary'},
42
+ {name:"Router2-#{time}", host: '10.10.10.2', user:'admin', password:'admin', path:'./', format:'script'}
43
+ ]
44
+
45
+
46
+ backup = MTik_backup.new(config)
47
+ # Start backup
48
+ backup.backup
49
+ ```
50
+
51
+ ### Only Download backup (previously created)
52
+ ```ruby
53
+ backup.download
54
+ ```
55
+
56
+ ### Create backup and download
57
+ ```ruby
58
+ backup.backup_and_download
59
+ ```
60
+
61
+ ### Logging
62
+ ```ruby
63
+ # Logging only Error, out to console
64
+ backup.logger(Logger::ERROR) #<- Default
65
+
66
+ # Full log out to console
67
+ backup.logger(Logger::DEBUG)
68
+
69
+ # Full log out to file
70
+ backup.logger(Logger::DEBUG,'backup.log')
71
+ ```
72
+
73
+ ## Contributing
74
+
75
+ 1. Fork it ( https://github.com/POStroi/ruby_mikrotik_backup/fork )
76
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
77
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
78
+ 4. Push to the branch (`git push origin my-new-feature`)
79
+ 5. Create a new Pull Request
data/Rakefile CHANGED
@@ -1,2 +1,2 @@
1
- require "bundler/gem_tasks"
2
-
1
+ require "bundler/gem_tasks"
2
+
@@ -1,89 +1,108 @@
1
- require "mikrotik-backup/version"
2
- require 'net/ssh'
3
- require 'net/sftp'
4
- # MikroTik backup class
5
- class MTik_backup
6
- # Initialize
7
- def initialize(config)
8
- @config = config
9
- logger
10
- end
11
- # Setting for Ruby Logger
12
- def logger(log_level = Logger::ERROR,log_file = nil)
13
- if log_file.nil?
14
- @log = Logger.new(STDOUT)
15
- else
16
- @log = Logger.new(log_file)
17
- end
18
- @log.level = log_level
19
- @log.formatter = proc { |severity, datetime, progname, msg|
20
- "[#{datetime.strftime("%Y-%m-%d %H:%M:%S")}] #{severity}: #{msg}\n"
21
- }
22
- end
23
-
24
- # Backup and download MTik config
25
- def backup(download=false)
26
- @config.each do |config|
27
- connect_to_host(config[:host],config[:user],config[:password])
28
- backup_config(config[:name])
29
- download_backup(config[:host],config[:user],config[:password],config[:name],config[:path]) if download
30
- end
31
- end
32
- # Only download MTik config
33
- def download
34
- @config.each do |config|
35
- download_backup(config[:host],config[:user],config[:password],config[:name],config[:path])
36
- end
37
- end
38
-
39
- # Private section
40
- private
41
- # Function connect to SSH/SFTP host
42
- def connect_to_host(host,user,password,sftp=false)
43
- begin
44
- if sftp
45
- @log.info("SFTP connect to host #{host}")
46
- @ssh_connect = Net::SFTP.start(host,user,:password=>password)
47
- else
48
- @log.info("SSH connect to host #{host}")
49
- @ssh_connect = Net::SSH.start(host,user,:password=>password)
50
- end
51
- rescue Exception => error
52
- @log.error("#{error}")
53
- exit
54
- end
55
- end
56
- # Backup function, send SSH command
57
- def backup_config(name)
58
- @log.info("Backup MikroTik configuration")
59
- send_command("/export file=#{name}")
60
- @ssh_connect.close
61
- end
62
- # Download backup file from host
63
- def download_backup(host,user,password,name,path)
64
- connect_to_host(host,user,password,true)
65
- local_file = path+name+".rsc"
66
- remote_file = name+".rsc"
67
- download_file(remote_file,local_file)
68
- @ssh_connect.close(@ssh_connect)
69
- end
70
- # Send command to host (SSH)
71
- def send_command(command)
72
- begin
73
- @ssh_connect.exec!(command)
74
- rescue Exception => error
75
- @log.error("#{error}")
76
- end
77
- end
78
- # Download file from host
79
- def download_file(remote_file, local_file)
80
- begin
81
- @log.info("Download file #{remote_file} to #{local_file}")
82
- @ssh_connect.download!(remote_file,local_file)
83
- rescue Exception => error
84
- @log.error("#{error}")
85
- exit
86
- end
87
- end
88
- end
89
-
1
+ require "mikrotik-backup/version"
2
+ require 'net/ssh'
3
+ require 'net/sftp'
4
+ # MikroTik backup class
5
+ # noinspection RubyArgCount
6
+ class MTik_backup
7
+ # Initialize
8
+ def initialize(config)
9
+ @config = config
10
+ logger
11
+ end
12
+ # Setting for Ruby Logger
13
+ def logger(log_level = Logger::ERROR,log_file = nil)
14
+ if log_file.nil?
15
+ @log = Logger.new(STDOUT)
16
+ else
17
+ @log = Logger.new(log_file)
18
+ end
19
+ @log.level = log_level
20
+ @log.formatter = proc { |severity, datetime, progname, msg|
21
+ "[#{datetime.strftime("%Y-%m-%d %H:%M:%S")}] #{severity}: #{msg}\n"
22
+ }
23
+ end
24
+ # Backup MTik config
25
+ def backup
26
+ @config.each do |config|
27
+ connect_to_host(config[:host],config[:user],config[:password])
28
+ backup_config(config[:name],config[:format])
29
+ end
30
+ return true
31
+ end
32
+ # Only download MTik config
33
+ def download
34
+ @config.each do |config|
35
+ download_backup(config[:host],config[:user],config[:password],config[:name],config[:path],config[:format])
36
+ end
37
+ return true
38
+ end
39
+ # Backup and download MTik config
40
+ def backup_and_download
41
+ @config.each do |config|
42
+ connect_to_host(config[:host],config[:user],config[:password])
43
+ backup_config(config[:name],config[:format])
44
+ download_backup(config[:host],config[:user],config[:password],config[:name],config[:path],config[:format])
45
+ end
46
+ return true
47
+ end
48
+
49
+ # Private section
50
+ private
51
+ # Function connect to SSH/SFTP host
52
+ def connect_to_host(host,user,password,sftp=false)
53
+ begin
54
+ if sftp
55
+ @log.info("SFTP connect to host #{host}")
56
+ @ssh_connect = Net::SFTP.start(host,user,:password=>password)
57
+ else
58
+ @log.info("SSH connect to host #{host}")
59
+ @ssh_connect = Net::SSH.start(host,user,:password=>password)
60
+ end
61
+ rescue Exception => error
62
+ @log.error("#{error}")
63
+ exit
64
+ end
65
+ end
66
+ # Backup function, send SSH command
67
+ def backup_config(name,format='binary')
68
+ @log.info("Backup MikroTik configuration")
69
+ if format == 'binary'
70
+ send_command("/system backup save name=#{name}")
71
+ elsif format == 'script'
72
+ send_command("/export file=#{name}")
73
+ end
74
+ @ssh_connect.close
75
+ end
76
+ # Download backup file from host
77
+ def download_backup(host,user,password,name,path,format)
78
+ connect_to_host(host,user,password,true)
79
+ if format == 'binary'
80
+ local_file = path+name+".backup"
81
+ remote_file = name+".backup"
82
+ elsif format== 'script'
83
+ local_file = path+name+".rsc"
84
+ remote_file = name+".rsc"
85
+ end
86
+ download_file(remote_file,local_file)
87
+ @ssh_connect.close(@ssh_connect)
88
+ end
89
+ # Send command to host (SSH)
90
+ def send_command(command)
91
+ begin
92
+ @ssh_connect.exec!(command)
93
+ rescue Exception => error
94
+ @log.error("#{error}")
95
+ end
96
+ end
97
+ # Download file from host
98
+ def download_file(remote_file, local_file)
99
+ begin
100
+ @log.info("Download file #{remote_file} to #{local_file}")
101
+ @ssh_connect.download!(remote_file,local_file)
102
+ rescue Exception => error
103
+ @log.error("#{error}")
104
+ exit
105
+ end
106
+ end
107
+ end
108
+
@@ -1,3 +1,3 @@
1
- module MikrotikBackup
2
- VERSION = "0.0.3"
3
- end
1
+ module MikrotikBackup
2
+ VERSION = "0.0.4"
3
+ end
@@ -1,25 +1,25 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'mikrotik-backup/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "mikrotik-backup"
8
- spec.version = MikrotikBackup::VERSION
9
- spec.authors = ["POS_troi"]
10
- spec.email = ["root@sysalex.com"]
11
- spec.summary = %q{Backup MikroTik configuration using SSH and SFTP.}
12
- spec.description = %q{Backup MikroTik configuration using SSH and SFTP.}
13
- spec.homepage = "https://sysalex.com"
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.7"
22
- spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_dependency "net-ssh", "~> 2.9"
24
- spec.add_dependency "net-sftp", "~> 2.1"
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mikrotik-backup/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mikrotik-backup"
8
+ spec.version = MikrotikBackup::VERSION
9
+ spec.authors = ["POS_troi"]
10
+ spec.email = ["root@sysalex.com"]
11
+ spec.summary = %q{Backup MikroTik configuration using SSH and SFTP.}
12
+ spec.description = %q{Backup MikroTik configuration using SSH and SFTP.}
13
+ spec.homepage = "https://sysalex.com"
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.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_dependency "net-ssh", "~> 2.9"
24
+ spec.add_dependency "net-sftp", "~> 2.1"
25
25
  end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mikrotik-backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - POS_troi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-10 00:00:00.000000000 Z
11
+ date: 2015-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.7'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: net-ssh
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: '2.9'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.9'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: net-sftp
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: '2.1'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2.1'
69
69
  description: Backup MikroTik configuration using SSH and SFTP.
@@ -73,7 +73,7 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
- - ".gitignore"
76
+ - .gitignore
77
77
  - Gemfile
78
78
  - LICENSE.txt
79
79
  - README.md
@@ -91,17 +91,17 @@ require_paths:
91
91
  - lib
92
92
  required_ruby_version: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  requirements:
99
- - - ">="
99
+ - - '>='
100
100
  - !ruby/object:Gem::Version
101
101
  version: '0'
102
102
  requirements: []
103
103
  rubyforge_project:
104
- rubygems_version: 2.4.5
104
+ rubygems_version: 2.0.14
105
105
  signing_key:
106
106
  specification_version: 4
107
107
  summary: Backup MikroTik configuration using SSH and SFTP.