Adds logging - removes secrets
This commit is contained in:
@@ -9,8 +9,8 @@
|
|||||||
# create checks implementation to use management API to create each one
|
# create checks implementation to use management API to create each one
|
||||||
|
|
||||||
let b2Repo = "/home/jbrechtel/kopia/leonard-brechtel-backup/repository.config"
|
let b2Repo = "/home/jbrechtel/kopia/leonard-brechtel-backup/repository.config"
|
||||||
let rootURL = "https://status.roo.lol"
|
let observeURL = "https://observe.roo.lol"
|
||||||
let pingKey = "pRybo-Yjebna0KHQCYCpTg"
|
let secrets = open ~/backups.nuon
|
||||||
|
|
||||||
let jobs = [{ statusSlug: "photos-content-b2-kopia", type: "kopia", source: "/nas1/photos.roo.lol", target: $b2Repo, }
|
let jobs = [{ statusSlug: "photos-content-b2-kopia", type: "kopia", source: "/nas1/photos.roo.lol", target: $b2Repo, }
|
||||||
,{ statusSlug: "photos-service-b2-kopia", type: "kopia", source: "/services/photos.roo.lol", target: $b2Repo, }
|
,{ statusSlug: "photos-service-b2-kopia", type: "kopia", source: "/services/photos.roo.lol", target: $b2Repo, }
|
||||||
@@ -43,55 +43,66 @@ def backup [job] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def zfsBackup [job] {
|
def zfsBackup [job] {
|
||||||
logStartJob $job.statusSlug
|
pingStartJob $job.statusSlug
|
||||||
try {
|
try {
|
||||||
syncoid --no-sync-snap --create-bookmark --no-privilege-elevation --recursive ($job.source) ($job.target)
|
let output = syncoid --no-sync-snap --create-bookmark --no-privilege-elevation --recursive ($job.source) ($job.target) | complete
|
||||||
logFinishedJob $job.statusSlug
|
logJob { slug: $job.statusSlug, output: $output, success: true }
|
||||||
|
pingFinishedJob $job.statusSlug
|
||||||
} catch { |err|
|
} catch { |err|
|
||||||
logFailedJob $job.statusSlug $err.debug
|
logJob { slug: $job.statusSlug, output: $err, success: false }
|
||||||
|
pingFailedJob $job.statusSlug $err.debug
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def kopiaBackup [job] {
|
def kopiaBackup [job] {
|
||||||
#using sudo is annoying but since this is backing up docker containers
|
#using sudo is annoying but since this is backing up docker containers
|
||||||
#the permissions are often wrong. I should be using podman + rootless
|
#the permissions are often wrong. I should be using podman + rootless
|
||||||
logStartJob $job.statusSlug
|
pingStartJob $job.statusSlug
|
||||||
try {
|
try {
|
||||||
sudo kopia --config-file=($job.target) snapshot create ($job.source)
|
let output = sudo kopia --config-file=($job.target) snapshot create ($job.source) | complete
|
||||||
logFinishedJob $job.statusSlug
|
logJob { slug: $job.statusSlug, output: $output, success: true }
|
||||||
|
pingFinishedJob $job.statusSlug
|
||||||
} catch { |err|
|
} catch { |err|
|
||||||
logFailedJob $job.statusSlug $err.debug
|
logJob { slug: $job.statusSlug, output: $err, success: false }
|
||||||
|
pingFailedJob $job.statusSlug $err.debug
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def logStartJob [slug] {
|
def pingStartJob [slug] {
|
||||||
print $"starting job: ($slug)"
|
print $"starting job: ($slug)"
|
||||||
print $"($rootURL)/ping/($pingKey)/($slug)/start"
|
print $"($secrets.hcURL)/ping/($secrets.hcPingKey)/($slug)/start"
|
||||||
curl -s $"($rootURL)/ping/($pingKey)/($slug)/start" | save -f /dev/null
|
curl -s $"($secrets.hcURL)/ping/($secrets.hcPingKey)/($slug)/start" | save -f /dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
def logFailedJob [slug, err] {
|
def pingFailedJob [slug, err] {
|
||||||
print $"failed to run job: ($slug) with error: ($err)"
|
print $"failed to run job: ($slug) with error: ($err)"
|
||||||
curl -s $"($rootURL)/ping/($pingKey)/($slug)/fail" | save -f /dev/null
|
curl -s $"($secrets.hcURL)/ping/($secrets.hcPingKey)/($slug)/fail" | save -f /dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
def logFinishedJob [slug] {
|
def pingFinishedJob [slug] {
|
||||||
print $"finished job: ($slug)"
|
print $"finished job: ($slug)"
|
||||||
curl -s $"($rootURL)/ping/($pingKey)/($slug)" | save -f /dev/null
|
curl -s $"($secrets.hcURL)/ping/($secrets.hcPingKey)/($slug)" | save -f /dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
def logJob [details] {
|
||||||
|
http post -u $secrets.observeUser -p $secrets.observePassword $"($secrets.observeURL)/api/default/backups/_json" ($details | to json)
|
||||||
}
|
}
|
||||||
|
|
||||||
def createJob [job] {
|
def createJob [job] {
|
||||||
let jobDetails = { name: $job.statusSlug, slug: $job.statusSlug, timeout: 86400 }
|
let jobDetails = { name: $job.statusSlug, slug: $job.statusSlug, timeout: 86400 }
|
||||||
http post --full --headers {"X-API-Key": $env.HC_API } --content-type "application/json" $"($rootURL)/api/v3/checks/" ($jobDetails | to json)
|
http post --full --headers {"X-API-Key": $secrets.hcAPIKey } --content-type "application/json" $"($secrets.hcURL)/api/v3/checks/" ($jobDetails | to json)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def "main log" [msg] {
|
||||||
|
logJob { slug: "testing", data: $msg }
|
||||||
|
}
|
||||||
def "main list" [] {
|
def "main list" [] {
|
||||||
print "Known jobs:"
|
print "Known jobs:"
|
||||||
print $"($jobs | get statusSlug | to text)"
|
print $"($jobs | get statusSlug | to text)"
|
||||||
}
|
}
|
||||||
|
|
||||||
def "main create-missing" [] {
|
def "main create-missing" [] {
|
||||||
let existingSlugs = (curl -H $"X-API-Key: ($env.HC_API)" $"($rootURL)/api/v3/checks/" | from json | get checks.slug | to nuon)
|
let existingSlugs = (curl -H $"X-API-Key: ($secrets.hcAPIKey)" $"($secrets.hcURL)/api/v3/checks/" | from json | get checks.slug | to nuon)
|
||||||
let missingJobs = $jobs | filter { |job| not ($job.statusSlug in $existingSlugs) }
|
let missingJobs = $jobs | filter { |job| not ($job.statusSlug in $existingSlugs) }
|
||||||
$missingJobs | each { createJob $in }
|
$missingJobs | each { createJob $in }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user