Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backup s3 keep not working #751

Closed
heldopslippers opened this issue Mar 11, 2016 · 35 comments
Closed

Backup s3 keep not working #751

heldopslippers opened this issue Mar 11, 2016 · 35 comments
Assignees
Labels

Comments

@heldopslippers
Copy link

Hi Guys,

Trying it with 4.2.2 and 4.2.3.
keep doesn't seem to work with S3 (didn't try it with other adapters).

Anybody else have the same problems?

store_with S3 do |s3|
    s3.keep = 5
    s3.access_key_id = "******"
    s3.secret_access_key = "*****"
    s3.region = "eu-west-1"
    s3.bucket = "****"
    s3.path = "******"
  end
@nahidnascenia
Copy link

Hi
I have the same issue with Local storage. It seems keep function is not working.
'gem 'backup', require: false'
It installed V3.4.0 using command 'bundle install'

store_with Local do |local|
    local.path = "~/backups/#{ENV['RAILS_ENV']}_db_backup"
    local.keep = 10
end

@tombruijn
Copy link
Member

Hi @heldopslippers and @nahidnascenia, that doesn't seem right. Can you try version 4.2.0? That's before I reworked the keep option a bit. See if that works? If so, I can narrow the issue down

@heldopslippers
Copy link
Author

Ok this is weird, just tested it with 4.2.0.
Works like a charm!
But I am not sure if 4.2.2 didn't work though!

@benortiz
Copy link

I'm having this same problem on s3 with a daily/weekly/monthly backup. Daily backups are duplicating and weekly backups are only keeping 1. I haven't run it long enough to see what happens on month 2.

# Backup Schedule
time = Time.now
if time.day == 1  # first day of the month
  storage_id = :monthly
  keep = 12
elsif time.sunday?
  storage_id = :weekly
  keep = 4
else
  storage_id = :daily
  keep = 27
end

store_with S3 do |s3|
  s3.access_key_id = AWS_ID
  s3.secret_access_key = AWS_KEY
  s3.region            = AWS_REGION
  s3.bucket            = AWS_BUCKET
  s3.path              = "/#{ storage_id }"
  s3.keep              = keep
end

And this runs daily from a whenever crontab with: backup perform -t db_backup --config-file /home/deploy/OppSites/releases/RELEASE_PATH/config/backup/config.rb

Backup version: Backup 4.2.3

I can make a new issue if that's appropriate, but it seems to be a similar issue. I haven't tried 4.2.0, is that really the solution to this problem?

@tombruijn
Copy link
Member

@benortiz yes, it might be caused by a recent update. Please try the 4.2.0 version. It it still happens I know if both problems are caused by it

@benortiz
Copy link

@tombruijn thanks! I fixed the duplication problem, that was my mistake (I had it deployed to two separate servers). I'll try 4.2.0 to see if that fixes the weekly backup.

@benortiz
Copy link

@tombruijn Using 4.2.0 I get an error for the reply_to method: NoMethodError: undefined methodreply_to=' for #Backup::Notifier::Mail:0x00000002eb7e48`

My config for mail looks like this

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

    mail.from                 = "from-address@oppsites.com"
    mail.to                   = "my-email-address@domain.com"
    mail.reply_to             = "from-address@oppsites.com"
    mail.address              = MAIL_CONFIG['mailer_no_reply']['address']
    mail.port                 = MAIL_CONFIG['mailer_no_reply']['port']
    mail.domain               = MAIL_CONFIG['mailer_no_reply']['domain']
    mail.user_name            = MAIL_CONFIG['mailer_no_reply']['user_name']
    mail.password             = MAIL_CONFIG['mailer_no_reply']['password']
    mail.authentication       = "plain"
    mail.encryption           = :starttls
  end

@tombruijn
Copy link
Member

@benortiz sorry about that, that option was only added in 4.2.1, see PR #707

@benortiz
Copy link

@tombruijn Ah okay, so should I be using 4.2.1 then? or 4.2.0 and remove the reply_to line?

@tombruijn
Copy link
Member

either option works (sorry for the delayed response)

@tteurs
Copy link

tteurs commented Aug 25, 2016

i'm Using gem 4.3 still not working keep on s3
[2016/08/25 17:07:58][error] NoMethodError: undefined method `keep=' for #Backup::Syncer::Cloud::S3:0x007f451a684e60

@tombruijn
Copy link
Member

That's because it's not made to work on syncers, only storage.

@bouchard
Copy link

bouchard commented Oct 4, 2016

I have this same issue with S3 - keep seems to be ignored. I currently have 42 daily backups, here is a sanitized copy of my config (Backup version 4.3.0):

Backup::Model.new(:pr, 'Backup the database.') do
  require 'yaml'
  db = YAML.load_file(File.expand_path('../config/database.yml', File.dirname(__FILE__)))
  s3 = YAML.load_file(File.expand_path('../config/backup-secrets.yml', File.dirname(__FILE__)))

  database PostgreSQL do |d|
    d.name                = db['production']['database']
    d.username            = db['production']['username']
    d.password            = db['production']['password']
    d.host                = db['production']['host']
  end

  compress_with Bzip2

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

  time = Time.now
  if time.day == 1
    storage_id = :monthly
    keep = 12
  elsif time.sunday?
    storage_id = :weekly
    keep = 4
  else
    storage_id = :daily
    keep = 7
  end

  store_with S3 do |s|
    s.access_key_id       = s3['access_key_id']
    s.secret_access_key   = s3['secret_access_key']
    s.bucket              = 'backups.example.com'
    s.path                = storage_id.to_s
    s.fog_options         = { path_style: true }
    s.region              = 'us-east-1'
    s.keep                = keep
    s.encryption          = :aes256
  end

  notify_by Mail do |mail|
    mail.delivery_method  = :sendmail
    mail.on_success       = true
    mail.on_failure       = true
    mail.on_warning       = true
    mail.from             = 'backups@example.com'
    mail.to               = 'brady@example.com'
  end
end

# * * * * * * * * * * * * * * * * * * * *
#        Do Not Edit Below Here.
# All Configuration Should Be Made Above.

##
# Load all models from the models directory.
Dir[File.join(File.dirname(Config.config_file), 'models', '*.rb')].each do |model|
  instance_eval(File.read(model))
end

@tombruijn
Copy link
Member

Can you try version 4.2.0? Does it still not work properly?

@bouchard
Copy link

bouchard commented Oct 5, 2016

Log below. It looks like 4.2.0 may work correctly (it removes the 6th oldest backup), but it does not trim older backups (a.k.a. if I have 42 backups in daily to begin with, backup 4.2.0 will add 1 / delete 1 each time so I always have 42 backups).

I think expected behaviour would be to truncate the folder to (in this case, 5) backups total for daily, etc.

n/backup perform -t pr --config_file config/backup.rb'
[2016/10/05 16:08:37][info] Performing Backup for 'Backup the PR database. (pr)'!
[2016/10/05 16:08:37][info] [ backup 4.2.0 : ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux] ]
[2016/10/05 16:08:37][info] Database::PostgreSQL Started...
[2016/10/05 16:08:37][info] Using Compressor::Bzip2 for compression.
[2016/10/05 16:08:37][info]   Command: '/bin/bzip2'
[2016/10/05 16:08:37][info]   Ext: '.bz2'
[2016/10/05 16:08:37][info] Database::PostgreSQL Finished!
[2016/10/05 16:08:37][info] Packaging the backup files...
[2016/10/05 16:08:37][info] Running system utility 'tar'...
[2016/10/05 16:08:37][info] tar:STDOUT: tar (GNU tar) 1.28
[2016/10/05 16:08:37][info] tar:STDOUT: Copyright (C) 2014 Free Software Foundation, Inc.
[2016/10/05 16:08:37][info] tar:STDOUT: License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
[2016/10/05 16:08:37][info] tar:STDOUT: This is free software: you are free to change and redistribute it.
[2016/10/05 16:08:37][info] tar:STDOUT: There is NO WARRANTY, to the extent permitted by law.
[2016/10/05 16:08:37][info] tar:STDOUT: 
[2016/10/05 16:08:37][info] tar:STDOUT: Written by John Gilmore and Jay Fenlason.
[2016/10/05 16:08:37][info] Using Encryptor::OpenSSL to encrypt the archive.
[2016/10/05 16:08:37][info] Packaging Complete!
[2016/10/05 16:08:37][info] Cleaning up the temporary files...
[2016/10/05 16:08:37][info] Storage::S3 Started...
[2016/10/05 16:08:37][info] Storing 'example.com/daily/pillrefill/2016.10.05.16.08.37/pillrefill.tar.enc'...
[2016/10/05 16:08:38][info] Cycling Started...
[2016/10/05 16:08:38][info] Removing backup package dated 2016.09.29.12.15.03...
[2016/10/05 16:08:38][info] Storage::S3 Finished!
[2016/10/05 16:08:38][info] Cleaning up the package files...
[2016/10/05 16:08:38][info] Backup for 'Backup the PR database. (pr)' Completed Successfully in 00:00:01
[2016/10/05 16:08:38][info] Sending notification using Notifier::Mail...
Got it, thanks!

@max-allan-surevine
Copy link

max-allan-surevine commented Nov 17, 2016

Is this still an expected issue with 4.3? It seems quite a fundamental problem. I am still seeing problems with 4.3.

[2016/11/17 13:15:21][info] Storage::Local (daily) Started...
[2016/11/17 13:15:21][info] Storing '
/var/localbackup/max.test/daily/test/2016.11.17.13.15.18/test.tar.gpg'...
[2016/11/17 13:15:21][info] Cycling Started...
[2016/11/17 13:15:21][info] Storage::Local (daily) Finished!
[2016/11/17 13:15:21][info] Cleaning up the package files...
[2016/11/17 13:15:21][warn] Backup for 'The daily backup (test)' Completed Successfully (with Warnings) in 00:00:03
[2016/11/17 13:15:21][info] Sending notification using Notifier::Mail...
[root@ip-10-66-2-145 models]# !ls
ls -la /var/localbackup/max.test/daily/test/ | wc
     25     218    1462
[root@ip-10-66-2-145 models]# grep local.keep test.rb 
    local.keep      = 11

I have 25 backups and I'm expecting only 11. If I use v 4.2.1 as suggested, I get the same problem (Actually 4.2.1 is missing from gem, 4.2.3 is present gem install backup -v '4.2.3', but the banner reports itself as 4.2.1 ... )

@stuartellis
Copy link
Contributor

@max-allan-surevine Please can you post the IAM policy permissions that the user has on the S3 bucket? By coincidence, I have seen an issue using keep with 4.3 on S3 this week. I haven't had time to fully investigate, but in that case the issue at least appears to be the effective permissions.

@bouchard
Copy link

Hey @stuartellis, as I posted previously above there seems to be a difference in function between 4.2 and 4.3. The bug was introduced between these two versions, and (this bug at least) occurs regardless of permissions.

@stuartellis
Copy link
Contributor

Thanks, @bouchard. I should be able to take a look this weekend.

@max-allan-surevine
Copy link

I was assuming there was a general issue with keep. Not limited to S3. But now I see it seems to be working fine on S3 but not on local files. @nahidnascenia mentioned the same issue above.
I will raise a new issue for it.
FYI @stuartellis the IAM role has full permissions! I think I need to fix that, thanks for the reminder!

rvalyi added a commit to akretion/simple-docker-backup that referenced this issue May 19, 2017
@stuartellis stuartellis self-assigned this Aug 31, 2017
@benben
Copy link

benben commented Nov 11, 2017

still a problem with 4.4.0

@stuartellis
Copy link
Contributor

Hello @benben - This ticket is getting a little confused. Would you mind opening a new ticket for your specific issue with 4.4.0 ? The ticket template specifies the information that we will need to reproduce your issue.

@ziaulrehman40
Copy link

This needs to be fixed, falling back to 4.2.0 is not an option for everyone because of this: #820 which is that installation of older versions fail on ruby 2.4+

@stale
Copy link

stale bot commented Nov 24, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 24, 2020
@ziaulrehman40
Copy link

bump, needs fix

@stale stale bot removed the stale label Nov 24, 2020
@stale
Copy link

stale bot commented Jan 23, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 23, 2021
@ziaulrehman40
Copy link

bump

@stale stale bot removed the stale label Jan 24, 2021
@stale
Copy link

stale bot commented Mar 25, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Mar 25, 2021
@stale stale bot closed this as completed Apr 9, 2021
@mcohen9
Copy link

mcohen9 commented Dec 6, 2021

still not working need fix

@elthariel
Copy link
Contributor

Feel free to send a merge request

@elthariel elthariel reopened this Dec 8, 2021
@stale stale bot removed the stale label Dec 8, 2021
@stale
Copy link

stale bot commented Feb 6, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Feb 6, 2022
@stale stale bot closed this as completed Feb 21, 2022
@h0jeZvgoxFepBQ2C
Copy link

lol this is still open, I was wondering why we have 90 TB of backups which we have to pay for, just to find out that instead of 24 hourly backups we have 6000. lol.

@h0jeZvgoxFepBQ2C
Copy link

/reopen

@h0jeZvgoxFepBQ2C
Copy link

I guess the reason is that the S3 Storage class doesn't implement the cycle method?

if respond_to?(:cycle!, true) && (keep.to_i > 0 || keep.is_a?(Time))
or am I wrong?

We should at least throw an exception if keep is set, but keep not supported? This error has probalby cost us around 60k EUR (also fault of us due to not noticing it over the last years).

@max-allan-surevine
Copy link

@h0jeZvgoxFepBQ2C I don't think cycler gets called directly, it runs something else which then uses "remove" in the S3 code:

# Called by the Cycler.

But it's a long time since I looked at this project!
IIRC I found a clash between some other storage class (local files) that was resetting the keep flag for no apparent reason. And if you used local files and S3, only local files would cycle properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests