Working backup and restore

This commit is contained in:
IamTheFij 2022-07-27 22:04:22 -07:00
parent d175166045
commit c074df4bc7
4 changed files with 17 additions and 48 deletions

View File

@ -43,7 +43,7 @@ job "backup%{ if batch_node != null }-oneoff-${batch_node}%{ endif }" {
volume "all-volumes" { volume "all-volumes" {
type = "host" type = "host"
read_only = true read_only = false
source = "all-volumes" source = "all-volumes"
} }
@ -86,7 +86,7 @@ job "backup%{ if batch_node != null }-oneoff-${batch_node}%{ endif }" {
volume_mount { volume_mount {
volume = "all-volumes" volume = "all-volumes"
destination = "/data" destination = "/data"
read_only = true read_only = false
} }
config { config {
@ -123,14 +123,19 @@ job "backup%{ if batch_node != null }-oneoff-${batch_node}%{ endif }" {
template { template {
# Probably want to use database credentials that have access to dump all tables # Probably want to use database credentials that have access to dump all tables
data = <<EOF data = <<EOF
{{ with secret "kv/data/nextcloud" }} {{ with secret "kv/data/nextcloud" -}}
MYSQL_DATABASE={{ .Data.data.db_name }} MYSQL_DATABASE={{ .Data.data.db_name }}
MYSQL_USER={{ .Data.data.db_user }} MYSQL_USER={{ .Data.data.db_user }}
MYSQL_PASSWORD={{ .Data.data.db_pass }} MYSQL_PASSWORD={{ .Data.data.db_pass }}
{{ end }} {{ end -}}
{{ with secret "kv/data/backups" }} {{ with secret "kv/data/backups" -}}
BACKUP_PASSPHRASE={{ .Data.data.backup_passphrase }} BACKUP_PASSPHRASE={{ .Data.data.backup_passphrase }}
{{ end }} RCLONE_FTP_HOST={{ .Data.data.nas_ftp_host }}
RCLONE_FTP_USER={{ .Data.data.nas_ftp_user }}
RCLONE_FTP_PASS={{ .Data.data.nas_ftp_pass | toJSON }}
RCLONE_FTP_EXPLICIT_TLS=true
RCLONE_FTP_NO_CHECK_CERTIFICATE=true
{{ end -}}
EOF EOF
destination = "secrets/db.env" destination = "secrets/db.env"
env = true env = true

View File

@ -1,23 +1,11 @@
job "Consul" { job "Consul" {
schedule = "* * * * *" schedule = "0 * * * *"
config { config {
# TODO: Backup to a meaningful location, this is just for testing repo = "rclone::ftp,env_auth:/nomad/consul"
repo = "/local/repo"
# Read from secret file
passphrase = env("BACKUP_PASSPHRASE") passphrase = env("BACKUP_PASSPHRASE")
} }
# Remove when using a proper backup destination
task "Create dir for repo" {
pre_script {
on_backup = "echo 'Backing up something'"
}
pre_script {
on_backup = "mkdir -p /local/repo"
}
}
task "Use consul snapshots" { task "Use consul snapshots" {
pre_script { pre_script {
on_backup = "mkdir -p /local/consul" on_backup = "mkdir -p /local/consul"

View File

@ -1,23 +1,11 @@
job "lldap" { job "lldap" {
schedule = "* * * * *" schedule = "0 * * * *"
config { config {
# TODO: Backup to a meaningful location, this is just for testing repo = "rclone::ftp,env_auth:/nomad/lldap"
repo = "/local/repo"
# Read from secret file
passphrase = env("BACKUP_PASSPHRASE") passphrase = env("BACKUP_PASSPHRASE")
} }
# Remove when using a proper backup destination
task "Create dir for repo" {
pre_script {
on_backup = "echo 'Backing up something'"
}
pre_script {
on_backup = "mkdir -p /local/repo"
}
}
# sqlite "Backup database" { # sqlite "Backup database" {
# path = "/data/lldap/users.db" # path = "/data/lldap/users.db"
# # sqlite3 /data/lldap/users.db .backup /data/lldap/users.db.bak # # sqlite3 /data/lldap/users.db .backup /data/lldap/users.db.bak

View File

@ -1,23 +1,11 @@
job "Nextcloud" { job "Nextcloud" {
schedule = "* * * * *" schedule = "0 * * * *"
config { config {
# TODO: Backup to a meaningful location, this is just for testing repo = "rclone::ftp,env_auth:/nomad/nextcloud"
repo = "/local/repo"
# Read from secret file
passphrase = env("BACKUP_PASSPHRASE") passphrase = env("BACKUP_PASSPHRASE")
} }
# Remove when using a proper backup destination
task "Create dir for repo" {
pre_script {
on_backup = "echo 'Backing up something'"
}
pre_script {
on_backup = "mkdir -p /local/repo"
}
}
mysql "Backup database" { mysql "Backup database" {
hostname = env("MYSQL_HOST") hostname = env("MYSQL_HOST")
port = env("MYSQL_PORT") port = env("MYSQL_PORT")