Skip to content
Brian D. Burns edited this page Mar 16, 2012 · 2 revisions

Storage Cycling

Each Storage (except for RSync) supports the keep setting, which specifies how many backups to keep at this location.

store_with SFTP do |sftp|
  sftp.keep = 5
end

Once the keep limit has been reached, the oldest backup will be removed.

Note that if keep is set to 5, then the 6th backup will be transferred and stored, before the oldest is removed.

Storage Identifiers

Each storage supports the ability to specify a string to uniquely identify that specific storage. This allows you to use multiple storages of the same type, with each tracking it's own cycling data.

For example, to store your backup to 2 different servers using SFTP, you could do:

Backup::Model.new(:my_backup, 'My Backup') do

  archive :my_archive do |archive|
    # archive some stuff...
  end

  store_with SFTP, 'Server #1' do |sftp|
    sftp.username = 'my_username'
    sftp.password = 'my_password'
    sftp.ip       = 'server1.domain.com'
    sftp.port     = 22
    sftp.path     = '~/backups/'
    sftp.keep     = 10
  end

  store_with SFTP, 'Server #2' do |sftp|
    sftp.username = 'my_username'
    sftp.password = 'my_password'
    sftp.ip       = 'server2.domain.com'
    sftp.port     = 22
    sftp.path     = '~/backups/'
    sftp.keep     = 5
  end

end

Server #1 will keep/cycle the last 10 backups, and Server #2 the last 5. So you always have your last 5 backups stored at 2 different locations.

What this does is store 2 different YAML cycling data files.

Instead of storing this data in data_path/SFTP.yml, as it would if no string identifier is used, it stores each location's data seperately in data_path/SFTP-Server__1.yml and data_path/SFTP-Server__2.yml.

Note that this identifier has nothing to do with the physical location.

Let's say you have a daily backup Monday thru Saturday, and you'd like to keep 2 weeks worth of these. And you have a weekly backup which runs on Sunday, and would like to keep the last 5 of these. And... you want to keep all these in the same physical location.

You could setup the following:

Backup::Storage::SFTP.defaults do |sftp|
  sftp.username = 'my_username'
  sftp.password = 'my_password'
  sftp.ip       = '123.45.678.90'
  sftp.port     = 22
  sftp.path     = '~/backups/'
end

Backup::Model.new(:my_daily, 'My Daily Backup') do

  archive :my_archive do |archive|
    # archive some stuff...
  end

  store_with SFTP, 'Daily' do |sftp|
    sftp.keep = 12
  end

end

Backup::Model.new(:my_weekly, 'My Weekly Backup') do

  archive :my_archive do |archive|
    # archive some stuff...
  end

  store_with SFTP, 'Weekly' do |sftp|
    sftp.keep = 5
  end

end

# Then, use Whenever to schedule the backups:

%w{ mon tue wed thu fri sat }.each do |day|
  every day, :at => '4:30am' do
    command 'backup perform -t my_daily'
  end
end

every :sun, :at => '4:30am' do
  command 'backup perform -t my_weekly'
end

So, even though both jobs will store their backups in the same location, they will be cycling their respective backups seperately. The Daily backups will be tracked in data_path/SFTP-Daily.yml, and the Weekly backups will be tracked in data_path/SFTP-Weekly.yml.

Clone this wiki locally