From 3b2aa22ec0564ef5361644a459793c4665da4338 Mon Sep 17 00:00:00 2001 From: Son Roy Almerol Date: Mon, 11 Nov 2024 15:18:32 -0500 Subject: [PATCH] use hostname as id on local targets --- internal/backend/backup/fix_datastore.go | 12 +++++++++++- internal/backend/backup/jobrun.go | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/internal/backend/backup/fix_datastore.go b/internal/backend/backup/fix_datastore.go index d6df579..c3ebbaa 100644 --- a/internal/backend/backup/fix_datastore.go +++ b/internal/backend/backup/fix_datastore.go @@ -46,8 +46,18 @@ func FixDatastore(job *store.Job, storeInstance *store.Store) error { newOwner = storeInstance.LastToken.Username } + hostname, err := os.Hostname() + if err != nil { + hostnameFile, err := os.ReadFile("/etc/hostname") + if err != nil { + hostname = "localhost" + } + + hostname = strings.TrimSpace(string(hostnameFile)) + } + isAgent := strings.HasPrefix(target.Path, "agent://") - backupId := job.Target + backupId := hostname if isAgent { backupId = strings.TrimSpace(strings.Split(target.Name, " - ")[0]) } diff --git a/internal/backend/backup/jobrun.go b/internal/backend/backup/jobrun.go index 7f22805..b76e9ae 100644 --- a/internal/backend/backup/jobrun.go +++ b/internal/backend/backup/jobrun.go @@ -63,7 +63,17 @@ func RunBackup(job *store.Job, storeInstance *store.Store) (*store.Task, error) return nil, fmt.Errorf("RunBackup: failed to fix datastore permissions -> %w", err) } - backupId := job.Target + hostname, err := os.Hostname() + if err != nil { + hostnameFile, err := os.ReadFile("/etc/hostname") + if err != nil { + hostname = "localhost" + } + + hostname = strings.TrimSpace(string(hostnameFile)) + } + + backupId := hostname if isAgent { backupId = strings.TrimSpace(strings.Split(target.Name, " - ")[0]) }