generators/backup_files/templates/s3.rake in backup-1.1.0 vs generators/backup_files/templates/s3.rake in backup-1.2.0

- old
+ new

@@ -9,28 +9,52 @@ # If you wish to put specific files in subfolders inside the bucket, you may do so by doing something like this: # :bucket => "my_bucket/subfolder1/subfolder2" etc. desc 'Makes a backup from a MySQL database and transfers it to Amazon S3.' task :mysql => :s3_config do @config = @config['mysql'] - Backup::Adapter::Mysql.new({ - :adapter => 'mysql', - :mysql => { - :user => @config['mysql_config']['user'], - :password => @config['mysql_config']['password'], - :database => @config['mysql_config']['database'] - }, + unless @config.is_a?(Array) + Backup::Adapter::Mysql.new({ + :adapter => 'mysql', + :mysql => { + :user => @config['mysql_config']['user'], + :password => @config['mysql_config']['password'], + :database => @config['mysql_config']['database'] + }, - :encrypt => @config['encrypt'], - :keep_backups => @config['keep_backups'], + :encrypt => @config['encrypt'], + :keep_backups => @config['keep_backups'], - :use => :s3, - :s3 => { - :access_key_id => @config['s3']['access_key_id'], - :secret_access_key => @config['s3']['secret_access_key'], - :bucket => @config['s3']['bucket'] - } - }).run + :use => :s3, + :s3 => { + :access_key_id => @config['s3']['access_key_id'], + :secret_access_key => @config['s3']['secret_access_key'], + :bucket => @config['s3']['bucket'] + } + }).run + else + @config.each do |config| + Backup::Adapter::Mysql.new({ + :adapter => 'mysql', + :mysql => { + :user => config['mysql_config']['user'], + :password => config['mysql_config']['password'], + :database => config['mysql_config']['database'] + }, + + :encrypt => config['encrypt'], + :keep_backups => config['keep_backups'], + + :use => :s3, + :s3 => { + :access_key_id => config['s3']['access_key_id'], + :secret_access_key => config['s3']['secret_access_key'], + :bucket => config['s3']['bucket'] + } + }).run + sleep(1) + end + end end # => rake backup:s3:sqlite3 # Specify which sqlite3 file you wish to back up. This will generally be "production.sqlite3". (and this is the default, so you can remove the :file attribute if it is) # Specify that you want to use :s3 @@ -39,24 +63,44 @@ # If you wish to put specific files in subfolders inside the bucket, you may do so by doing something like this: # :bucket => "my_bucket/subfolder1/subfolder2" etc. desc 'Makes a backup from a SQLite3 database and transfers it to Amazon S3.' task :sqlite3 => :s3_config do @config = @config['sqlite3'] - Backup::Adapter::Sqlite3.new({ - :adapter => 'sqlite3', - :file => @config['file'], - :path => @config['path'], - :encrypt => @config['encrypt'], - :keep_backups => @config['keep_backups'], + unless @config.is_a?(Array) + Backup::Adapter::Sqlite3.new({ + :adapter => 'sqlite3', + :file => @config['file'], + :path => @config['path'], + :encrypt => @config['encrypt'], + :keep_backups => @config['keep_backups'], - :use => :s3, - :s3 => { - :access_key_id => @config['s3']['access_key_id'], - :secret_access_key => @config['s3']['secret_access_key'], - :bucket => @config['s3']['bucket'] - } - }).run + :use => :s3, + :s3 => { + :access_key_id => @config['s3']['access_key_id'], + :secret_access_key => @config['s3']['secret_access_key'], + :bucket => @config['s3']['bucket'] + } + }).run + else + @config.each do |config| + Backup::Adapter::Sqlite3.new({ + :adapter => 'sqlite3', + :file => config['file'], + :path => config['path'], + :encrypt => config['encrypt'], + :keep_backups => config['keep_backups'], + + :use => :s3, + :s3 => { + :access_key_id => config['s3']['access_key_id'], + :secret_access_key => config['s3']['secret_access_key'], + :bucket => config['s3']['bucket'] + } + }).run + sleep(1) + end + end end # => rake backup:s3:assets # Specify which directory (:path) (and all it's underlaying files and folders) you wish to backup. # Specify that you want to use :s3 @@ -65,23 +109,42 @@ # If you wish to put specific files in subfolders inside the bucket, you may do so by doing something like this: # :bucket => "my_bucket/subfolder1/subfolder2" etc. desc 'Makes a backup from Assets and transfers it to Amazon S3.' task :assets => :s3_config do @config = @config['assets'] - Backup::Adapter::Assets.new({ - :adapter => 'assets', - :path => @config['path'], - :encrypt => @config['encrypt'], - :keep_backups => @config['keep_backups'], + unless @config.is_a?(Array) + Backup::Adapter::Assets.new({ + :adapter => 'assets', + :path => @config['path'], + :encrypt => @config['encrypt'], + :keep_backups => @config['keep_backups'], - :use => :s3, - :s3 => { - :access_key_id => @config['s3']['access_key_id'], - :secret_access_key => @config['s3']['secret_access_key'], - :bucket => @config['s3']['bucket'] - } - }).run + :use => :s3, + :s3 => { + :access_key_id => @config['s3']['access_key_id'], + :secret_access_key => @config['s3']['secret_access_key'], + :bucket => @config['s3']['bucket'] + } + }).run + else + @config.each do |config| + Backup::Adapter::Assets.new({ + :adapter => 'assets', + :path => config['path'], + :encrypt => config['encrypt'], + :keep_backups => config['keep_backups'], + + :use => :s3, + :s3 => { + :access_key_id => config['s3']['access_key_id'], + :secret_access_key => config['s3']['secret_access_key'], + :bucket => config['s3']['bucket'] + } + }).run + sleep(1) + end + end end # => rake backup:s3:custom # This is a more complex implementation of the Backup gem. # Might you be using a database type that is currently not supported, then you can manually create an SQL dump @@ -117,23 +180,44 @@ # Just use the ":use => :s3" as usual to tell it you would like to back up these files using S3. # And then, like in the example below, provide the S3 credentials/details to be able to connect to the server you wish to back these files up to. desc 'Makes a backup from a Custom database and transfers it to Amazon S3.' task :custom => :s3_config do @config = @config['custom'] - Backup::Adapter::Custom.new({ - :adapter => 'custom', - :file => @config['file'], - :path => @config['path'], - :command => @config['command'], - :encrypt => @config['encrypt'], - :keep_backups => @config['keep_backups'], + unless @config.is_a?(Array) + Backup::Adapter::Custom.new({ + :adapter => 'custom', + :file => @config['file'], + :path => @config['path'], + :command => @config['command'], + :encrypt => @config['encrypt'], + :keep_backups => @config['keep_backups'], - :use => :s3, - :s3 => { - :access_key_id => @config['s3']['access_key_id'], - :secret_access_key => @config['s3']['secret_access_key'], - :bucket => @config['s3']['bucket'] - } - }).run + :use => :s3, + :s3 => { + :access_key_id => @config['s3']['access_key_id'], + :secret_access_key => @config['s3']['secret_access_key'], + :bucket => @config['s3']['bucket'] + } + }).run + else + @config.each do |config| + Backup::Adapter::Custom.new({ + :adapter => 'custom', + :file => config['file'], + :path => config['path'], + :command => config['command'], + :encrypt => config['encrypt'], + :keep_backups => config['keep_backups'], + + :use => :s3, + :s3 => { + :access_key_id => config['s3']['access_key_id'], + :secret_access_key => config['s3']['secret_access_key'], + :bucket => config['s3']['bucket'] + } + }).run + sleep(1) + end + end end end end \ No newline at end of file