working nextcloud backups

This commit is contained in:
Nickiel12 2023-10-28 19:43:56 -07:00
parent 4f9f3dc676
commit d2947e3803
2 changed files with 78 additions and 68 deletions

View file

@ -18,6 +18,21 @@
./modules/vaultwarden.nix ./modules/vaultwarden.nix
]; ];
programs.alaska_backup_script = {
enable = true;
run_nightly = false;
tmp_mount_point = /Aurora/backup_drive_mount_point;
backup1_drive_label = "AlaskaBackup";
nextcloud = {
root_dir = /Aurora/nextcloud;
db_server = "127.0.0.1";
db_name = "nextcloud";
db_user = "nextcloud";
db_passfile = /Aurora/nextcloud/nextcloud_db_password;
};
};
networking.hosts = { networking.hosts = {
"100.64.0.1" = ["files.nickiel.net" "git.nickiel.net" "nickiel.net" "jellyfin.nickiel.net" ]; "100.64.0.1" = ["files.nickiel.net" "git.nickiel.net" "nickiel.net" "jellyfin.nickiel.net" ];
}; };
@ -27,6 +42,7 @@
#pkgs.jellyfin-ffmpeg #pkgs.jellyfin-ffmpeg
pkgs.hddtemp pkgs.hddtemp
pkgs.smartmontools pkgs.smartmontools
pkgs.screen
]; ];
services.xserver.videoDrivers = [ "nvidia" ]; services.xserver.videoDrivers = [ "nvidia" ];

View file

@ -4,16 +4,9 @@ let
cfg = config.programs.alaska_backup_script; cfg = config.programs.alaska_backup_script;
in in
{ {
options.programs.alaska_backup_script = { options.programs.alaska_backup_script = {
enable = lib.mkEnableOption (lib.mdDoc "Alaska Backup Script service"); enable = lib.mkEnableOption (lib.mdDoc "Alaska Backup Script service");
package = lib.mkOption {
type = lib.types.package;
default = self.packages.${system}.alaska_backup_script;
defaultText = "pkgs.alaska_backup_script";
description = lib.mkDoc ''
the alaska backup script
'';
};
run_nightly = lib.mkOption { run_nightly = lib.mkOption {
type = lib.types.bool; type = lib.types.bool;
@ -78,28 +71,41 @@ in
}; };
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
stdenv.mkDerivation rec {
name = "alaska_backup_script";
version = "1.0";
# runtimeInputs = [ pkgs.rsync ]; systemd.services.alaska_backup_script_onfail = {
description = "Clean up permissions on script fail";
path = with pkgs; [
config.services.nextcloud.occ
umount
];
script = ''
nextcloud-occ maintenance:mode --off
installPhase = " echo "Unmounting the external drive"
mkdir -p $out/bin umount ${cfg.tmp_mount_point}
install $src/bin/${name} $out/bin '';
"; };
src = (pkgs.writeScriptBin "${name}" '' systemd.services.alaska_backup_script = {
#!/bin/sh description = "Alaska Nightly Backup Service";
onFailure = [ "alaska_backup_script_onfail.service" ];
path = with pkgs; [
config.services.nextcloud.occ
config.services.postgresql.package
rsync
mount
umount
];
script = ''
# ${pkgs.lib.makeBinPath [ pkgs.screen ]}/screen -dmS AlaskaBackupJob \
# ${pkgs.lib.makeBinPath [ pkgs.bash ]}/bash -c "
echo "Created the temporary mount point if it does not exit" echo "Created the temporary mount point if it does not exit"
mkdir -p ${builtins.toString cfg.tmp_mount_point} mkdir -p ${builtins.toString cfg.tmp_mount_point}
echo "Mounting the external backup drive" echo "Mounting the external backup drive"
mount /dev/disk/by-label/${cfg.backup1_drive_label} ${builtins.toString cfg.tmp_mount_point} mount /dev/disk/by-label/${cfg.backup1_drive_label} ${builtins.toString cfg.tmp_mount_point}
echo "Puttin nextcloud into maintenance mode so that changes cannot happen during the backup" echo "Puttin nextcloud into maintenance mode so that changes cannot happen during the backup"
nextcloud-occ maintenance:mode --on nextcloud-occ maintenance:mode --on
@ -122,31 +128,19 @@ in
umount ${cfg.tmp_mount_point} umount ${cfg.tmp_mount_point}
echo "Job completed" echo "Job completed"
'' # "
).overriteAttrs(old: {
buildCommand = "${old.buildCommand}\n patchShebangs $out";
});
};
config.systemd.services.alaska_backup_script = let
pkg = self.packages.${system}.alaska_backup_script;
in lib.mkIf cfg.run_nightly {
description = "Alaska Nightly Backup Service";
serviceConfig = {
Type = "oneshot";
ExecStart = ''
${pkgs.lib.makeBinPath [ pkgs.screen ]}/bin/screen -dmS AlaskaBackupJob ${pkgs.lib.makeBinPath [ pkgs.bash ]}/bash -c "${cfg.alaska_backup_script.package.out}/alaska_backup_script"
''; '';
}; startAt = "Sun 14:00:00";
# serviceConfig = {
# Type = "oneshot";
# };
}; };
config.systemd.timers.alaska_backup_script = let # config.systemd.timers.alaska_backup_script = lib.mkIf cfg.run_nightly {
pkg = self.packages.${system}.alaska_backup_script; # wantedBy = [ "timers.target" ];
in lib.mkIf cfg.run_nightly { # partOf = [ "alaska_backup_script.service" ];
wantedBy = [ "timers.target" ];
partOf = [ "alaska_backup_script.service" ];
# timerConfig.OnCalendar # timerConfig.OnCalendar
}; # };
};
}; };
} }