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, ... }:
let
cfg = config.services.mysql;
backupDir = "/var/lib/mysql-backups";
backupDir = "/data/mysql-backups";
in
{
# services.mysqlBackup = lib.mkIf cfg.enable {
@@ -9,6 +9,12 @@ in
# 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 {
enable = true;
locations.${backupDir} = {
@@ -42,8 +48,7 @@ in
in ''
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
@@ -63,7 +68,8 @@ in
IOSchedulingClass = "best-effort";
IOSchedulingPriority = 7;
StateDirectory = [ (builtins.baseNameOf backupDir) ];
StateDirectory = [ "mysql-backups" ];
BindPaths = [ "${backupDir}:/var/lib/mysql-backups" ];
# TODO: hardening
};