From 7dbd5652ed6a82f182af7aaab17e07a4580f5511 Mon Sep 17 00:00:00 2001 From: Petru Paler Date: Mon, 15 Jan 2024 10:14:03 +0000 Subject: [PATCH] mysql backup cron --- secrets/mysql_root_password | 2 +- services/mysql-backup.hcl | 37 +++++++++++++++++++++++++++ stateful-commands.txt | 2 +- utils/file_to_nomad_var.sh | 50 ------------------------------------- 4 files changed, 39 insertions(+), 52 deletions(-) create mode 100644 services/mysql-backup.hcl delete mode 100755 utils/file_to_nomad_var.sh diff --git a/secrets/mysql_root_password b/secrets/mysql_root_password index b1873c6..73894f6 100644 --- a/secrets/mysql_root_password +++ b/secrets/mysql_root_password @@ -1 +1 @@ -wiochohv8foR9eDo5ol5 +wiochohv8foR9eDo5ol5 \ No newline at end of file diff --git a/services/mysql-backup.hcl b/services/mysql-backup.hcl new file mode 100644 index 0000000..df605e1 --- /dev/null +++ b/services/mysql-backup.hcl @@ -0,0 +1,37 @@ +job "mysql-backup" { + datacenters = ["alo"] + type = "batch" + + periodic { + cron = "23 23 * * * *" + prohibit_overlap = true + } + + group "db" { + task "backup" { + driver = "raw_exec" + + config { + command = "/bin/sh" + args = [ "local/script.sh" ] + } + + template { + destination = "local/script.sh" + data = < /data/compute/appdata/db-backups/mysql/backup.sql + EOH + } + + template { + destination = "secrets/file.env" + env = true + data = < -# -# filename can be - for stdin. -# -# read the var back out with: -# - nomad var get -# -# From https://github.com/gerrowadat/nomad-homelab/blob/main/utilities/file_to_nomad_var.sh - -function print_usage() { - echo "Usage: ${0} " -} - -filename=$1 -nomad_var=$2 -var_key=$3 - -if [ "${filename}" != "-" ]; -then - if [ ! -f "${filename}" ] - then - echo "${filename} does not exist" - exit - fi -fi - -var_contents=$(cat ${filename}) - -if [[ "${nomad_var}" == "" || "${var_key}" == "" ]]; -then - print_usage - exit -fi - -echo "Copying ${filename} to ${nomad_var}:${var_key}..." - -nomad var put -force -in hcl - <