I’d like to incorporate the nextcloud-occ command maintenance:mode --on
inside a pre-hook in my borg backup service module, but borg doesn’t seem to have access to the nextcloud-occ
path and throws a command not found
error in the logs. The systemctl commands work fine. Here is the code snippet I’ve tried:
services.borgbackup = {
jobs = {
cypress = {
archiveBaseName = "cypress";
dateFormat = "+%Y.%m.%d-T%H:%M:%S";
doInit = true; # run borg init if backup directory does not already contain the repository
failOnWarnings = false;
extraCreateArgs = [
"--progress"
"--stats"
];
startAt = "*-*-* 02:30:00"; # everyday at 2:30am
preHook = ''
echo "spinning down services and starting sql database dumps"
${lib.getExe config.services.nextcloud.occ} maintenance:mode --on
sleep 10
systemctl stop lldap.service
systemctl start postgresqlBackup-lldap.service
systemctl start postgresqlBackup-nextcloud.service
sleep 120
'';
postHook = ''
echo "spinning services back up"
${lib.getExe config.services.nextcloud.occ} maintenance:mode --off
systemctl start lldap.service
'';
repo = "borg@${configVars.thinkpadLanIp}:."; # this automatically picks up the location of the remote borg repository assuming remote is running a nixos borg module
encryption = {
mode = "repokey-blake2"; # encrypt using password and save encryption key inside repository
passCommand = "cat ${config.sops.secrets.borgCryptPasswd.path}";
};
environment = {
BORG_RSH = "ssh -p 28764 -o StrictHostKeyChecking=no -i /root/.ssh/borg-ed25519-cypress";
BORG_RELOCATED_REPO_ACCESS_IS_OK = "yes"; # supress warning about repo location being moved since last backup (e.g. changing directory location or IP address)
};
compression = "auto,zstd,8";
paths = [
"/var/lib/private/lldap"
"/var/lib/nextcloud"
"/var/lib/redis-nextcloud"
"/var/lib/tailscale"
"/var/backup/postgresql/lldap.sql.gz"
"/var/backup/postgresql/nextcloud.sql.gz"
];
prune.keep = {
daily = 7; # keep the last seven daily archives
monthly = 3; # keep the last three monthly archives
};
};
};
};