bicep/{postgres,mysql}: move backups to /data

This commit is contained in:
h7x4
2026-01-29 13:41:06 +09:00
parent 25f2a13391
commit f08bd96b74
2 changed files with 20 additions and 7 deletions

View File

@@ -1,7 +1,7 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
let let
cfg = config.services.mysql; cfg = config.services.mysql;
backupDir = "/var/lib/mysql-backups"; backupDir = "/data/mysql-backups";
in in
{ {
# services.mysqlBackup = lib.mkIf cfg.enable { # services.mysqlBackup = lib.mkIf cfg.enable {
@@ -9,6 +9,12 @@ in
# location = "/var/lib/mysql-backups"; # location = "/var/lib/mysql-backups";
# }; # };
systemd.tmpfiles.settings."10-mysql-backups".${backupDir}.d = {
user = "mysql";
group = "mysql";
mode = "700";
};
services.rsync-pull-targets = lib.mkIf cfg.enable { services.rsync-pull-targets = lib.mkIf cfg.enable {
enable = true; enable = true;
locations.${backupDir} = { locations.${backupDir} = {
@@ -42,8 +48,7 @@ in
in '' in ''
set -eo pipefail set -eo pipefail
mysqldump --all-databases | gzip -c -9 --rsyncable > "${backupDir}/mysql-dump.sql.gz" mysqldump --all-databases | gzip -c -9 --rsyncable > "/var/lib/mysql-backups/mysql-dump.sql.gz"
''; '';
# NOTE: keep multiple backups and symlink latest one once we have more disk again # NOTE: keep multiple backups and symlink latest one once we have more disk again
@@ -63,7 +68,8 @@ in
IOSchedulingClass = "best-effort"; IOSchedulingClass = "best-effort";
IOSchedulingPriority = 7; IOSchedulingPriority = 7;
StateDirectory = [ (builtins.baseNameOf backupDir) ]; StateDirectory = [ "mysql-backups" ];
BindPaths = [ "${backupDir}:/var/lib/mysql-backups" ];
# TODO: hardening # TODO: hardening
}; };

View File

@@ -1,7 +1,7 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
let let
cfg = config.services.postgresql; cfg = config.services.postgresql;
backupDir = "/var/lib/postgresql-backups"; backupDir = "/data/postgresql-backups";
in in
{ {
# services.postgresqlBackup = lib.mkIf cfg.enable { # services.postgresqlBackup = lib.mkIf cfg.enable {
@@ -10,6 +10,12 @@ in
# backupAll = true; # backupAll = true;
# }; # };
systemd.tmpfiles.settings."10-postgresql-backups".${backupDir}.d = {
user = "postgres";
group = "postgres";
mode = "700";
};
services.rsync-pull-targets = lib.mkIf cfg.enable { services.rsync-pull-targets = lib.mkIf cfg.enable {
enable = true; enable = true;
locations.${backupDir} = { locations.${backupDir} = {
@@ -43,7 +49,7 @@ in
in '' in ''
set -eo pipefail set -eo pipefail
pg_dumpall -U postgres | gzip -c -9 --rsyncable > "${backupDir}/postgresql-dump.sql.gz" pg_dumpall -U postgres | gzip -c -9 --rsyncable > "/var/lib//postgresql-backups/postgresql-dump.sql.gz"
''; '';
# pg_dumpall -U postgres | gzip -c -9 --rsyncable > "${backupDir}/$(date --iso-8601)-dump.sql.gz" # pg_dumpall -U postgres | gzip -c -9 --rsyncable > "${backupDir}/$(date --iso-8601)-dump.sql.gz"
@@ -61,7 +67,8 @@ in
IOSchedulingClass = "best-effort"; IOSchedulingClass = "best-effort";
IOSchedulingPriority = 7; IOSchedulingPriority = 7;
StateDirectory = [ (builtins.baseNameOf backupDir) ]; StateDirectory = [ "postgresql-backups" ];
BindPaths = [ "${backupDir}:/var/lib/postgresql-backups" ];
# TODO: hardening # TODO: hardening
}; };