job "sonarr" {
  schedule = "@daily"

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

    options {
      InsecureTls = true
    }
  }

  task "Backup main database" {
    sqlite "Backup database" {
      path = "/data/sonarr/sonarr.db"
      dump_to = "/data/sonarr/Backups/sonarr.db.bak"
    }
  }

  task "Backup logs database" {
    sqlite "Backup database" {
      path = "/data/sonarr/logs.db"
      dump_to = "/data/sonarr/Backups/logs.db.bak"
    }
  }

  backup {
    paths = ["/data/sonarr"]

    backup_opts {
      Exclude = [
        "sonarr_backup_*.zip",
        "*.db",
        "*.db-shm",
        "*.db-wal",
      ]
      Host = "nomad"
    }

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

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