summaryrefslogtreecommitdiff
path: root/database/backups.go
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-04-21 21:14:58 -0700
committerElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-04-21 21:14:58 -0700
commit9d96d1a9422b30dd6caa42cca2a561970735f160 (patch)
tree3a548002293bf8a79514134437f718484a10193b /database/backups.go
parentbef72712c271e7628342521985d68f418dcf0343 (diff)
downloadbackup-notify-9d96d1a9422b30dd6caa42cca2a561970735f160.tar.gz
backup-notify-9d96d1a9422b30dd6caa42cca2a561970735f160.zip
notify when we don't receive a thing in the last 24 hours
Diffstat (limited to 'database/backups.go')
-rw-r--r--database/backups.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/database/backups.go b/database/backups.go
index ab2155f..a588576 100644
--- a/database/backups.go
+++ b/database/backups.go
@@ -49,3 +49,47 @@ func ReceivedBackup(dbConn *sql.DB, hostname string) error {
return err
}
+
+func BackupedHostnamesInTheLastDay(dbConn *sql.DB) ([]string, error) {
+ log.Println("listing hostnames that have been backed up in the last day")
+
+ rows, err := dbConn.Query(`SELECT DISTINCT hostname FROM backups WHERE received_on > ?;`, time.Now().Add(-24*time.Hour))
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+
+ hostnames := []string{}
+ for rows.Next() {
+ var hostname string
+ err := rows.Scan(&hostname)
+ if err != nil {
+ return nil, err
+ }
+ hostnames = append(hostnames, hostname)
+ }
+
+ return hostnames, nil
+}
+
+func ReceivedHostnames(dbConn *sql.DB) ([]string, error) {
+ log.Println("listing received hostnames")
+
+ rows, err := dbConn.Query(`SELECT DISTINCT hostname FROM backups;`)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+
+ hostnames := []string{}
+ for rows.Next() {
+ var hostname string
+ err := rows.Scan(&hostname)
+ if err != nil {
+ return nil, err
+ }
+ hostnames = append(hostnames, hostname)
+ }
+
+ return hostnames, nil
+}