diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2017-04-30 15:56:29 +0300 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2017-04-30 15:56:41 +0300 |
commit | 3a3cf815c149878db36e57561f5462b060f2110c (patch) | |
tree | 04840b897a4e3be874f9d6cd79d15ba10ac76861 /modules/apps | |
parent | 9be6c7b78f2a668aa1edcafa25c3dd1ba8ae6ad7 (diff) | |
download | nixsap-3a3cf815c149878db36e57561f5462b060f2110c.tar.gz |
mysqlbackup: fail if any server is unavailable
Diffstat (limited to 'modules/apps')
-rw-r--r-- | modules/apps/mysqlbackup.nix | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/modules/apps/mysqlbackup.nix b/modules/apps/mysqlbackup.nix index 811e930..8e87da6 100644 --- a/modules/apps/mysqlbackup.nix +++ b/modules/apps/mysqlbackup.nix @@ -207,7 +207,8 @@ let mkJobs = name: server: pkgs.writeBashScript "mkjobs-${name}" '' set -euo pipefail mkdir -p '${privateDir}/jobs/${name}' - for db in $(${mysql} --defaults-file=${defaultsFile name server} -N < ${showDatabases name server} | shuf) + ${mysql} --defaults-file=${defaultsFile name server} -N < ${showDatabases name server} \ + | while read -r db do ln -svf ${job name server} "${privateDir}/jobs/${name}/$db" done @@ -297,6 +298,7 @@ let '') (filterAttrs (_: s: s.connection.password-file != null) cfg.servers) )} + failedServers=0 { cat <<'LIST' ${concatStringsSep "\n" (mapAttrsToList (mkJobs) cfg.servers)} @@ -311,11 +313,10 @@ let --shuf \ --tagstr '* {}:' \ --timeout ${toString (10 * 60)} \ - || true + || failedServers=$? - failed=0 + failedJobs=0 log="${cfg.dumpDir}/$DATE/joblog.txt" - { cd '${privateDir}/jobs' && ${pkgs.findutils}/bin/find . -type l -printf '%P\n'; } | ${pkgs.parallel}/bin/parallel \ @@ -328,13 +329,18 @@ let --retries 2 \ --tagstr '* {}:' \ --timeout ${toString (6 * 60 * 60)} \ - '${privateDir}/jobs/{}' || failed=$? + '${privateDir}/jobs/{}' || failedJobs=$? cat "$log" clean du -sh "${cfg.dumpDir}/$DATE" || true - exit "$failed" + + if [ "$failedServers" -gt "$failedJobs" ]; then + exit "$failedServers" + else + exit "$failedJobs" + fi ''; in { |