From 804fc4c5e520cfaf145807530a9bc45fe1b97e31 Mon Sep 17 00:00:00 2001 From: wizzdom Date: Fri, 26 Jul 2024 21:58:11 +0100 Subject: [PATCH] add members-mysql (#46) --- jobs/services/members-mysql-backup.hcl | 50 +++++++++++++++++ jobs/services/members-mysql.hcl | 78 ++++++++++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 jobs/services/members-mysql-backup.hcl create mode 100644 jobs/services/members-mysql.hcl diff --git a/jobs/services/members-mysql-backup.hcl b/jobs/services/members-mysql-backup.hcl new file mode 100644 index 0000000..c07b00f --- /dev/null +++ b/jobs/services/members-mysql-backup.hcl @@ -0,0 +1,50 @@ +job "members-mysql-backup" { + datacenters = ["aperture"] + type = "batch" + + periodic { + crons = ["0 */3 * * * *"] + prohibit_overlap = true + } + + group "db-backup" { + task "mysql-backup" { + driver = "raw_exec" + + config { + command = "/bin/bash" + args = ["local/script.sh"] + } + + template { + data = < "${file}" + +find /storage/backups/nomad/mysql/members/members-mysql* -ctime +3 -exec rm {} \; || true + +if [ -s "$file" ]; then # check if file exists and is not empty + echo "Backup successful" + exit 0 +else + rm $file + curl -H "Content-Type: application/json" -d \ + '{"content": "<@&585512338728419341> `MySQL` backup for **'"${job_name}"'** has just **FAILED**\nFile name: `'"$file"'`\nDate: `'"$(TZ=Europe/Dublin date)"'`\nTurn off this script with `nomad job stop '"${job_name}"'` \n\n## Remember to restart this backup job when fixed!!!"}' \ + {{ key "mysql/webhook/discord" }} +fi +EOH + destination = "local/script.sh" + } + } + } +} + diff --git a/jobs/services/members-mysql.hcl b/jobs/services/members-mysql.hcl new file mode 100644 index 0000000..6587da7 --- /dev/null +++ b/jobs/services/members-mysql.hcl @@ -0,0 +1,78 @@ +job "members-mysql" { + datacenters = ["aperture"] + + constraint { + attribute = "${attr.unique.hostname}" + value = "wheatley" + } + + group "db" { + network { + port "db" { + static = 3306 + } + } + + task "mariadb" { + driver = "docker" + + template { + data = <