job "lidarr" {
  schedule = "@daily"

  config {
    repo = "s3://backups-minio.agnosticfront.thefij:8443/nomad/lidarr"
    passphrase = env("BACKUP_PASSPHRASE")

    options {
      InsecureTls = true
    }
  }

  task "Backup main database" {
    postgres "Backup database" {
      hostname       = env("POSTGRES_HOST")
      port           = env("POSTGRES_PORT")
      username       = env("POSTGRES_USER")
      password       = env("POSTGRES_PASSWORD")
      database       = "lidarr"
      no_tablespaces = true
      dump_to        = "/data/nas-container/lidarr/Backups/dump-lidarr.sql"
    }
  }

  task "Backup logs database" {
    postgres "Backup database" {
      hostname       = env("POSTGRES_HOST")
      port           = env("POSTGRES_PORT")
      username       = env("POSTGRES_USER")
      password       = env("POSTGRES_PASSWORD")
      database       = "lidarr-logs"
      no_tablespaces = true
      dump_to        = "/data/nas-container/lidarr/Backups/dump-lidarr-logs.sql"
    }
  }

  backup {
    paths = ["/data/nas-container/lidarr"]

    backup_opts {
      Exclude = [
        "lidarr_backup_*.zip",
        "/data/nas-container/lidarr/MediaCover",
        "/data/nas-container/lidarr/logs",
      ]
      Host = "nomad"
    }

    restore_opts {
      Host = ["nomad"]
      # Because path is absolute
      Target = "/"
    }
  }

  forget {
    KeepLast = 2
    KeepDaily = 30
    KeepWeekly = 8
    KeepMonthly = 6
    KeepYearly = 2
    Prune = true
  }
}