A
A
Anton Misyagin2018-02-14 12:42:50
ruby
Anton Misyagin, 2018-02-14 12:42:50

How to set the number of backup gems to keep?

To back up the database, I use the backup gem , which in ruby
​​is not possible to set the number of recent backups. The number is growing every day
backup.rb

require 'yaml'
db_config = YAML.load_file('/var/www/site/shared/config/database.yml')['production']
smtp_config = YAML.load_file('/var/www/site/shared/config/backup_smtp.yml')

Model.new(:backup, 'Backup [production]') do
  
  compress_with Gzip do |compression|
    compression.level = 6
  end

  encrypt_with OpenSSL do |encryption|
    encryption.password = 'simple-password'
    encryption.base64   = true
    encryption.salt     = true
  end

  database PostgreSQL, db_config['database'] do |db|
    db.name					= db_config['database']
    db.username				= db_config['username']
    db.password				= db_config['password']
    db.host					= db_config['host']
    db.port					= db_config['port']
    db.skip_tables			= []
    db.only_tables			= []
    db.additional_options	= []
  end

  notify_by Mail do |mail|
    mail.on_success		= true
    mail.on_failure		= true

    mail.from			= smtp_config['user']
    mail.to				= smtp_config['default_mail']
    mail.address		= smtp_config['server']
    mail.port			= smtp_config['port']
    mail.domain			= smtp_config['domain']
    mail.user_name		= smtp_config['user']
    mail.password		= smtp_config['password']
    mail.authentication	= smtp_config['authentication']
    mail.encryption		= :starttls
  end


  store_with Local do |local|
    local.path	= '/var/www/site/'
    local.keep	= 15
  end
end

[2018/02/13 23:10:01][info] Performing Backup for 'Backup [production] (backup)'!
[2018/02/13 23:10:01][info] [ backup 4.2.0 : ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux] ]
[2018/02/13 23:10:01][info] Database::PostgreSQL (site) Started...
[2018/02/13 23:10:01][info] Using Compressor::Gzip for compression.
[2018/02/13 23:10:01][info]   Command: '/bin/gzip -6'
[2018/02/13 23:10:01][info]   Ext: '.gz'
[2018/02/13 23:10:23][info] Database::PostgreSQL (site) Finished!
[2018/02/13 23:10:23][info] Creating Archive 'logs'...
[2018/02/13 23:10:23][info] Running system utility 'tar'...
[2018/02/13 23:10:23][info] tar:STDOUT: tar (GNU tar) 1.27.1
[2018/02/13 23:10:23][info] tar:STDOUT: Copyright (C) 2013 Free Software Foundation, Inc.
[2018/02/13 23:10:23][info] tar:STDOUT: License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
[2018/02/13 23:10:23][info] tar:STDOUT: This is free software: you are free to change and redistribute it.
[2018/02/13 23:10:23][info] tar:STDOUT: There is NO WARRANTY, to the extent permitted by law.
[2018/02/13 23:10:23][info] tar:STDOUT: 
[2018/02/13 23:10:23][info] tar:STDOUT: Written by John Gilmore and Jay Fenlason.
[2018/02/13 23:10:23][info] Using Compressor::Gzip for compression.
[2018/02/13 23:10:23][info]   Command: '/bin/gzip -6'
[2018/02/13 23:10:23][info]   Ext: '.gz'
[2018/02/13 23:10:28][info] Archive 'logs' Complete!
[2018/02/13 23:10:28][info] Packaging the backup files...
[2018/02/13 23:10:28][info] Using Encryptor::OpenSSL to encrypt the archive.
[2018/02/13 23:10:29][info] Packaging Complete!
[2018/02/13 23:10:29][info] Cleaning up the temporary files...
[2018/02/13 23:10:29][info] Storage::Local Started...
[2018/02/13 23:10:29][info] Storing '/var/www/site/backup/2018.02.13.23.10.01/backup.tar.enc'...
[2018/02/13 23:10:29][info] Cycling Started...
[2018/02/13 23:10:29][info] Storage::Local Finished!
[2018/02/13 23:10:29][info] Cleaning up the package files...
[2018/02/13 23:10:29][info] Backup for 'Backup [production] (backup)' Completed Successfully in 00:00:28
[2018/02/13 23:10:29][info] Sending notification using Notifier::Mail...

There is no response to local.keep = 15
and then:
[2018/02/13 23:10:29][info] Cycling Started...
But how successful is unclear. How to overcome?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Misyagin, 2018-02-15
@sunnmas

backup-4.2.0\lib\backup\storage\cycler.rb:

def cycle!
        Logger.info 'Cycling Started...'

        packages = yaml_load.unshift(package)
        Logger.info "packages.count: #{packages.count}"
        excess = packages.count - keep.to_i
        Logger.info "excess: #{excess}"

        if excess > 0
          packages.pop(excess).each do |pkg|
            Logger.info "pkg.time: #{pkg.time}"
            begin
              Logger.info "pkg.no_cycle: #{pkg.no_cycle}"
              remove!(pkg) unless pkg.no_cycle
            rescue => err
              Logger.warn Error.wrap(err, <<-EOS)
                There was a problem removing the following package:
                Trigger: #{pkg.trigger} :: Dated: #{pkg.time}
                Package included the following #{ pkg.filenames.count } file(s):
                #{ pkg.filenames.join("\n") }
              EOS
            end
          end
        end

        yaml_save(packages)
      end

[2018/02/15 10:12:26][info] Storing '/var/www/site/backup/2018.02.15.10.12.02/backup.tar.enc'...
[2018/02/15 10:12:27][info] Cycling Started...
[2018/02/15 10:12:27][info] packages.count: 1
[2018/02/15 10:12:27][info] excess: -14
[2018/02/15 10:12:27][info] Storage::Local Finished!
[2018/02/15 10:12:27][info] Cleaning up the package files...

For some reason, it sees only one backup ...
It turned out that every time the Local.yml file was deleted during the deployment. This file records which backups have already been made. In general, your cant.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question