remove postgres job
This commit is contained in:
		
							parent
							
								
									353d849f26
								
							
						
					
					
						commit
						a748b917c5
					
				
					 2 changed files with 0 additions and 146 deletions
				
			
		| 
						 | 
					@ -1,50 +0,0 @@
 | 
				
			||||||
job "postgres-backup" {
 | 
					 | 
				
			||||||
  datacenters = ["aperture"]
 | 
					 | 
				
			||||||
  type        = "batch"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  periodic {
 | 
					 | 
				
			||||||
    crons            = ["0 */3 * * * *"]
 | 
					 | 
				
			||||||
    prohibit_overlap = true
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  group "db-backup" {
 | 
					 | 
				
			||||||
    task "postgres-backup" {
 | 
					 | 
				
			||||||
      driver = "raw_exec"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      config {
 | 
					 | 
				
			||||||
        command = "/bin/bash"
 | 
					 | 
				
			||||||
        args    = ["local/script.sh"]
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      template {
 | 
					 | 
				
			||||||
        data        = <<EOH
 | 
					 | 
				
			||||||
#!/bin/bash
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
file=/storage/backups/nomad/postgres/postgres-$(date +%Y-%m-%d_%H-%M-%S).sql
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
mkdir -p /storage/backups/nomad/postgres
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
alloc_id=$(nomad job status postgres | grep running | tail -n 1 | cut -d " " -f 1)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
job_name=$(echo ${NOMAD_JOB_NAME} | cut -d "/" -f 1)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
nomad alloc exec $alloc_id pg_dumpall -U {{ key "postgres/username/root" }} > "${file}"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
find /storage/backups/nomad/postgres/postgres* -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> `PostgreSQL` 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 "postgres/webhook/discord" }}
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
EOH
 | 
					 | 
				
			||||||
        destination = "local/script.sh"
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1,96 +0,0 @@
 | 
				
			||||||
job "postgres" {
 | 
					 | 
				
			||||||
  datacenters = ["aperture"]
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  constraint {
 | 
					 | 
				
			||||||
    attribute = "${attr.unique.hostname}"
 | 
					 | 
				
			||||||
    value     = "wheatley"
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  group "db" {
 | 
					 | 
				
			||||||
    network {
 | 
					 | 
				
			||||||
      port "db" {
 | 
					 | 
				
			||||||
        static = 5432
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    task "postgres-db" {
 | 
					 | 
				
			||||||
      driver = "docker"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      template {
 | 
					 | 
				
			||||||
        data = <<EOH
 | 
					 | 
				
			||||||
POSTGRES_PASSWORD="{{ key "postgres/password/root" }}"
 | 
					 | 
				
			||||||
POSTGRES_USER="{{ key "postgres/username/root" }}"
 | 
					 | 
				
			||||||
EOH
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        destination = "local/file.env"
 | 
					 | 
				
			||||||
        env         = true
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      config {
 | 
					 | 
				
			||||||
        image = "postgres:16-alpine"
 | 
					 | 
				
			||||||
        ports = ["db"]
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        volumes = [
 | 
					 | 
				
			||||||
          "/opt/postgres:/var/lib/postgresql/data",
 | 
					 | 
				
			||||||
          "local/postgresql.conf:/etc/postgres/postgresql.conf",
 | 
					 | 
				
			||||||
          "local/pg_hba.conf:/pg_hba.conf",
 | 
					 | 
				
			||||||
        ]
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      template {
 | 
					 | 
				
			||||||
        data = <<EOH
 | 
					 | 
				
			||||||
max_connections = 100
 | 
					 | 
				
			||||||
shared_buffers = 2GB
 | 
					 | 
				
			||||||
effective_cache_size = 6GB
 | 
					 | 
				
			||||||
maintenance_work_mem = 512MB
 | 
					 | 
				
			||||||
checkpoint_completion_target = 0.9
 | 
					 | 
				
			||||||
wal_buffers = 16MB
 | 
					 | 
				
			||||||
default_statistics_target = 100
 | 
					 | 
				
			||||||
random_page_cost = 1.1
 | 
					 | 
				
			||||||
effective_io_concurrency = 200
 | 
					 | 
				
			||||||
work_mem = 5242kB
 | 
					 | 
				
			||||||
min_wal_size = 1GB
 | 
					 | 
				
			||||||
max_wal_size = 4GB
 | 
					 | 
				
			||||||
max_worker_processes = 4
 | 
					 | 
				
			||||||
max_parallel_workers_per_gather = 2
 | 
					 | 
				
			||||||
max_parallel_workers = 4
 | 
					 | 
				
			||||||
max_parallel_maintenance_workers = 2
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
hba_file = "/pg_hba.conf"
 | 
					 | 
				
			||||||
EOH
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        destination = "local/postgresql.conf"
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      template {
 | 
					 | 
				
			||||||
        data = <<EOH
 | 
					 | 
				
			||||||
local   all             all                                     trust
 | 
					 | 
				
			||||||
host    all             all             127.0.0.1/32            trust
 | 
					 | 
				
			||||||
host    all             all             ::1/128                 trust
 | 
					 | 
				
			||||||
local   replication     all                                     trust
 | 
					 | 
				
			||||||
host    replication     all             127.0.0.1/32            trust
 | 
					 | 
				
			||||||
host    replication     all             ::1/128                 trust
 | 
					 | 
				
			||||||
host 	all 		    all 		    all 			        scram-sha-256
 | 
					 | 
				
			||||||
EOH
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        destination = "local/pg_hba.conf"
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      resources {
 | 
					 | 
				
			||||||
        cpu    = 400
 | 
					 | 
				
			||||||
        memory = 800
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      service {
 | 
					 | 
				
			||||||
        name = "postgres"
 | 
					 | 
				
			||||||
        port = "db"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        check {
 | 
					 | 
				
			||||||
          type     = "tcp"
 | 
					 | 
				
			||||||
          interval = "2s"
 | 
					 | 
				
			||||||
          timeout  = "2s"
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
		Loading…
	
		Reference in a new issue