Module: S3MetaSync

Defined in:
lib/s3_meta_sync.rb,
lib/s3_meta_sync/version.rb

Defined Under Namespace

Classes: Syncer

Constant Summary collapse

RemoteWithoutMeta =
Class.new(Exception)
META_FILE =
".s3-meta-sync"
VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.parse_options(argv) ⇒ Object



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/s3_meta_sync.rb', line 166

def parse_options(argv)
  options = {
    :key => ENV["AWS_ACCESS_KEY_ID"],
    :secret => ENV["AWS_SECRET_ACCESS_KEY"]
  }
  OptionParser.new do |opts|
    opts.banner = "      Sync folders with s3 using a metadata file with md5 sums.\n\n      # upload local files and remove everything that is not local\n      s3-meta-sync <local> <bucket:folder> --key <aws-access-key> --secret <aws-secret-key>\n\n      # download files and remove everything that is not remote\n      s3-meta-sync <bucket:folder> <local> # no credentials required\n\n      Key and secret can also be supplied using AWS_ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY\n\n      Options:\n    BANNER\n    opts.on(\"-k\", \"--key KEY\", \"AWS access key\") { |c| options[:key] = c }\n    opts.on(\"-s\", \"--secret SECRET\", \"AWS secret key\") { |c| options[:secret] = c }\n    opts.on(\"-r\", \"--region REGION\", \"AWS region if not us-standard\") { |c| options[:region] = c }\n    opts.on(\"-p\", \"--parallel COUNT\", Integer, \"Use COUNT threads for download/upload default: 10\") { |c| options[:parallel] = c }\n    opts.on(\"-V\", \"--verbose\", \"Verbose mode\"){ options[:verbose] = true }\n    opts.on(\"-h\", \"--help\", \"Show this.\") { puts opts; exit }\n    opts.on(\"-v\", \"--version\", \"Show Version\"){ puts VERSION; exit}\n  end.parse!(argv)\n\n  raise \"need source and destination\" unless argv.size == 2\n  raise \"need 1 local and 1 remote\" unless argv.select { |a| a.include?(\":\") }.size == 1\n  raise \"need credentials --key + --secret\" if argv.last.include?(\":\") and (not options[:key] or not options[:secret])\n\n  [*argv, options]\nend\n".gsub(/^ {10}/, "")

.run(argv) ⇒ Object



160
161
162
163
164
# File 'lib/s3_meta_sync.rb', line 160

def run(argv)
  source, dest, options = parse_options(argv)
  Syncer.new(options).sync(source, dest)
  0
end