Class: S3Rotate::BackupManager

Inherits:
Object
  • Object
show all
Defined in:
lib/s3_rotate/core/backup_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, secret, bucket, region) ⇒ Object

Initialize a new BackupManager instance.

Parameters:

  • key

    String representing the AWS ACCESS KEY ID.

  • secret

    String representing the AWS ACCESS KEY SECRET.

  • bucket

    String representing the name of the bucket ot use.

  • region

    String representing the region to conect to.



23
24
25
26
27
# File 'lib/s3_rotate/core/backup_manager.rb', line 23

def initialize(key, secret, bucket, region)
  @s3_client = S3Client.new(key, secret, bucket, region)
  @uploader  = BackupUploader.new(@s3_client)
  @rotator   = BackupRotator.new(@s3_client)
end

Instance Attribute Details

#rotatorObject

Returns the value of attribute rotator.



11
12
13
# File 'lib/s3_rotate/core/backup_manager.rb', line 11

def rotator
  @rotator
end

#s3_clientObject

attributes



9
10
11
# File 'lib/s3_rotate/core/backup_manager.rb', line 9

def s3_client
  @s3_client
end

#uploaderObject

Returns the value of attribute uploader.



10
11
12
# File 'lib/s3_rotate/core/backup_manager.rb', line 10

def uploader
  @uploader
end

Instance Method Details

#rotate(backup_name, local_backups_dir, max_local = 3, max_daily = 7, max_weekly = 4, max_monthly = 3) ⇒ Object

Rotate files (local, daily, weekly, monthly) and apply maximum limits for each type

Parameters:

  • backup_name

    String containing the name of the backup to rotate

  • local_backups_path

    String containing the path to the directory containing the backups

  • max_local (defaults to: 3)

    Integer specifying the maximum number of local backups to keep

  • max_daily (defaults to: 7)

    Integer specifying the maximum number of daily backups to keep

  • max_weekly (defaults to: 4)

    Integer specifying the maximum number of weekly backups to keep

  • max_monthly (defaults to: 3)

    Integer specifying the maximum number of monthly backups to keep

Returns:

  • nothing



57
58
59
# File 'lib/s3_rotate/core/backup_manager.rb', line 57

def rotate(backup_name, local_backups_dir, max_local=3, max_daily=7, max_weekly=4, max_monthly=3)
  @rotator.rotate(backup_name, local_backups_dir, max_local, max_daily, max_weekly, max_monthly)
end

#upload(backup_name, local_backups_path, date_regex = /\d{4}-\d{2}-\d{2}/, date_format = "%Y-%m-%d") ⇒ 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

Parameters:

  • backup_name

    String containing the name of the backup to upload

  • local_backups_path

    String containing the path to the directory containing the backups

  • date_regex (defaults to: /\d{4}-\d{2}-\d{2}/)

    Regex returning the date contained in the filename of each backup

  • date_format (defaults to: "%Y-%m-%d")

    Format to be used by DateTime.strptime to parse the extracted date

Returns:

  • nothing



41
42
43
# File 'lib/s3_rotate/core/backup_manager.rb', line 41

def upload(backup_name, local_backups_path, date_regex=/\d{4}-\d{2}-\d{2}/, date_format="%Y-%m-%d")
  @uploader.upload(backup_name, local_backups_path, date_regex, date_format)
end