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.1.3"

Class Method Summary collapse

Class Method Details

.parse_options(argv) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/s3_meta_sync.rb', line 140

def parse_options(argv)
  options = {}
  OptionParser.new do |opts|
    opts.banner = <<-BANNER.gsub(/^ {10}/, "")
      Sync folders with s3 using a metadata file with md5 sums.

      # upload local files and remove everything that is not local
      s3-meta-sync <local> <bucket:folder> --key <aws-access-key> --secret <aws-secret-key>

      # download files and remove everything that is not remote
      s3-meta-sync <bucket:folder> <local> # no credentials required


      Options:
    BANNER
    opts.on("-k", "--key KEY", "AWS access key") { |c| options[:key] = c }
    opts.on("-s", "--secret SECRET", "AWS secret key") { |c| options[:secret] = c }
    opts.on("-r", "--region REGION", "AWS region if not us-standard") { |c| options[:region] = c }
    opts.on("-p", "--parallel COUNT", Integer, "Use COUNT processes for download/upload default: 10") { |c| options[:parallel] = c }
    opts.on("-h", "--help", "Show this.") { puts opts; exit }
    opts.on("-v", "--version", "Show Version"){ puts VERSION; exit}
  end.parse!(argv)

  raise "need source and destination" unless argv.size == 2
  raise "need 1 local and 1 remote" unless argv.select { |a| a.include?(":") }.size == 1
  raise "need credentials --key + --secret" if argv.last.include?(":") and (not options[:key] or not options[:secret])

  [*argv, options]
end

.run(argv) ⇒ Object



134
135
136
137
138
# File 'lib/s3_meta_sync.rb', line 134

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