Class: S3Backup
- Inherits:
-
Object
- Object
- S3Backup
- Defined in:
- lib/s3-backup/base.rb
Instance Attribute Summary collapse
-
#backup_name ⇒ Object
Prefix for tarball, defaults to “backup”.
-
#bucket_name ⇒ Object
readonly
Name of bucket to push to, set on initialize.
-
#copies_to_keep ⇒ Object
Number of backups to keep on S3.
-
#files ⇒ Object
Array of files or paths to back up.
-
#files_to_cleanup ⇒ Object
Array of files that will be deleted post-backup, regardless of success.
-
#tar_excludes ⇒ Object
Array of exclude patterns, these are passed to tar as
--exclude
flags.
Instance Method Summary collapse
-
#after_backup(&block) ⇒ Object
Called after backup runs.
-
#before_backup(&block) ⇒ Object
Called before backup runs.
-
#initialize(bucket_name) ⇒ S3Backup
constructor
Initialize with the name of S3 bucket to push to.
-
#run ⇒ Object
Runs the backup: creates tarball, pushes to s3, and rotates old backups.
Constructor Details
#initialize(bucket_name) ⇒ S3Backup
Initialize with the name of S3 bucket to push to
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/s3-backup/base.rb', line 22 def initialize(bucket_name) @files = [] @files_to_cleanup = [] @tar_excludes = [] @copies_to_keep = 5 @bucket_name = bucket_name @backup_name = 'backup' @s3 = RightAws::S3.new(AWSCredentials.access_key, AWSCredentials.secret_access_key, :logger => Logger.new(nil)) end |
Instance Attribute Details
#backup_name ⇒ Object
Prefix for tarball, defaults to “backup”.
16 17 18 |
# File 'lib/s3-backup/base.rb', line 16 def backup_name @backup_name end |
#bucket_name ⇒ Object (readonly)
Name of bucket to push to, set on initialize.
19 20 21 |
# File 'lib/s3-backup/base.rb', line 19 def bucket_name @bucket_name end |
#copies_to_keep ⇒ Object
Number of backups to keep on S3. Defaults to 5.
13 14 15 |
# File 'lib/s3-backup/base.rb', line 13 def copies_to_keep @copies_to_keep end |
#files ⇒ Object
Array of files or paths to back up
4 5 6 |
# File 'lib/s3-backup/base.rb', line 4 def files @files end |
#files_to_cleanup ⇒ Object
Array of files that will be deleted post-backup, regardless of success
7 8 9 |
# File 'lib/s3-backup/base.rb', line 7 def files_to_cleanup @files_to_cleanup end |
#tar_excludes ⇒ Object
Array of exclude patterns, these are passed to tar as --exclude
flags
10 11 12 |
# File 'lib/s3-backup/base.rb', line 10 def tar_excludes @tar_excludes end |
Instance Method Details
#after_backup(&block) ⇒ Object
Called after backup runs. Useful for restarting services.
41 42 43 |
# File 'lib/s3-backup/base.rb', line 41 def after_backup &block @after_backup = block end |
#before_backup(&block) ⇒ Object
Called before backup runs. Useful for dumping a database, or creating files prior to tarball create. As you create tmpfiles, you can push onto files_to_cleanup to ensure post-backup cleanup.
36 37 38 |
# File 'lib/s3-backup/base.rb', line 36 def before_backup &block @before_backup = block end |
#run ⇒ Object
Runs the backup: creates tarball, pushes to s3, and rotates old backups.
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/s3-backup/base.rb', line 46 def run begin @before_backup.call unless @before_backup.nil? create_tarball push_to_s3 rotate_remote_backups @after_backup.call unless @after_backup.nil? ensure cleanup_files end end |