webtranslateit-safe 0.4.4 → 0.4.5
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/CHANGELOG +4 -0
- data/README.markdown +8 -0
- data/lib/webtranslateit/safe/config/builder.rb +1 -1
- data/lib/webtranslateit/safe/scp.rb +107 -0
- data/lib/webtranslateit/safe.rb +3 -1
- metadata +16 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63bd94e905a8a424ce2b408fa3d0d2898fc5d22c3be9739a95ff73668cd612ad
|
4
|
+
data.tar.gz: 2f33a476839a38aa403e89a3f0e35ad5c78a9c403756c0472f15c45337a0b575
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b50f77cc5ee6b609ad05e85fa5fc106ed21af49e014397427aa9a77de4bba9e5d6e3cff8773d78e14314e44388d6f0cf6cbf258d0e3ffd9db0ddeedc063a525d
|
7
|
+
data.tar.gz: e21c75b914bf576842f22893098c872659ba5d7dd27b84d4f087226e7aa80a43f32a133f668a20c09492762f2459707ae1c3e7f9e074db4a8b9fc7c933b4f885
|
data/CHANGELOG
CHANGED
data/README.markdown
CHANGED
@@ -155,6 +155,13 @@ The procedure to create and transfer the key is as follows:
|
|
155
155
|
password "ssh password for sftp"
|
156
156
|
end
|
157
157
|
|
158
|
+
sftp do
|
159
|
+
host "sftp.astrails.com"
|
160
|
+
user "astrails"
|
161
|
+
# port 8023
|
162
|
+
password "ssh password for scp"
|
163
|
+
end
|
164
|
+
|
158
165
|
gpg do
|
159
166
|
command "/usr/local/bin/gpg"
|
160
167
|
options "--no-use-agent"
|
@@ -170,6 +177,7 @@ The procedure to create and transfer the key is as follows:
|
|
170
177
|
s3 100
|
171
178
|
cloudfiles 100
|
172
179
|
sftp 100
|
180
|
+
scp 100
|
173
181
|
end
|
174
182
|
|
175
183
|
mysqldump do
|
@@ -77,7 +77,7 @@ module WebTranslateIt
|
|
77
77
|
:api_key, :container, :socket, :service_net, :repo_path
|
78
78
|
multi_value :skip_tables, :exclude, :files
|
79
79
|
mixed_value :s3, :local, :cloudfiles, :sftp, :mysqldump, :tar, :gpg, :keep, :pgdump, :tar, :svndump,
|
80
|
-
:ftp, :mongodump
|
80
|
+
:ftp, :mongodump, :scp
|
81
81
|
collection :database, :archive, :repo
|
82
82
|
|
83
83
|
private
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WebTranslateIt
|
4
|
+
|
5
|
+
module Safe
|
6
|
+
|
7
|
+
class Scp < Sink
|
8
|
+
|
9
|
+
MAX_RETRIES = 5
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def active?
|
14
|
+
host && user
|
15
|
+
end
|
16
|
+
|
17
|
+
def path
|
18
|
+
@path ||= expand(config[:scp, :path] || config[:local, :path] || ':kind/:id')
|
19
|
+
end
|
20
|
+
|
21
|
+
def save # rubocop:todo Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
22
|
+
raise 'pipe-streaming not supported for SCP.' unless @backup.path
|
23
|
+
|
24
|
+
puts "Uploading #{host}:#{full_path} via SCP" if verbose? || dry_run?
|
25
|
+
|
26
|
+
return if dry_run? || local_only?
|
27
|
+
|
28
|
+
retries = 0
|
29
|
+
opts = {}
|
30
|
+
opts[:password] = password if password
|
31
|
+
opts[:port] = port if port
|
32
|
+
Net::SCP.start(host, user, opts) do |scp|
|
33
|
+
puts "Sending #{@backup.path} to #{full_path}" if verbose?
|
34
|
+
begin
|
35
|
+
scp.upload! @backup.path, full_path
|
36
|
+
rescue IO::TimeoutError
|
37
|
+
puts 'Upload timed out, retrying'
|
38
|
+
retries += 1
|
39
|
+
if retries >= MAX_RETRIES
|
40
|
+
puts "Tried #{retries} times. Giving up."
|
41
|
+
else
|
42
|
+
retry unless retries >= MAX_RETRIES
|
43
|
+
end
|
44
|
+
rescue Net::SCP::Error
|
45
|
+
puts "Ensuring remote path (#{path}) exists" if verbose?
|
46
|
+
# mkdir -p
|
47
|
+
folders = path.split('/')
|
48
|
+
folders.each_index do |i|
|
49
|
+
folder = folders[0..i].join('/')
|
50
|
+
puts "Creating #{folder} on remote" if verbose?
|
51
|
+
begin
|
52
|
+
scp.mkdir!(folder)
|
53
|
+
rescue StandardError
|
54
|
+
Net::SCP::Error
|
55
|
+
end
|
56
|
+
end
|
57
|
+
retry
|
58
|
+
end
|
59
|
+
end
|
60
|
+
puts '...done' if verbose?
|
61
|
+
end
|
62
|
+
|
63
|
+
def cleanup
|
64
|
+
return if local_only? || dry_run?
|
65
|
+
|
66
|
+
return unless (keep = config[:keep, :scp])
|
67
|
+
|
68
|
+
puts "listing files: #{host}:#{base}*" if verbose?
|
69
|
+
opts = {}
|
70
|
+
opts[:password] = password if password
|
71
|
+
opts[:port] = port if port
|
72
|
+
Net::SFTP.start(host, user, opts) do |sftp|
|
73
|
+
files = sftp.dir.glob(path, File.basename("#{base}*"))
|
74
|
+
|
75
|
+
puts files.collect(&:name) if verbose?
|
76
|
+
|
77
|
+
files = files.collect(&:name).sort
|
78
|
+
|
79
|
+
cleanup_with_limit(files, keep) do |f|
|
80
|
+
file = File.join(path, f)
|
81
|
+
puts "removing sftp file #{host}:#{file}" if dry_run? || verbose?
|
82
|
+
sftp.remove!(file) unless dry_run? || local_only?
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def host
|
88
|
+
config[:scp, :host]
|
89
|
+
end
|
90
|
+
|
91
|
+
def user
|
92
|
+
config[:scp, :user]
|
93
|
+
end
|
94
|
+
|
95
|
+
def password
|
96
|
+
config[:scp, :password]
|
97
|
+
end
|
98
|
+
|
99
|
+
def port
|
100
|
+
config[:scp, :port]
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
data/lib/webtranslateit/safe.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'aws/s3'
|
2
2
|
require 'cloudfiles'
|
3
3
|
require 'net/sftp'
|
4
|
+
require 'net/scp'
|
4
5
|
# require 'net/ftp'
|
5
6
|
require 'fileutils'
|
6
7
|
require 'benchmark'
|
@@ -31,6 +32,7 @@ require 'webtranslateit/safe/sink'
|
|
31
32
|
require 'webtranslateit/safe/local'
|
32
33
|
require 'webtranslateit/safe/s3'
|
33
34
|
require 'webtranslateit/safe/cloudfiles'
|
35
|
+
require 'webtranslateit/safe/scp'
|
34
36
|
require 'webtranslateit/safe/sftp'
|
35
37
|
require 'webtranslateit/safe/ftp'
|
36
38
|
|
@@ -53,7 +55,7 @@ module WebTranslateIt
|
|
53
55
|
next unless collection = config[*path]
|
54
56
|
|
55
57
|
collection.each do |name, c|
|
56
|
-
klass.new(name, c).backup.run(c, :gpg, :gzip, :local, :s3, :cloudfiles, :sftp, :ftp)
|
58
|
+
klass.new(name, c).backup.run(c, :gpg, :gzip, :local, :s3, :cloudfiles, :scp, :sftp, :ftp)
|
57
59
|
end
|
58
60
|
end
|
59
61
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webtranslateit-safe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edouard Briere
|
@@ -39,6 +39,20 @@ dependencies:
|
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: net-scp
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
42
56
|
- !ruby/object:Gem::Dependency
|
43
57
|
name: net-sftp
|
44
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,6 +96,7 @@ files:
|
|
82
96
|
- lib/webtranslateit/safe/pgdump.rb
|
83
97
|
- lib/webtranslateit/safe/pipe.rb
|
84
98
|
- lib/webtranslateit/safe/s3.rb
|
99
|
+
- lib/webtranslateit/safe/scp.rb
|
85
100
|
- lib/webtranslateit/safe/sftp.rb
|
86
101
|
- lib/webtranslateit/safe/sink.rb
|
87
102
|
- lib/webtranslateit/safe/source.rb
|