Add nextcloud backup job

This commit is contained in:
IamTheFij 2022-04-15 12:11:41 -07:00
parent 5acb814abd
commit 3c7df5fa54
4 changed files with 100 additions and 4 deletions

View File

@ -48,4 +48,4 @@ all:
servers: {} servers: {}
vault_instances: vault_instances:
children: children:
# servers: {} servers: {}

View File

@ -0,0 +1,42 @@
job "Nextcloud" {
schedule = "* * * * *"
config {
repo = "/local/repo"
# Read from secret file
# Either options.PasswordFile or using readfile()
passphrase = "secret phrase"
}
task "Create dir for repo" {
pre_script {
on_backup = "echo 'Backing up something'"
}
pre_script {
on_backup = "mkdir -p /local/repo"
}
}
mysql "Backup database" {
hostname = env("MYSQL_HOST")
port = env("MYSQL_PORT")
database = env("MYSQL_DATABASE")
username = env("MYSQL_USER")
password = env("MYSQL_PASSWORD")
no_tablespaces = true
dump_to = "/local/dump.sql"
}
backup {
paths = ["/data"]
restore_opts {
Target = "/"
}
}
forget {
KeepLast = 2
Prune = true
}
}

View File

@ -13,6 +13,11 @@ variable "nextcloud_pass" {
default = "nextcloud" default = "nextcloud"
} }
variable "backup_config" {
type = string
description = "HCL config for Restic Scheduler jobs"
}
job "nextcloud" { job "nextcloud" {
datacenters = ["dc1"] datacenters = ["dc1"]
type = "service" type = "service"
@ -83,9 +88,12 @@ job "nextcloud" {
"-c", "-c",
"/usr/bin/mysql -h${NOMAD_UPSTREAM_IP_mysql_server} -P${NOMAD_UPSTREAM_PORT_mysql_server} -uroot -psupersecretpassword < /bootstrap.sql", "/usr/bin/mysql -h${NOMAD_UPSTREAM_IP_mysql_server} -P${NOMAD_UPSTREAM_PORT_mysql_server} -uroot -psupersecretpassword < /bootstrap.sql",
] ]
volumes = [
"local/bootstrap.sql:/bootstrap.sql" mount {
] type = "bind"
source = "local/bootstrap.sql"
target = "/bootstrap.sql"
}
} }
template { template {
@ -129,5 +137,44 @@ job "nextcloud" {
memory = 250 memory = 250
} }
} }
task "backup" {
driver = "docker"
volume_mount {
volume = "nextcloud-data"
destination = "/data"
read_only = true
}
config {
image = "iamthefij/resticscheduler"
args = ["/jobs/nextcloud.hcl"]
mount {
type = "bind"
target = "/jobs"
source = "jobs"
}
}
env = {
"MYSQL_HOST" = "${NOMAD_UPSTREAM_IP_mysql_server}"
"MYSQL_PORT" = "${NOMAD_UPSTREAM_PORT_mysql_server}"
"MYSQL_DATABASE" = "${var.nextcloud_db}"
"MYSQL_USER" = "${var.nextcloud_user}"
"MYSQL_PASSWORD" = "${var.nextcloud_pass}"
}
template {
data = var.backup_config
destination = "jobs/nextcloud.hcl"
}
resources {
cpu = 50
memory = 256
}
}
} }
} }

View File

@ -1,6 +1,13 @@
locals {
backup_config = file("${path.module}/nextcloud-backup.hcl")
}
resource "nomad_job" "nextcloud" { resource "nomad_job" "nextcloud" {
hcl2 { hcl2 {
enabled = true enabled = true
vars = {
"backup_config" = "${local.backup_config}",
}
} }
jobspec = file("${path.module}/nextcloud.nomad") jobspec = file("${path.module}/nextcloud.nomad")