-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmysql.nix
37 lines (33 loc) · 995 Bytes
/
mysql.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
{ pkgs, ...}:
let
backupsDirectory = "/zbackup/backups/mysql";
maxBackups = 2;
in {
services.mysql = {
enable = true;
package = pkgs.mariadb;
# replication = {
# role = "master";
# serverId = 5;
# masterHost = "daedalus.internal";
# slaveHost = "daedalus.internal";
# masterUser = "replicator";
# masterPassword = builtins.readFile "/etc/mysql-replication.secret";
# };
};
systemd.services.mysql-backup = {
wantedBy = [ "multi-user.target" ];
serviceConfig.Type = "oneshot";
script = ''
path=${backupsDirectory}/backup-$(date +"%F-%T").sql.gz
${pkgs.mariadb}/bin/mysqldump --single-transaction --routines --triggers --all-databases | ${pkgs.gzip}/bin/gzip -c >$path
chmod 400 $path
'';
};
systemd.timers.mysql-backup = {
wantedBy = [ "multi-user.target" ];
partOf = [ "mysql-backup.service" ];
timerConfig.OnCalendar = "daily";
};
networking.firewall.allowedTCPPorts = [ 3306 ];
}