databacker / mysql-backup

image to enable automated backups of mysql databases in containers
643 stars 180 forks source link

Please provide an option to keep at most x number of backups #48

Open AndrewBedscastle opened 6 years ago

AndrewBedscastle commented 6 years ago

Hi, it would be nice to be able to specify a number of backups to keep, oldest backups should be removed automatically.

Best regards Andreas

deitch commented 6 years ago

It is a good idea @AndrewBedscastle , and has been discussed before. Since this runs in an infinite loop, it might be able to prune them as part of its loop.

On the other hand, it makes it do "one more thing", which may not be desired.

I don't object though, since it always will be optional. Open a PR for it, including tests?

michabbb commented 5 years ago

@AndrewBedscastle i had the same idea but a simple "find rm" solves that problem for most cases. i guess (never tested) it should also work with /scripts.d/pre-backup or /scripts.d/post-backup

Bessonov commented 5 years ago

Workaround for S3 users:

  1. Create versioned bucket with expiration:
    Resources:
    BackupServiceS3Bucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: backup
      VersioningConfiguration:
        Status: Enabled
      LifecycleConfiguration:
        Rules:
          # clean up old unfinished uploads
          - AbortIncompleteMultipartUpload:
              DaysAfterInitiation: 7
            Status: Enabled
          # hold removed files for 14 days
          - NoncurrentVersionExpirationInDays: 14
            Status: Enabled
  2. Set static name for backup:
apiVersion: v1
kind: ConfigMap 
metadata:
  name: backup
data:
  target.sh: |
    #!/bin/bash
    echo "backup.tgz"
[...]
            volumeMounts:
            - name: backup
              mountPath: /scripts.d/target.sh
              subPath: target.sh

Now, backup file is overridden on every backup and old versions are away after 14 days. You can get not expired backups through console or api.

achims311 commented 5 years ago

There is a quite nice utility to implement this cronicle. At least for file backups this should work. requires python

Akruidenberg commented 5 years ago

What's the progress of this feature?

deitch commented 5 years ago

No one has offered a PR yet.

achims311 commented 5 years ago

PR?

michabbb commented 5 years ago

@achims311 https://help.github.com/en/articles/about-pull-requests

j-flowers commented 3 years ago

I put a pull request in to limit the number of days a backup is kept.

https://github.com/databacker/mysql-backup/pull/149