feat: add backup for server

This commit is contained in:
danny 2025-09-28 12:37:26 +08:00
parent 20ee47caa2
commit f7409e0537
14 changed files with 256 additions and 165 deletions

View file

@ -0,0 +1,92 @@
{
lib,
config,
pkgs,
...
}:
let
inherit (lib) mkIf;
backupAt = "*-*-* 03:00:00";
backupPath = "/mnt/backup_dn";
backupScript = pkgs.writeShellScript "backup-nextcloud.sh" ''
nextcloudPath="${config.services.nextcloud.datadir}"
if [ ! -d "$nextcloudPath" ]; then
echo "nextcloud path not found: $nextcloudPath"
exit 1
fi
backupPath="${backupPath}"
nextcloudBakPath="$backupPath"
if [ ! -d "$backupPath" ]; then
echo "Backup device is not mounted: $backupPath"
exit 1
fi
echo "Start syncing..."
${pkgs.rsync}/bin/rsync -rh --delete "$nextcloudPath" "$nextcloudBakPath"
echo "Data dir backup completed."
'';
in
{
fileSystems."/mnt/backup_dn" = {
device = "/dev/disk/by-uuid/FBD9-F625";
fsType = "exfat";
options = [
"x-systemd.automount"
"noauto"
"x-systemd.idle-timeout=600"
"nofail"
"user"
"x-gvfs-show"
"gid=1000"
"uid=1000"
"dmask=000"
"fmask=000"
];
};
# ==== Advance Backup ==== #
# services.pgbackrest = {
# enable = true;
# repos.localhost.path = "${backupPath}/postgresql";
# };
services.postgresqlBackup = {
enable = true;
startAt = backupAt;
pgdumpOptions = "--no-owner";
databases = [
"nextcloud"
"vaultwarden"
"paperless"
];
location = "${backupPath}/postgresql";
};
systemd = mkIf config.services.nextcloud.enable {
timers = {
"nextcloud-backup" = {
enable = true;
description = "Nextcloud backup";
timerConfig = {
OnCalendar = backupAt;
Persistent = true;
OnUnitActiveSec = "1d";
AccuracySec = "1h";
Unit = "nextcloud-backup.service";
};
wantedBy = [ "timers.target" ];
};
};
services."nextcloud-backup" = {
enable = true;
serviceConfig = {
User = "nextcloud";
ExecStart = "${backupScript}";
};
};
};
}

View file

@ -1,23 +1,6 @@
{ pkgs, ... }:
{
fileSystems."/mnt/backup_dn" = {
device = "/dev/disk/by-uuid/FBD9-F625";
fsType = "exfat";
options = [
"x-systemd.automount"
"noauto"
"x-systemd.idle-timeout=600"
"nofail"
"user"
"x-gvfs-show"
"gid=1000"
"uid=1000"
"dmask=000"
"fmask=000"
];
};
boot.kernelPackages = pkgs.linuxPackages;
boot.loader.systemd-boot.enable = true;

View file

@ -18,6 +18,7 @@ in
intel-bus-id = "PCI:0:2:0";
nvidia-bus-id = "PCI:1:0:0";
})
./backup.nix
./security.nix
./sops-conf.nix
./boot.nix
@ -56,8 +57,6 @@ in
})
(import ../../modules/nextcloud.nix {
hostname = "nextcloud.net.dn";
dataBackupPath = "/mnt/backup_dn";
dbBackupPath = "/mnt/backup_dn";
adminpassFile = config.sops.secrets."nextcloud/adminPassword".path;
trusted = [ "nextcloud.daccc.info" ];
})

View file

@ -386,7 +386,7 @@ in
virtualisation = {
oci-containers = {
backend = "docker";
backend = "podman";
containers = {
uptime-kuma = {
extraOptions = [ "--network=host" ];