Compare commits

..

6 Commits

Author SHA1 Message Date
2149a58293 finish new backups and restructure gameservers 2025-10-18 18:58:59 -05:00
62a813eb81 no sudo bro wtf? 2025-10-18 18:44:21 -05:00
f11dbc52bc no awk 2025-10-18 18:43:18 -05:00
3e216701e0 final touches backups now start the db backups automatcially 2025-10-18 18:41:23 -05:00
f72e067a4e ensure immich gets backed up 2025-10-18 18:22:37 -05:00
39336740e1 ensure postgres backups exist 2025-10-18 18:18:03 -05:00
4 changed files with 26 additions and 25 deletions

View File

@@ -13,7 +13,7 @@ in
../../../modules/system ../../../modules/system
../../../modules/holocron ../../../modules/holocron
../../../modules/homelab ../../../modules/homelab
../../../modules/homelab/minecraft_recpro ../../../modules/gameservers/minecraft_recpro
]; ];
system = { system = {

View File

@@ -3,15 +3,7 @@
config, config,
lib, lib,
... ...
}: }: let
/*
to restore db make sure it exists with rebuild or command below
then use zstd command to decompress and restore in one go
mysql -u root -p -e "CREATE DATABASE IF NOT EXISTS minecraft_recpro_db;"
zstd -dc <path_to_backup> | mysql -u root -p minecraft_recpro_db
*/
let
service = "minecraft_recpro"; service = "minecraft_recpro";
cfg = config.gameservers.${service}; cfg = config.gameservers.${service};
sec = config.sops.secrets; sec = config.sops.secrets;

View File

@@ -4,7 +4,17 @@
pkgs, pkgs,
... ...
}: }:
/**/ /*
to restore mysql/marinadb database:
mysql -u root -p -e "DROP DATABASE IF EXISTS <database_name>;" # delete old db if still lingering
mysql -u root -p -e "CREATE DATABASE IF NOT EXISTS <database_name>;" # create empty db w/ correct name
zstd -dc <path_to_backup> | mysql -u root -p <database_name>
to restore a postgres database:
sudo -u postgres psql -c "DROP DATABASE IF EXISTS <database_name>;" # delete old db if lingering (prolly wont work)
sudo -u postgres psql -c "CREATE DATABASE <database_name>;" # create empty db w/ correct name
zstd -dc <path_to_backup> | sudo -u postgres psql -d immich # restore from the dump
*/
let let
cfg = config.homelab.backups; cfg = config.homelab.backups;
sec = config.sops.secrets; sec = config.sops.secrets;
@@ -30,10 +40,14 @@ in {
repo = cfg.backup_repo; repo = cfg.backup_repo;
paths = lib.flatten (lib.attrsets.mapAttrsToList (_: arg: arg.paths) cfg.baks); paths = lib.flatten (lib.attrsets.mapAttrsToList (_: arg: arg.paths) cfg.baks);
compression = "auto,zstd"; compression = "auto,zstd";
startAt = "daily"; startAt = "03:30";
group = "archives"; group = "archives";
encryption.mode = "repokey-blake2"; encryption.mode = "repokey-blake2";
encryption.passCommand = "cat ${sec."borg_passwd".path}"; encryption.passCommand = "cat ${sec."borg_passwd".path}";
preHook = ''
systemctl start mysql-backup.service
systemctl start $(systemctl list-unit-files 'postgresqlBackup-*.service' --no-legend --no-pager | cut -d' ' -f1)
'';
extraArgs = ["--verbose" "--show-rc" "--umask" "0007"]; extraArgs = ["--verbose" "--show-rc" "--umask" "0007"];
extraCreateArgs = ["--list" "--stats" "--filter" "AME"]; extraCreateArgs = ["--list" "--stats" "--filter" "AME"];
prune.keep = { prune.keep = {
@@ -45,20 +59,20 @@ in {
}; };
# mysql backups currently minecraft_recpro is the only thing using this # mysql backups currently minecraft_recpro is the only thing using this
services.mysqlBackup = lib.mkIf config.services.mysql.enable { services.mysqlBackup = lib.mkIf (config.services.mysql.ensureDatabases != []) {
enable = true; enable = true;
location = "/var/backup/mysql"; location = "/var/backup/mysql";
user = "root"; user = "root";
calendar = "*-*-* *:59:45"; # goes fast, included in back up with server dirs at **:00 calendar = "daily"; # goes fast, included in back up with server dirs at **:00
compressionAlg = "zstd"; compressionAlg = "zstd";
databases = config.services.mysql.ensureDatabases; # set to all databases defined in esure databases databases = config.services.mysql.ensureDatabases; # set to all databases defined in esure databases
}; };
# postgresql backups currently immich is the only user # postgresql backups currently immich is the only user
services.postgresqlBackup = lib.mkIf config.services.postgresql.enable { services.postgresqlBackup = lib.mkIf (config.services.postgresql.ensureDatabases != []) {
enable = true; enable = true;
location = "/var/backup/postgresql"; location = "/var/backup/postgresql";
compression = "zstd"; # optional: "xz", "zstd", "none" compression = "zstd"; # optional: "xz", "zstd", "none"
startAt = "03:59"; # the dump is included in a backup taken at 4:00 startAt = "daily"; # the dump is included in a backup taken at 4:00
databases = config.services.postgresql.ensureDatabases; # set to all databases defined in esure databases databases = config.services.postgresql.ensureDatabases; # set to all databases defined in esure databases
}; };

View File

@@ -5,14 +5,7 @@
inputs, inputs,
unstable_pkgs, unstable_pkgs,
... ...
}: }: let
/*
to restore database ensure it exists
sudo -u postgres psql -c "DROP DATABASE IF EXISTS immich; CREATE DATABASE immich;"
zstd -dc <path_to_backup> | sudo -u postgres psql -d immich
*/
let
service = "immich"; service = "immich";
cfg = config.homelab.${service}; cfg = config.homelab.${service};
sec = config.sops.secrets; sec = config.sops.secrets;
@@ -115,7 +108,9 @@ in {
]; ];
# add postgresql database that is automatically created to the backup list # add postgresql database that is automatically created to the backup list
services.postgresqlBackup.databases = ["immich"]; # set to all databases defined in esure databases #services.postgresqlBackup.databases = ["immich"]; # set to all databases defined in esure databases
services.postgresql.ensureDatabases = [service]; # set to all databases defined in esure databases
# add to backups # add to backups
homelab.backups.baks = { homelab.backups.baks = {