diff options
author | Robert Helgesson <robert@rycee.net> | 2021-08-03 23:04:48 +0200 |
---|---|---|
committer | Robert Helgesson <robert@rycee.net> | 2021-08-05 00:42:16 +0200 |
commit | bcc7a902d58555306065f62032be9fb991f906e3 (patch) | |
tree | d37e4519b6095a1ac11415c362979ff2282c3f8d /nixos/tests/postgresql.nix | |
parent | 4393d15463f76d437ce64e914e4e403898538c76 (diff) |
nixos postgresql-backup: add `compression` option
This option allows basic configuration of the compression technique used in the backup script. Specifically it adds `none` and `zstd` as new alternatives, keeping `gzip` as the default.
Diffstat (limited to 'nixos/tests/postgresql.nix')
-rw-r--r-- | nixos/tests/postgresql.nix | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/nixos/tests/postgresql.nix b/nixos/tests/postgresql.nix index 0369a07071901..4e5f921696711 100644 --- a/nixos/tests/postgresql.nix +++ b/nixos/tests/postgresql.nix @@ -43,6 +43,7 @@ let testScript = let backupName = if backup-all then "all" else "postgres"; backupService = if backup-all then "postgresqlBackup" else "postgresqlBackup-postgres"; + backupFileBase = "/var/backup/postgresql/${backupName}"; in '' def check_count(statement, lines): return 'test $(sudo -u postgres psql postgres -tAc "{}"|wc -l) -eq {}'.format( @@ -72,9 +73,32 @@ let with subtest("Backup service works"): machine.succeed( "systemctl start ${backupService}.service", - "zcat /var/backup/postgresql/${backupName}.sql.gz | grep '<test>ok</test>'", + "zcat ${backupFileBase}.sql.gz | grep '<test>ok</test>'", "ls -hal /var/backup/postgresql/ >/dev/console", - "stat -c '%a' /var/backup/postgresql/${backupName}.sql.gz | grep 600", + "stat -c '%a' ${backupFileBase}.sql.gz | grep 600", + ) + with subtest("Backup service removes prev files"): + machine.succeed( + # Create dummy prev files. + "touch ${backupFileBase}.prev.sql{,.gz,.zstd}", + "chown postgres:postgres ${backupFileBase}.prev.sql{,.gz,.zstd}", + + # Run backup. + "systemctl start ${backupService}.service", + "ls -hal /var/backup/postgresql/ >/dev/console", + + # Since nothing has changed in the database, the cur and prev files + # should match. + "zcat ${backupFileBase}.sql.gz | grep '<test>ok</test>'", + "cmp ${backupFileBase}.sql.gz ${backupFileBase}.prev.sql.gz", + + # The prev files with unused suffix should be removed. + "[ ! -f '${backupFileBase}.prev.sql' ]", + "[ ! -f '${backupFileBase}.prev.sql.zstd' ]", + + # Both cur and prev file should only be accessible by the postgres user. + "stat -c '%a' ${backupFileBase}.sql.gz | grep 600", + "stat -c '%a' '${backupFileBase}.prev.sql.gz' | grep 600", ) with subtest("Backup service fails gracefully"): # Sabotage the backup process @@ -84,8 +108,8 @@ let ) machine.succeed( "ls -hal /var/backup/postgresql/ >/dev/console", - "zcat /var/backup/postgresql/${backupName}.prev.sql.gz | grep '<test>ok</test>'", - "stat /var/backup/postgresql/${backupName}.in-progress.sql.gz", + "zcat ${backupFileBase}.prev.sql.gz | grep '<test>ok</test>'", + "stat ${backupFileBase}.in-progress.sql.gz", ) # In a previous version, the second run would overwrite prev.sql.gz, # so we test a second run as well. @@ -93,8 +117,8 @@ let "systemctl start ${backupService}.service", ) machine.succeed( - "stat /var/backup/postgresql/${backupName}.in-progress.sql.gz", - "zcat /var/backup/postgresql/${backupName}.prev.sql.gz | grep '<test>ok</test>'", + "stat ${backupFileBase}.in-progress.sql.gz", + "zcat ${backupFileBase}.prev.sql.gz | grep '<test>ok</test>'", ) |