mite-backup 0.1.0 → 0.3.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 +2 -0
- data/README.md +5 -6
- data/bin/mite-backup +15 -6
- data/lib/mite-backup.rb +33 -12
- data/lib/mite-backup/version.rb +1 -1
- data/mite-backup.gemspec +0 -1
- metadata +15 -33
- data/.rvmrc +0 -1
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a117790317b4837a4f8e2cd95226457a36b089494e74a39ae443fa0fc6f03cf3
|
4
|
+
data.tar.gz: 278c4c22b657de5c21bbfab81c059d6d5beae1a9c2e5c15972142511456ff7c9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a0ed983b6beb773b1e5bf1cf95fee71464c2b26a1248f44078b49fc43b8990b786ced405a5e9bfa884a19a10d78e453b5e1d7d946259738767a510e79d3c585a
|
7
|
+
data.tar.gz: dafd207a7c3c4e29df78c69d74bc76c675bb23dd4c93b456b1bb7ad692ac2f15317d1e391e89fa15e75aa30e825bc19ae07c45a42bc270214400562969ff32e6
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -5,22 +5,21 @@ Simple command-line tool for downloading a backup in XML of your [mite](http://m
|
|
5
5
|
## Installation
|
6
6
|
|
7
7
|
gem install mite-backup
|
8
|
-
|
8
|
+
|
9
9
|
## Usage
|
10
10
|
|
11
|
-
mite-backup -a [ACCOUNT] -e [EMAIL] -p [PASSWORD]
|
12
|
-
|
11
|
+
mite-backup -a [ACCOUNT-SUBDOMAIN] -e [EMAIL] -p [PASSWORD]
|
12
|
+
|
13
13
|
This will output the backup file in XML to the prompt. You propably want to pipe it into an file:
|
14
14
|
|
15
|
-
mite-backup -a [ACCOUNT] -e [EMAIL] -p [PASSWORD] > my_backup_file.xml
|
15
|
+
mite-backup -a [ACCOUNT-SUBDOMAIN] -e [EMAIL] -p [PASSWORD] > my_backup_file.xml
|
16
16
|
|
17
17
|
For further instructions run
|
18
18
|
|
19
19
|
mite-backup -h
|
20
|
-
|
21
20
|
|
22
21
|
## BlaBla
|
23
22
|
|
24
|
-
Copyright (c) 2011 [Yolk](http://yo.lk/) Sebastian Munz & Julia Soergel GbR
|
23
|
+
Copyright (c) 2011-2012 [Yolk](http://yo.lk/) Sebastian Munz & Julia Soergel GbR
|
25
24
|
|
26
25
|
Beyond that, the implementation is licensed under the MIT License.
|
data/bin/mite-backup
CHANGED
@@ -5,7 +5,9 @@ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
|
|
5
5
|
require 'mite-backup'
|
6
6
|
require 'optparse'
|
7
7
|
|
8
|
-
@options = {
|
8
|
+
@options = {
|
9
|
+
"wait_for" => MiteBackup::DEFAULT_WAIT_FOR
|
10
|
+
}
|
9
11
|
|
10
12
|
parser = OptionParser.new do |opts|
|
11
13
|
opts.banner = "Usage: mite-backup COMMAND [options]"
|
@@ -13,18 +15,25 @@ parser = OptionParser.new do |opts|
|
|
13
15
|
opts.separator ""
|
14
16
|
opts.separator "Options:"
|
15
17
|
|
16
|
-
opts.on("-a", "--account
|
18
|
+
opts.on("-a", "--account ACCOUNT-SUBDOMAIN", "your mite account subdomain (without .mite.yo.lk)") do |account|
|
17
19
|
@options["account"] = account
|
18
20
|
end
|
19
21
|
|
20
|
-
opts.on("-e", "--email
|
22
|
+
opts.on("-e", "--email EMAIL", "mite.user email") do |email|
|
21
23
|
@options["email"] = email
|
22
24
|
end
|
23
25
|
|
24
|
-
opts.on("-p", "--password
|
26
|
+
opts.on("-p", "--password PASSWORD", "mite.user password") do |password|
|
25
27
|
@options["password"] = password
|
26
28
|
end
|
27
29
|
|
30
|
+
opts.on(
|
31
|
+
"-w", "--wait-for SECONDS", Integer,
|
32
|
+
"Number of seconds to wait for backup to be ready. Defaults to 240 seconds."
|
33
|
+
) do |seconds|
|
34
|
+
@options["wait_for"] = seconds
|
35
|
+
end
|
36
|
+
|
28
37
|
opts.on("-c", "--clear", "Removes all config values from config file.") do
|
29
38
|
@options["clear_config"] = true
|
30
39
|
end
|
@@ -37,7 +46,7 @@ parser = OptionParser.new do |opts|
|
|
37
46
|
opts.separator ""
|
38
47
|
opts.separator "Commands:"
|
39
48
|
opts.separator " get Download backupfile and ouput xml to STDOUT (Default command)"
|
40
|
-
opts.separator " setup
|
49
|
+
opts.separator " setup Write given options to config file ~/.mite-backup.yml, so you don't need to repeat them on every get command."
|
41
50
|
opts.separator ""
|
42
51
|
end
|
43
52
|
|
@@ -53,4 +62,4 @@ else
|
|
53
62
|
puts ""
|
54
63
|
puts parser.help
|
55
64
|
exit(1)
|
56
|
-
end
|
65
|
+
end
|
data/lib/mite-backup.rb
CHANGED
@@ -6,17 +6,20 @@ require 'zlib'
|
|
6
6
|
require 'yaml'
|
7
7
|
|
8
8
|
class MiteBackup
|
9
|
-
|
10
|
-
SLEEP_BEFORE_EACH_CHECK =
|
9
|
+
DEFAULT_WAIT_FOR = 240 # seconds
|
10
|
+
SLEEP_BEFORE_EACH_CHECK = 5 # seconds
|
11
11
|
CONFIG_FILE = File.expand_path('~/.mite-backup.yml')
|
12
12
|
USER_AGENT = "mite-backup/#{MiteBackup::VERSION}"
|
13
13
|
|
14
14
|
def initialize(options={})
|
15
15
|
@options = options
|
16
16
|
self.class.clear_config if options["clear_config"]
|
17
|
-
@account = options["account"] || config["account"]
|
17
|
+
@account = correct_account(options["account"] || config["account"])
|
18
18
|
@email = options["email"] || config["email"]
|
19
19
|
@password = options["password"] || config["password"]
|
20
|
+
@max_checks = options["wait_for"] != DEFAULT_WAIT_FOR ?
|
21
|
+
options["wait_for"] / SLEEP_BEFORE_EACH_CHECK :
|
22
|
+
config["wait_for"] || DEFAULT_WAIT_FOR
|
20
23
|
end
|
21
24
|
|
22
25
|
def run
|
@@ -30,7 +33,9 @@ class MiteBackup
|
|
30
33
|
(config["account"] = @account) || config.delete("account")
|
31
34
|
(config["email"] = @email) || config.delete("email")
|
32
35
|
(config["password"] = @password) || config.delete("password")
|
33
|
-
|
36
|
+
(config["wait_for"] = @options["wait_for"]) || config.delete("wait_for")
|
37
|
+
config.delete("wait_for") if config["wait_for"] == DEFAULT_WAIT_FOR
|
38
|
+
|
34
39
|
if config.size == 0
|
35
40
|
self.class.clear_config
|
36
41
|
else
|
@@ -47,17 +52,19 @@ class MiteBackup
|
|
47
52
|
private
|
48
53
|
|
49
54
|
def runnable?
|
50
|
-
failed "Please provide your account
|
55
|
+
failed "Please provide your account subdomain with --account [ACCOUNT-SUBDOMAIN]." unless @account
|
51
56
|
failed "Please provide your mite.users email with --email [EMAIL]." unless @email
|
52
57
|
failed "Please provide your mite.users password with --password [PASSWORD]." unless @password
|
53
58
|
end
|
54
59
|
|
55
60
|
def create
|
56
|
-
@id = parse_json(perform_request(Net::HTTP::Post.new("/account/backup.json"))
|
61
|
+
@id = parse_json(perform_request(Net::HTTP::Post.new("/account/backup.json")){ |code|
|
62
|
+
"Could not find any account located at #{domain}" if code == "404"
|
63
|
+
})["id"]
|
57
64
|
end
|
58
65
|
|
59
66
|
def check
|
60
|
-
|
67
|
+
@max_checks.times do |i|
|
61
68
|
sleep(SLEEP_BEFORE_EACH_CHECK)
|
62
69
|
@ready = parse_json(perform_request(Net::HTTP::Get.new("/account/backup/#{@id}.json")))["ready"]
|
63
70
|
break if @ready
|
@@ -67,10 +74,15 @@ class MiteBackup
|
|
67
74
|
def download
|
68
75
|
if @ready
|
69
76
|
content = perform_request(Net::HTTP::Get.new("/account/backup/#{@id}/download.json"))
|
70
|
-
|
77
|
+
content_str = StringIO.new(content)
|
78
|
+
gz = if RUBY_VERSION =~ /\A1\.8\./
|
79
|
+
Zlib::GzipReader.new(content_str)
|
80
|
+
else
|
81
|
+
Zlib::GzipReader.new(content_str, :external_encoding => content.encoding)
|
82
|
+
end
|
71
83
|
puts gz.read
|
72
84
|
else
|
73
|
-
failed "Backup was not ready for download after #{
|
85
|
+
failed "Backup was not ready for download after #{@options["wait_for"]} seconds. Contact the mite.support."
|
74
86
|
end
|
75
87
|
end
|
76
88
|
|
@@ -81,7 +93,8 @@ class MiteBackup
|
|
81
93
|
if response.code == "401"
|
82
94
|
failed "Could not authenticate with email #{@email.inspect} and provided password. The user needs to be an admin or the owner of the mite.account!"
|
83
95
|
elsif !["200", "201"].include?(response.code)
|
84
|
-
|
96
|
+
message = block_given? && yield(response.code)
|
97
|
+
failed(message || "mite responded with irregular code #{response.code}")
|
85
98
|
end
|
86
99
|
response.body
|
87
100
|
end
|
@@ -92,18 +105,26 @@ class MiteBackup
|
|
92
105
|
|
93
106
|
def mite
|
94
107
|
@mite ||= begin
|
95
|
-
mite = Net::HTTP.new(URI.parse(
|
108
|
+
mite = Net::HTTP.new(URI.parse(domain).host, 443)
|
96
109
|
mite.use_ssl = true
|
97
110
|
mite
|
98
111
|
end
|
99
112
|
end
|
100
113
|
|
114
|
+
def domain
|
115
|
+
"https://#{@account}.mite.yo.lk/"
|
116
|
+
end
|
117
|
+
|
101
118
|
def failed(reason)
|
102
119
|
$stderr.puts "Failed: #{reason}"
|
103
120
|
exit(1)
|
104
121
|
end
|
105
|
-
|
122
|
+
|
106
123
|
def config
|
107
124
|
@config ||= File.exist?(CONFIG_FILE) && YAML::load( File.open( CONFIG_FILE ) ) || {}
|
108
125
|
end
|
126
|
+
|
127
|
+
def correct_account(account)
|
128
|
+
account.split(/\/\//, 2)[-1].split(/\./, 2)[0] if account
|
129
|
+
end
|
109
130
|
end
|
data/lib/mite-backup/version.rb
CHANGED
data/mite-backup.gemspec
CHANGED
metadata
CHANGED
@@ -1,38 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mite-backup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Sebastian
|
9
|
-
autorequire:
|
8
|
+
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2020-10-22 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: multi_json
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: rake
|
27
|
-
requirement: &2170014340 !ruby/object:Gem::Requirement
|
28
|
-
none: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
29
23
|
requirements:
|
30
|
-
- -
|
24
|
+
- - ">="
|
31
25
|
- !ruby/object:Gem::Version
|
32
26
|
version: '0'
|
33
|
-
type: :development
|
34
|
-
prerelease: false
|
35
|
-
version_requirements: *2170014340
|
36
27
|
description: Download a backup of your mite.account from the command-line.
|
37
28
|
email:
|
38
29
|
- sebastian@yo.lk
|
@@ -41,8 +32,7 @@ executables:
|
|
41
32
|
extensions: []
|
42
33
|
extra_rdoc_files: []
|
43
34
|
files:
|
44
|
-
- .gitignore
|
45
|
-
- .rvmrc
|
35
|
+
- ".gitignore"
|
46
36
|
- Gemfile
|
47
37
|
- MIT-LICENSE
|
48
38
|
- README.md
|
@@ -53,32 +43,24 @@ files:
|
|
53
43
|
- mite-backup.gemspec
|
54
44
|
homepage: http://mite.yo.lk/en
|
55
45
|
licenses: []
|
56
|
-
|
46
|
+
metadata: {}
|
47
|
+
post_install_message:
|
57
48
|
rdoc_options: []
|
58
49
|
require_paths:
|
59
50
|
- lib
|
60
51
|
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
-
none: false
|
62
52
|
requirements:
|
63
|
-
- -
|
53
|
+
- - ">="
|
64
54
|
- !ruby/object:Gem::Version
|
65
55
|
version: '0'
|
66
|
-
segments:
|
67
|
-
- 0
|
68
|
-
hash: 1027709733883102799
|
69
56
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
-
none: false
|
71
57
|
requirements:
|
72
|
-
- -
|
58
|
+
- - ">="
|
73
59
|
- !ruby/object:Gem::Version
|
74
60
|
version: '0'
|
75
|
-
segments:
|
76
|
-
- 0
|
77
|
-
hash: 1027709733883102799
|
78
61
|
requirements: []
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
specification_version: 3
|
62
|
+
rubygems_version: 3.0.3
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
83
65
|
summary: Download a backup of your mite.account from the command-line.
|
84
66
|
test_files: []
|
data/.rvmrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rvm use ruby-1.9.3@mite-backup --create
|