Module: S3MetaSync

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

Defined Under Namespace

Modules: Zip Classes: Syncer

Constant Summary collapse

RemoteWithoutMeta =
Class.new(StandardError)
RemoteCorrupt =
Class.new(StandardError)
META_FILE =
".s3-meta-sync"
CORRUPT_FILES_LOG =
"s3-meta-sync-corrupted.log"
VERSION =
"0.5.0"

Class Method Summary collapse

Class Method Details

.parse_options(argv) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/s3_meta_sync.rb', line 18

def parse_options(argv)
  options = {
    key: ENV["AWS_ACCESS_KEY_ID"],
    secret: ENV["AWS_SECRET_ACCESS_KEY"],
    zip: false,
  }
  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(\"--ssl-none\", \"Do not verify ssl certs\") { options[:ssl_none] = true }\n    opts.on(\"-z\", \"--zip\", \"Zip when uploading to save bandwidth\") { options[:zip] = true }\n    opts.on(\"--no-local-changes\", \"Do not md5 all the local files, they did not change\") { options[:no_local_changes] = true }\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



12
13
14
15
16
# File 'lib/s3_meta_sync.rb', line 12

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