NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.77k stars 13.88k forks source link

RFC: mysqlBackup / postgresqlBackup filename patterns #27267

Open mguentner opened 7 years ago

mguentner commented 7 years ago

I am using both services to make (easy) backups of DBs, mostly within containers. For some databases it is interesting to keep a history, i.e. not overwriting the file.

Currently I am using this patch to have a unique name:

diff --git a/nixos/modules/services/backup/postgresql-backup.nix b/nixos/modules/services/backup/postgresql-backup.nix
index 4a5ebebc68..61b7934bac 100644
--- a/nixos/modules/services/backup/postgresql-backup.nix
+++ b/nixos/modules/services/backup/postgresql-backup.nix
@@ -9,7 +9,7 @@ let

   postgresqlBackupCron = db:
     ''
-      ${config.services.postgresqlBackup.period} root ${config.services.postgresql.package}/bin/pg_dump ${db} | ${gzip}/bin/gzip -c > ${location}/${db}.gz
+      ${config.services.postgresqlBackup.period} root ${config.services.postgresql.package}/bin/pg_dump ${db} | ${gzip}/bin/gzip -c > ${location}/${db}_$(date --iso-8601=minutes).gz
     '';

 in

I believe that this is useful for others as well, so I'd like to create a PR, but before I'd like to hear some opinions. My idea is to introduce services.postgresqlBackup.pattern which defaults to an empty string and if supplied will be appended so...

${config.services.postgresql.package}/bin/pg_dump ${db} | ${gzip}/bin/gzip -c > ${location}/${db}${optionalString (cfg.pattern != null) "_${cfg.pattern}"}.gz

This will however amass backups without deleting them. Some cleanup needs to be done manually or by another cronjob.

fadenb commented 7 years ago

I am currently doing something quite similiar. Perhaps the option to cleanup all but the last X backups should be included in the module?

mguentner commented 7 years ago

Deleting the last X backups is possible, however care must be taken that only backups of the respective module are removed by the script in this directory. Also for KISS reasons: if pattern = "$(date +%e)" a history of one month will be kept without any need for deletion.

stale[bot] commented 4 years ago

Thank you for your contributions.

This has been automatically marked as stale because it has had no activity for 180 days.

If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.

Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse.
  3. Ask on the #nixos channel on irc.freenode.net.