ssync 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -0
- data/lib/ssync/command.rb +7 -4
- data/lib/ssync/helpers.rb +24 -4
- data/lib/ssync/setup.rb +15 -7
- data/lib/ssync/sync.rb +8 -10
- data/lib/ssync/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -28,6 +28,16 @@ To sync, run `ssync sync` and away it goes.
|
|
28
28
|
In the case of a corrupted/incomplete synchronisation, run `ssync sync -f`
|
29
29
|
or `ssync sync --force` to force a checksum comparison.
|
30
30
|
|
31
|
+
## Sync to Multiple Buckets
|
32
|
+
|
33
|
+
If you would like to sync to more than one S3 buckets, you may do so by:
|
34
|
+
|
35
|
+
ssync setup s3-bucket-name-1
|
36
|
+
ssync sync s3-bucket-name-1
|
37
|
+
|
38
|
+
ssync setup s3-bucket-name-2
|
39
|
+
ssync sync s3-bucket-name-2
|
40
|
+
|
31
41
|
## Why?
|
32
42
|
|
33
43
|
This library was written because we needed to be able to back up loads of
|
data/lib/ssync/command.rb
CHANGED
@@ -19,6 +19,11 @@ module Ssync
|
|
19
19
|
def initialize(action = :sync, *args)
|
20
20
|
@@action = action.to_sym
|
21
21
|
@@args = *args
|
22
|
+
|
23
|
+
if @@args[0] && @@args[0][0, 1] != "-"
|
24
|
+
Setup.default_config[:last_used_bucket] = @@args[0]
|
25
|
+
write_default_config!(Setup.default_config)
|
26
|
+
end
|
22
27
|
end
|
23
28
|
|
24
29
|
def run!
|
@@ -29,9 +34,7 @@ module Ssync
|
|
29
34
|
private
|
30
35
|
|
31
36
|
def pre_run_check!
|
32
|
-
if action_eq?(:
|
33
|
-
e! "Cannot run the setup, there is already an Ssync configuration in '#{config_path}'."
|
34
|
-
elsif action_eq?(:sync) && !config_exists?
|
37
|
+
if action_eq?(:sync) && !config_exists?(default_config_path) && !config_exists?
|
35
38
|
e! "Cannot run the sync, there is no Ssync configuration, try 'ssync setup' to create one first."
|
36
39
|
end
|
37
40
|
end
|
@@ -39,7 +42,7 @@ module Ssync
|
|
39
42
|
def perform_action!
|
40
43
|
case @@action
|
41
44
|
when :setup
|
42
|
-
|
45
|
+
Ssync::Setup.run!
|
43
46
|
when :sync
|
44
47
|
aquire_lock! { Ssync::Sync.run! }
|
45
48
|
when :help
|
data/lib/ssync/helpers.rb
CHANGED
@@ -30,16 +30,24 @@ module Ssync
|
|
30
30
|
Ssync::Command.action == action.to_sym
|
31
31
|
end
|
32
32
|
|
33
|
-
def config_exists?
|
34
|
-
File.exist?(
|
33
|
+
def config_exists?(path = config_path)
|
34
|
+
File.exist?(path)
|
35
|
+
end
|
36
|
+
|
37
|
+
def ssync_filename
|
38
|
+
".ssync-#{read_default_config[:last_used_bucket]}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def default_config_path
|
42
|
+
"#{ENV['HOME']}/.ssync.defaults.yml"
|
35
43
|
end
|
36
44
|
|
37
45
|
def config_path
|
38
|
-
ENV['HOME']
|
46
|
+
"#{ENV['HOME']}/#{ssync_filename}.yml"
|
39
47
|
end
|
40
48
|
|
41
49
|
def lock_path
|
42
|
-
ENV['HOME']
|
50
|
+
"#{ENV['HOME']}/#{ssync_filename}.lock"
|
43
51
|
end
|
44
52
|
|
45
53
|
def aquire_lock!
|
@@ -62,10 +70,22 @@ module Ssync
|
|
62
70
|
end
|
63
71
|
end
|
64
72
|
|
73
|
+
def read_default_config
|
74
|
+
begin
|
75
|
+
open(default_config_path, "r") { |f| YAML::load(f) }
|
76
|
+
rescue
|
77
|
+
{}
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
65
81
|
def write_config!(config)
|
66
82
|
open(config_path, "w") { |f| YAML::dump(config, f) }
|
67
83
|
end
|
68
84
|
|
85
|
+
def write_default_config!(config)
|
86
|
+
open(default_config_path, "w") { |f| YAML::dump(config, f) }
|
87
|
+
end
|
88
|
+
|
69
89
|
def options_set?(*options)
|
70
90
|
false
|
71
91
|
[options].flatten.each do |option|
|
data/lib/ssync/setup.rb
CHANGED
@@ -3,8 +3,16 @@ module Ssync
|
|
3
3
|
class << self
|
4
4
|
include Helpers
|
5
5
|
|
6
|
+
def default_config
|
7
|
+
@default_config ||= read_default_config
|
8
|
+
end
|
9
|
+
|
10
|
+
def default_config=(config)
|
11
|
+
@default_config = config
|
12
|
+
end
|
13
|
+
|
6
14
|
def config
|
7
|
-
@config
|
15
|
+
@config ||= read_config
|
8
16
|
end
|
9
17
|
|
10
18
|
def config=(config)
|
@@ -12,9 +20,7 @@ module Ssync
|
|
12
20
|
end
|
13
21
|
|
14
22
|
def run!
|
15
|
-
display "Welcome to Ssync! You will now be asked a few questions
|
16
|
-
|
17
|
-
config = read_config
|
23
|
+
display "Welcome to Ssync! You will now be asked for a few questions."
|
18
24
|
|
19
25
|
config[:aws_access_key] = ask config[:aws_access_key], "What is the AWS Access Key ID?"
|
20
26
|
config[:aws_secret_key] = ask config[:aws_secret_key], "What is the AWS Secret Access Key?"
|
@@ -24,7 +30,7 @@ module Ssync
|
|
24
30
|
if aws_credentials_is_valid?(config)
|
25
31
|
display "Successfully connected to AWS."
|
26
32
|
|
27
|
-
config[:aws_dest_bucket] = ask
|
33
|
+
default_config[:last_used_bucket] = config[:aws_dest_bucket] = ask(config[:aws_dest_bucket], "Which bucket would you like to put your backups in? Ssync will create the bucket for you if it doesn't exist.")
|
28
34
|
|
29
35
|
if bucket_exists?(config)
|
30
36
|
if bucket_empty?(config)
|
@@ -53,9 +59,11 @@ module Ssync
|
|
53
59
|
|
54
60
|
config[:find_options] = ask config[:find_options], "Do you have any options for 'find'? (e.g. \! -path *.git*)."
|
55
61
|
|
56
|
-
display "
|
62
|
+
display "Saving configuration data ..."
|
63
|
+
write_default_config!(default_config)
|
57
64
|
write_config!(config)
|
58
|
-
display "All done!
|
65
|
+
display "All done! The configuration file is stored in '#{config_path}'."
|
66
|
+
display "You may now use 'ssync sync' to syncronise your files to the S3 bucket."
|
59
67
|
end
|
60
68
|
|
61
69
|
def aws_credentials_is_valid?(config = read_config)
|
data/lib/ssync/sync.rb
CHANGED
@@ -45,11 +45,11 @@ module Ssync
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def last_sync_started
|
48
|
-
ENV['HOME'] + "
|
48
|
+
ENV['HOME'] + "/#{ssync_filename}.last-sync.started"
|
49
49
|
end
|
50
50
|
|
51
51
|
def last_sync_completed
|
52
|
-
ENV['HOME'] + "
|
52
|
+
ENV['HOME'] + "/#{ssync_filename}.last-sync.completed"
|
53
53
|
end
|
54
54
|
|
55
55
|
def last_sync_recorded?
|
@@ -99,19 +99,17 @@ module Ssync
|
|
99
99
|
end
|
100
100
|
|
101
101
|
def local_manifest_path
|
102
|
-
"/tmp
|
102
|
+
"/tmp/#{ssync_filename}.manifest.local"
|
103
103
|
end
|
104
104
|
|
105
105
|
def parse_manifest(location)
|
106
106
|
[]
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
{ :path => path, :checksum => checksum }
|
112
|
-
end
|
107
|
+
open(location, "r") do |file|
|
108
|
+
file.collect do |line|
|
109
|
+
path, checksum = *line.chomp.match(/^MD5\((.*)\)= (.*)$/).captures
|
110
|
+
{ :path => path, :checksum => checksum }
|
113
111
|
end
|
114
|
-
end
|
112
|
+
end if File.exist?(location)
|
115
113
|
end
|
116
114
|
|
117
115
|
def push_file(file)
|
data/lib/ssync/version.rb
CHANGED