Module: Backupsss

Defined in:
lib/backupsss.rb,
lib/backupsss/tar.rb,
lib/backupsss/backup.rb,
lib/backupsss/janitor.rb,
lib/backupsss/version.rb,
lib/backupsss/backup_dir.rb,
lib/backupsss/backup_bucket.rb,
lib/backupsss/configuration.rb,
lib/backupsss/removal_error.rb

Overview

A utility for backing things up to S3.

Defined Under Namespace

Classes: Backup, BackupBucket, BackupDir, Configuration, Janitor, RemovalError, Tar

Constant Summary collapse

VERSION =
'0.1.1'.freeze

Class Method Summary collapse

Class Method Details

.callObject



18
19
20
21
22
# File 'lib/backupsss.rb', line 18

def call
  push_backup(*prep_for_backup)
  cleanup_local
  cleanup_remote
end

.cleanup_localObject



48
49
50
51
52
53
# File 'lib/backupsss.rb', line 48

def cleanup_local
  local_janitor = Janitor.new(
    driver: BackupDir.new(dir: config.backup_dest_dir)
  )
  local_janitor.rm_garbage(local_janitor.sift_trash)
end

.cleanup_remoteObject



55
56
57
58
59
60
61
62
63
64
# File 'lib/backupsss.rb', line 55

def cleanup_remote
  remote_janitor = Janitor.new(
    driver: BackupBucket.new(
      dir: "#{config.s3_bucket}/#{config.s3_bucket_prefix}",
      region: config.aws_region
    ),
    retention_count: config.remote_retention
  )
  remote_janitor.rm_garbage(remote_janitor.sift_trash)
end

.configObject



14
15
16
# File 'lib/backupsss.rb', line 14

def config
  @config ||= Backupsss::Configuration.new
end

.prep_for_backupObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/backupsss.rb', line 24

def prep_for_backup
  filename = "#{Time.now.to_i}.tar"
  backup   = Backupsss::Backup.new(
    {
      s3_bucket_prefix: config.s3_bucket_prefix,
      s3_bucket:        config.s3_bucket,
      filename:         filename
    }, Aws::S3::Client.new(region: config.aws_region)
  )

  [filename, backup]
end

.push_backup(filename, backup) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/backupsss.rb', line 37

def push_backup(filename, backup)
  puts 'Create and Upload Tar: Starting'
  backup.put_file(
    Backupsss::Tar.new(
      config.backup_src_dir,
      "#{config.backup_dest_dir}/#{filename}"
    ).make
  )
  puts 'Create and Upload Tar: Finished'
end

.runObject



66
67
68
69
70
71
72
# File 'lib/backupsss.rb', line 66

def run
  scheduler = Rufus::Scheduler.new
  scheduler.cron(config.backup_freq, blocking: true) do
    call
  end
  scheduler.join
end