Skip to content

Commit

Permalink
use hostname as id on local targets
Browse files Browse the repository at this point in the history
Son Roy Almerol committed Nov 11, 2024
1 parent f6cce42 commit 3b2aa22
Showing 2 changed files with 22 additions and 2 deletions.
12 changes: 11 additions & 1 deletion internal/backend/backup/fix_datastore.go
Original file line number Diff line number Diff line change
@@ -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])
}
12 changes: 11 additions & 1 deletion internal/backend/backup/jobrun.go
Original file line number Diff line number Diff line change
@@ -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])
}

0 comments on commit 3b2aa22

Please sign in to comment.