cprobert-s3sync 1.3.6

Sign up to get free protection for your applications and to get access to all the features.
data/docs/README.txt ADDED
@@ -0,0 +1,184 @@
1
+
2
+
3
+ Change Log:
4
+ -----------
5
+
6
+ 2006-09-29:
7
+ Added support for --expires and --cache-control. Eg:
8
+ --expires="Thu, 01 Dec 2007 16:00:00 GMT"
9
+ --cache-control="no-cache"
10
+
11
+ Thanks to Charles for pointing out the need for this, and supplying a patch
12
+ proving that it would be trivial to add =) Apologies for not including the short
13
+ form (-e) for the expires. I have a rule that options taking arguments should
14
+ use the long form.
15
+ ----------
16
+
17
+ 2006-10-04
18
+ Several minor debugs and edge cases.
19
+ Fixed a bug where retries didn't rewind the stream to start over.
20
+ ----------
21
+
22
+ 2006-10-12
23
+ Version 1.0.5
24
+ Finally figured out and fixed bug of trying to follow local symlink-to-directory.
25
+ Fixed a really nasty sorting discrepancy that caused problems when files started
26
+ with the same name as a directory.
27
+ Retry on connection-reset on the S3 side.
28
+ Skip files that we can't read instead of dying.
29
+ ----------
30
+
31
+ 2006-10-12
32
+ Version 1.0.6
33
+ Some GC voodoo to try and keep a handle on the memory footprint a little better.
34
+ There is still room for improvement here.
35
+ ----------
36
+
37
+ 2006-10-13
38
+ Version 1.0.7
39
+ Fixed symlink dirs being stored to S3 as real dirs (and failing with 400)
40
+ Added a retry catch for connection timeout error.
41
+ (Hopefully) caught a bug that expected every S3 listing to contain results
42
+ ----------
43
+
44
+ 2006-10-14
45
+ Version 1.0.8
46
+ Was testing for file? before symlink? in localnode.stream. This meant that for
47
+ symlink files it was trying to shove the real file contents into the symlink
48
+ body on s3.
49
+ ----------
50
+
51
+ 2006-10-14
52
+ Version 1.0.9
53
+ Woops, I was using "max-entries" for some reason but the proper header is
54
+ "max-keys". Not a big deal.
55
+ Broke out the S3try stuff into a separate file so I could re-use it for s3cmd.rb
56
+ ----------
57
+
58
+ 2006-10-16
59
+ Added a couple debug lines; not even enough to call it a version revision.
60
+ ----------
61
+
62
+ 2006-10-25
63
+ Version 1.0.10
64
+ UTF-8 fixes.
65
+ Catching a couple more retry-able errors in s3try (instead of aborting the
66
+ program).
67
+ ----------
68
+
69
+ 2006-10-26
70
+ Version 1.0.11
71
+ Revamped some details of the generators and comparator so that directories are
72
+ handled in a more exact and uniform fashion across local and S3.
73
+ ----------
74
+
75
+ 2006-11-28
76
+ Version 1.0.12
77
+ Added a couple more error catches to s3try.
78
+ ----------
79
+
80
+ 2007-01-08
81
+ Version 1.0.13
82
+ Numerous small changes to slash and path handling, in order to catch several
83
+ cases where "root" directory nodes were not being created on S3.
84
+ This makes restores work a lot more intuitively in many cases.
85
+ ----------
86
+
87
+ 2007-01-25
88
+ Version 1.0.14
89
+ Peter Fales' marker fix.
90
+ Also, markers should be decoded into native charset (because that's what s3
91
+ expects to see).
92
+ ----------
93
+
94
+ 2007-02-19
95
+ Version 1.1.0
96
+ *WARNING* Lots of path-handling changes. *PLEASE* test safely before you just
97
+ swap this in for your working 1.0.x version.
98
+
99
+ - Adding --exclude (and there was much rejoicing).
100
+ - Found Yet Another Leading Slash Bug with respect to local nodes. It was always
101
+ "recursing" into the first folder even if there was no trailing slash and -r
102
+ wasn't specified. What it should have done in this case is simply create a node
103
+ for the directory itself, then stop (not check the dir's contents).
104
+ - Local node canonicalization was (potentially) stripping the trailing slash,
105
+ which we need in order to make some decisios in the local generator.
106
+ - Fixed problem where it would prepend a "/" to s3 key names even with blank
107
+ prefix.
108
+ - Fixed S3->local when there's no "/" in the source so it doesn't try to create
109
+ a folder with the bucket name.
110
+ - Updated s3try and s3_s3sync_mod to allow SSL_CERT_FILE
111
+ ----------
112
+
113
+ 2007-02-22
114
+ Version 1.1.1
115
+ Fixed dumb regression bug caused by the S3->local bucket name fix in 1.1.0
116
+ ----------
117
+
118
+ 2007-02-25
119
+ Version 1.1.2
120
+ Added --progress
121
+ ----------
122
+
123
+ 2007-06-02
124
+ Version 1.1.3
125
+ IMPORTANT!
126
+ Pursuant to http://s3sync.net/forum/index.php?topic=49.0 , the tar.gz now
127
+ expands into its own sub-directory named "s3sync" instead of dumping all the
128
+ files into the current directory.
129
+
130
+ In the case of commands of the form:
131
+ s3sync -r somedir somebucket:
132
+ The root directory node in s3 was being stored as "somedir/" instead of "somedir"
133
+ which caused restores to mess up when you say:
134
+ s3sync -r somebucket: restoredir
135
+ The fix to this, by coincidence, actually makes s3fox work even *less* well with
136
+ s3sync. I really need to build my own xul+javascript s3 GUI some day.
137
+
138
+ Also fixed some of the NoMethodError stuff for when --progress is used
139
+ and caught Errno::ETIMEDOUT
140
+ ----------
141
+
142
+ 2007-07-12
143
+ Version 1.1.4
144
+ Added Alastair Brunton's yaml config code.
145
+ ----------
146
+
147
+ 2007-11-17
148
+ Version 1.2.1
149
+ Compatibility for S3 API revisions.
150
+ When retries are exhausted, emit an error.
151
+ Don't ever try to delete the 'root' local dir.
152
+ ----------
153
+
154
+ 2007-11-20
155
+ Version 1.2.2
156
+ Handle EU bucket 307 redirects (in s3try.rb)
157
+ --make-dirs added
158
+ ----------
159
+
160
+ 2007-11-20
161
+ Version 1.2.3
162
+ Fix SSL verification settings that broke in new S3 API.
163
+ ----------
164
+
165
+ 2008-01-06
166
+ Version 1.2.4
167
+ Run from any dir (search "here" for includes).
168
+ Search out s3config.yml in some likely places.
169
+ Reset connection (properly) on retry-able non-50x errors.
170
+ Fix calling format bug preventing it from working from yml.
171
+ Added http proxy support.
172
+ ----------
173
+
174
+ 2008-05-11
175
+ Version 1.2.5
176
+ Added option --no-md5
177
+ ----------
178
+
179
+ 2008-06-16
180
+ Version 1.2.6
181
+ Catch connect errors and retry.
182
+ ----------
183
+
184
+ FNORD
@@ -0,0 +1,172 @@
1
+ Welcome to s3cmd.rb
2
+ -------------------
3
+ This is a ruby program that wraps S3 operations into a simple command-line tool.
4
+ It is inspired by things like rsh3ll, #sh3ll, etc., but shares no code from
5
+ them. It's meant as a companion utility to s3sync.rb but could be used on its
6
+ own (provided you have read the other readme file and know how to use s3sync in
7
+ theory).
8
+
9
+ I made this even though lots of other "shell"s exist, because I wanted a
10
+ single-operation utility, instead of a shell "environment". This lends itself
11
+ more to scripting, etc. Also the delete operation on rsh3ll seems to be borken
12
+ at the moment? =(
13
+
14
+ Users not yet familiar with s3sync should read about that first, since s3cmd and
15
+ s3sync share a tremendous amount of conventions and syntax. Particularly you
16
+ have to set up environment variables prior to calling s3cmd, and s3cmd also uses
17
+ the "bucket:key" syntax popularized by s3sync. Many of the options are the same
18
+ too. Really, go read the other readme first if you haven't used s3sync yet.
19
+ Otherwise you will become confused. It's OK, I'll wait.
20
+
21
+ ....
22
+
23
+ In general, s3sync and s3cmd complement each other. s3sync is useful to perform
24
+ serious synchronization operations, and s3cmd allows you to do simple things
25
+ such as bucket management, listing, transferring single files, and the like.
26
+
27
+ Here is the usage, with examples to follow.
28
+
29
+ s3cmd.rb [options] <command> [arg(s)] version 1.0.0
30
+ --help -h --verbose -v --dryrun -n
31
+ --ssl -s --debug -d
32
+
33
+ Commands:
34
+ s3cmd.rb listbuckets [headers]
35
+ s3cmd.rb createbucket|deletebucket <bucket> [headers]
36
+ s3cmd.rb list <bucket>[:prefix] [max/page] [delimiter] [headers]
37
+ s3cmd.rb delete <bucket>:key [headers]
38
+ s3cmd.rb deleteall <bucket>[:prefix] [headers]
39
+ s3cmd.rb get|put <bucket>:key <file> [headers]
40
+
41
+
42
+ A note about [headers]
43
+ ----------------------
44
+ For some S3 operations, such as "put", you might want to specify certain headers
45
+ to the request such as Cache-Control, Expires, x-amz-acl, etc. Rather than
46
+ supporting a load of separate command-line options for these, I just allow
47
+ header specification. So to upload a file with public-read access you could
48
+ say:
49
+ s3cmd.rb put MyBucket:TheFile.txt x-amz-acl:public-read
50
+
51
+ If you don't need to add any particular headers then you can just ignore this
52
+ whole [headers] thing and pretend it's not there. This is somewhat of an
53
+ advanced option.
54
+
55
+
56
+ Examples
57
+ --------
58
+ List all the buckets your account owns:
59
+ s3cmd.rb listbuckets
60
+
61
+ Create a new bucket:
62
+ s3cmd.rb createbucket BucketName
63
+
64
+ Create a new bucket in the EU:
65
+ s3cmd.rb createbucket BucketName EU
66
+
67
+ Find out the location constraint of a bucket:
68
+ s3cmd.rb location BucketName
69
+
70
+ Delete an old bucket you don't want any more:
71
+ s3cmd.rb deletebucket BucketName
72
+
73
+ Find out what's in a bucket, 10 lines at a time:
74
+ s3cmd.rb list BucketName 10
75
+
76
+ Only look in a particular prefix:
77
+ s3cmd.rb list BucketName:startsWithThis
78
+
79
+ Look in the virtual "directory" named foo;
80
+ lists sub-"directories" and keys that are at this level.
81
+ Note that if you specify a delimiter you must specify a max before it.
82
+ (until I make the options parsing smarter)
83
+ s3cmd.rb list BucketName:foo/ 10 /
84
+
85
+ Delete a key:
86
+ s3cmd.rb delete BucketName:AKey
87
+
88
+ Delete all keys that match (like a combo between list and delete):
89
+ s3cmd.rb deleteall BucketName:SomePrefix
90
+
91
+ Only pretend you're going to delete all keys that match, but list them:
92
+ s3cmd.rb --dryrun deleteall BucketName:SomePrefix
93
+
94
+ Delete all keys in a bucket (leaving the bucket):
95
+ s3cmd.rb deleteall BucketName
96
+
97
+ Get a file from S3 and store it to a local file
98
+ s3cmd.rb get BucketName:TheFileOnS3.txt ALocalFile.txt
99
+
100
+ Put a local file up to S3
101
+ Note we don't automatically set mime type, etc.
102
+ NOTE that the order of the options doesn't change. S3 stays first!
103
+ s3cmd.rb put BucketName:TheFileOnS3.txt ALocalFile.txt
104
+
105
+
106
+ Change Log:
107
+ -----------
108
+ 2006-10-14:
109
+ Created.
110
+ -----------
111
+
112
+ 2006-10-16
113
+ Version 1.0.1
114
+ Force content length to a string value since some ruby's don't convert it right.
115
+ -----------
116
+
117
+ 2006-10-25
118
+ UTF-8 fixes.
119
+ -----------
120
+
121
+ 2006-11-28
122
+ Version 1.0.3
123
+ Added a couple more error catches to s3try.
124
+ ----------
125
+
126
+ 2007-01-25
127
+ Version 1.0.4
128
+ Peter Fales' marker fix.
129
+ Also, markers should be decoded into native charset (because that's what s3
130
+ expects to see).
131
+ ----------
132
+
133
+ 2007-02-19
134
+ - Updated s3try and s3_s3sync_mod to allow SSL_CERT_FILE
135
+ ----------
136
+
137
+ 2007-2-25
138
+ Added --progress
139
+ ----------
140
+
141
+ 2007-07-12
142
+ Version 1.0.6
143
+ Added Alastair Brunton's yaml config code.
144
+ ----------
145
+
146
+ 2007-11-17
147
+ Version 1.2.1
148
+ Compatibility for S3 API revisions.
149
+ When retries are exhausted, emit an error.
150
+ ----------
151
+
152
+ 2007-11-20
153
+ Version 1.2.2
154
+ Handle EU bucket 307 redirects (in s3try.rb)
155
+ ----------
156
+
157
+ 2007-11-20
158
+ Version 1.2.3
159
+ Fix SSL verification settings that broke in new S3 API.
160
+ ----------
161
+
162
+ 2008-01-06
163
+ Version 1.2.4
164
+ Run from any dir (search "here" for includes).
165
+ Search out s3config.yml in some likely places.
166
+ Reset connection (properly) on retry-able non-50x errors.
167
+ Fix calling format bug preventing it from working from yml.
168
+ Added http proxy support.
169
+ ----------
170
+
171
+
172
+ FNORD
@@ -0,0 +1,3 @@
1
+ aws_access_key_id: 11111111111111111111111
2
+ aws_secret_access_key: 222222222222222222222
3
+ ssl_cert_dir: /home/user/s3sync/certs
data/lib/s3sync.rb ADDED
@@ -0,0 +1,39 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ module S3sync
5
+ VERSION = '1.3.0'
6
+
7
+ require 's3sync/s3try'
8
+ require 's3sync/s3config'
9
+
10
+ # after other mods, so we don't overwrite yaml vals with defaults
11
+ include S3Config
12
+
13
+
14
+ def S3sync.s3cmdList(bucket, path, max=nil, delim=nil, marker=nil, headers={})
15
+ debug(max)
16
+ options = Hash.new
17
+ options['prefix'] = path # start at the right depth
18
+ options['max-keys'] = max ? max.to_s : 100
19
+ options['delimiter'] = delim if delim
20
+ options['marker'] = marker if marker
21
+ S3try(:list_bucket, bucket, options, headers)
22
+ end
23
+
24
+ # turn an array into a hash of pairs
25
+ def S3sync.hashPairs(ar)
26
+ ret = Hash.new
27
+ ar.each do |item|
28
+ name = (/^(.*?):/.match(item))[1]
29
+ item = (/^.*?:(.*)$/.match(item))[1]
30
+ ret[name] = item
31
+ end if ar
32
+ ret
33
+ end
34
+ end
35
+
36
+
37
+ def debug(str)
38
+ $stderr.puts str if $S3syncOptions['--debug']
39
+ end
@@ -0,0 +1,108 @@
1
+ # This software code is made available "AS IS" without warranties of any
2
+ # kind. You may copy, display, modify and redistribute the software
3
+ # code either by itself or as incorporated into your code; provided that
4
+ # you do not remove any proprietary notices. Your use of this software
5
+ # code is at your own risk and you waive any claim against the author
6
+ # with respect to your use of this software code.
7
+ # (c) 2007 s3sync.net
8
+ #
9
+
10
+ # The purpose of this file is to overlay the net/http library
11
+ # to add some functionality
12
+ # (without changing the file itself or requiring a specific version)
13
+ # It still isn't perfectly robust, i.e. if radical changes are made
14
+ # to the underlying lib this stuff will need updating.
15
+
16
+ require 'net/http'
17
+ require 'delegate'
18
+
19
+ module Net
20
+
21
+ $HTTPStreamingDebug = false
22
+
23
+ # Allow request body to be an IO stream
24
+ # Allow an IO stream argument to stream the response body out
25
+ class HTTP
26
+ alias _HTTPStreaming_request request
27
+
28
+ def request(req, body = nil, streamResponseBodyTo = nil, &block)
29
+ if not block_given? and streamResponseBodyTo and streamResponseBodyTo.respond_to?(:write)
30
+ $stderr.puts "Response using streaming" if $HTTPStreamingDebug
31
+ # this might be a retry, we should make sure the stream is at its beginning
32
+ streamResponseBodyTo.rewind if streamResponseBodyTo.respond_to?(:rewind) and streamResponseBodyTo != $stdout
33
+ block = proc do |res|
34
+ res.read_body do |chunk|
35
+ streamResponseBodyTo.write(chunk)
36
+ end
37
+ end
38
+ end
39
+ if body != nil && body.respond_to?(:read)
40
+ $stderr.puts "Request using streaming" if $HTTPStreamingDebug
41
+ # this might be a retry, we should make sure the stream is at its beginning
42
+ body.rewind if body.respond_to?(:rewind)
43
+ req.body_stream = body
44
+ return _HTTPStreaming_request(req, nil, &block)
45
+ else
46
+ return _HTTPStreaming_request(req, body, &block)
47
+ end
48
+ end
49
+ end
50
+
51
+ end #module
52
+
53
+ module S3sync
54
+ class ProgressStream < SimpleDelegator
55
+ def initialize(s, size=0)
56
+ @start = @last = Time.new
57
+ @total = size
58
+ @transferred = 0
59
+ @closed = false
60
+ @printed = false
61
+ @innerStream = s
62
+ super(@innerStream)
63
+ __setobj__(@innerStream)
64
+ end
65
+ # need to catch reads and writes so we can count what's being transferred
66
+ def read(i)
67
+ res = @innerStream.read(i)
68
+ @transferred += res.respond_to?(:length) ? res.length : 0
69
+ now = Time.new
70
+ if(now - @last > 1) # don't do this oftener than once per second
71
+ @printed = true
72
+ begin
73
+ $stdout.printf("\rProgress: %db %db/s %s ", @transferred, (@transferred/(now - @start)).floor,
74
+ @total > 0? (100 * @transferred/@total).floor.to_s + "%" : ""
75
+ )
76
+ rescue FloatDomainError
77
+ #wtf?
78
+ end
79
+ $stdout.flush
80
+ @last = now
81
+ end
82
+ res
83
+ end
84
+ def write(s)
85
+ @transferred += s.length
86
+ res = @innerStream.write(s)
87
+ now = Time.new
88
+ if(now -@last > 1) # don't do this oftener than once per second
89
+ @printed = true
90
+ $stdout.printf("\rProgress: %db %db/s %s ", @transferred, (@transferred/(now - @start)).floor,
91
+ @total > 0? (100 * @transferred/@total).floor.to_s + "%" : ""
92
+ )
93
+ $stdout.flush
94
+ @last = now
95
+ end
96
+ res
97
+ end
98
+ def rewind()
99
+ @transferred = 0
100
+ @innerStream.rewind if @innerStream.respond_to?(:rewind)
101
+ end
102
+ def close()
103
+ $stdout.printf("\n") if @printed and not @closed
104
+ @closed = true
105
+ @innerStream.close
106
+ end
107
+ end
108
+ end #module