Class: Backup::Syncer::S3
Instance Attribute Summary collapse
-
#access_key_id ⇒ Object
Amazon Simple Storage Service (S3) Credentials.
-
#additional_options ⇒ Object
Additional options for the s3sync cli.
-
#bucket ⇒ Object
Amazon S3 bucket name and path to sync to.
-
#directories(&block) ⇒ Object
Syntactical suger for the DSL for adding directories.
-
#mirror ⇒ Object
Returns S3Sync syntax for enabling mirroring.
-
#path ⇒ Object
Amazon S3 bucket name and path to sync to.
-
#secret_access_key ⇒ Object
Amazon Simple Storage Service (S3) Credentials.
Instance Method Summary collapse
-
#add(path) ⇒ Object
Adds a path to the @directories array.
-
#initialize(&block) ⇒ S3
constructor
Instantiates a new S3 Syncer object and sets the default configuration specified in the Backup::Configuration::Syncer::S3.
-
#options ⇒ Object
Returns all the specified S3Sync options, concatenated, ready for the CLI.
-
#perform! ⇒ Object
Performs the S3Sync operation First it’ll set the Amazon S3 credentials for S3Sync before invoking it, and once it’s finished syncing the files and directories to Amazon S3, it’ll unset these credentials (back to nil values).
-
#recursive ⇒ Object
Returns S3Sync syntax for syncing recursively.
-
#set_s3sync_credentials! ⇒ Object
In order for S3Sync to know what credentials to use, we have to set the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables, these evironment variables will be used by S3Sync.
-
#unset_s3sync_credentials! ⇒ Object
Sets the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY back to nil.
-
#verbose ⇒ Object
Returns S3Sync syntax for making output verbose.
Methods included from Configuration::Helpers
#clear_defaults!, #getter_methods, #load_defaults!, #setter_methods
Methods included from CLI
Constructor Details
#initialize(&block) ⇒ S3
Instantiates a new S3 Syncer object and sets the default configuration specified in the Backup::Configuration::Syncer::S3. Then it sets the object defaults if particular properties weren’t set. Finally it’ll evaluate the users configuration file and overwrite anything that’s been defined
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/backup/syncer/s3.rb', line 32 def initialize(&block) load_defaults! @path ||= 'backups' @directories ||= Array.new @mirror ||= false ||= [] instance_eval(&block) if block_given? @path = path.sub(/^\//, '') end |
Instance Attribute Details
#access_key_id ⇒ Object
Amazon Simple Storage Service (S3) Credentials
9 10 11 |
# File 'lib/backup/syncer/s3.rb', line 9 def access_key_id @access_key_id end |
#additional_options ⇒ Object
Additional options for the s3sync cli
25 26 27 |
# File 'lib/backup/syncer/s3.rb', line 25 def end |
#bucket ⇒ Object
Amazon S3 bucket name and path to sync to
13 14 15 |
# File 'lib/backup/syncer/s3.rb', line 13 def bucket @bucket end |
#directories(&block) ⇒ Object
Syntactical suger for the DSL for adding directories
17 18 19 |
# File 'lib/backup/syncer/s3.rb', line 17 def directories @directories end |
#mirror ⇒ Object
Returns S3Sync syntax for enabling mirroring
21 22 23 |
# File 'lib/backup/syncer/s3.rb', line 21 def mirror @mirror end |
#path ⇒ Object
Amazon S3 bucket name and path to sync to
13 14 15 |
# File 'lib/backup/syncer/s3.rb', line 13 def path @path end |
#secret_access_key ⇒ Object
Amazon Simple Storage Service (S3) Credentials
9 10 11 |
# File 'lib/backup/syncer/s3.rb', line 9 def secret_access_key @secret_access_key end |
Instance Method Details
#add(path) ⇒ Object
Adds a path to the @directories array
94 95 96 |
# File 'lib/backup/syncer/s3.rb', line 94 def add(path) @directories << path end |
#options ⇒ Object
Returns all the specified S3Sync options, concatenated, ready for the CLI
63 64 65 |
# File 'lib/backup/syncer/s3.rb', line 63 def ([verbose, recursive, mirror] + ).compact.join("\s") end |
#perform! ⇒ Object
Performs the S3Sync operation First it’ll set the Amazon S3 credentials for S3Sync before invoking it, and once it’s finished syncing the files and directories to Amazon S3, it’ll unset these credentials (back to nil values)
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/backup/syncer/s3.rb', line 50 def perform! set_s3sync_credentials! directories.each do |directory| Logger.("#{ self.class } started syncing '#{ directory }'.") Logger.silent( run("#{ utility(:s3sync) } #{ options } '#{ directory }' '#{ bucket }:#{ path }'") ) end unset_s3sync_credentials! end |
#recursive ⇒ Object
Returns S3Sync syntax for syncing recursively
75 76 77 |
# File 'lib/backup/syncer/s3.rb', line 75 def recursive '--recursive' end |
#set_s3sync_credentials! ⇒ Object
In order for S3Sync to know what credentials to use, we have to set the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables, these evironment variables will be used by S3Sync
102 103 104 105 |
# File 'lib/backup/syncer/s3.rb', line 102 def set_s3sync_credentials! ENV['AWS_ACCESS_KEY_ID'] = access_key_id ENV['AWS_SECRET_ACCESS_KEY'] = secret_access_key end |
#unset_s3sync_credentials! ⇒ Object
Sets the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY back to nil
109 110 111 112 |
# File 'lib/backup/syncer/s3.rb', line 109 def unset_s3sync_credentials! ENV['AWS_ACCESS_KEY_ID'] = nil ENV['AWS_SECRET_ACCESS_KEY'] = nil end |
#verbose ⇒ Object
Returns S3Sync syntax for making output verbose
81 82 83 |
# File 'lib/backup/syncer/s3.rb', line 81 def verbose '--verbose' end |