Class: S3Rotate::BackupUploader
- Inherits:
-
Object
- Object
- S3Rotate::BackupUploader
- Defined in:
- lib/s3_rotate/core/backup_uploader.rb
Overview
BackupUploader Class Handles backup uploads with the right format
Instance Attribute Summary collapse
-
#s3_client ⇒ Object
attributes.
Instance Method Summary collapse
-
#initialize(s3_client) ⇒ Object
constructor
Initialize a new BackupUploader instance.
-
#upload(backup_name, local_backups_path, date_regex = /\d{4}-\d{2}-\d{2}/) ⇒ Object
Upload local backup files to AWS S3 Only uploads new backups Only uploads backups as daily backups: use ‘rotate` to generate the weekly & monthly files.
Constructor Details
#initialize(s3_client) ⇒ Object
Initialize a new BackupUploader instance.
22 23 24 |
# File 'lib/s3_rotate/core/backup_uploader.rb', line 22 def initialize(s3_client) @s3_client = s3_client end |
Instance Attribute Details
#s3_client ⇒ Object
attributes
13 14 15 |
# File 'lib/s3_rotate/core/backup_uploader.rb', line 13 def s3_client @s3_client end |
Instance Method Details
#upload(backup_name, local_backups_path, date_regex = /\d{4}-\d{2}-\d{2}/) ⇒ Object
Upload local backup files to AWS S3 Only uploads new backups Only uploads backups as daily backups: use ‘rotate` to generate the weekly & monthly files
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/s3_rotate/core/backup_uploader.rb', line 37 def upload(backup_name, local_backups_path, date_regex=/\d{4}-\d{2}-\d{2}/) # get backup files local_backups = FileUtils::files_in_directory(local_backups_path).reverse # upload local backups until we find one backup already uploaded local_backups.each do |local_backup| # parse the date & extension backup_date = FileUtils::date_from_filename(local_backup, date_regex) backup_extension = FileUtils::extension_from_filename(local_backup) # skip invalid files next if not backup_date # stop uploading once we reach a file already uploaded break if @s3_client.exists?(backup_name, backup_date, "daily", extension=backup_extension) # upload file @s3_client.upload_local_backup_to_s3(backup_name, backup_date, "daily", backup_extension, File.open(local_backup)) end end |