Go SDK
Official Go SDK for LOX Backup. Full-featured client library with type safety and context support.
v0.1.0Updated 2026-01-01
Installation
go get github.com/lox-backup/lox-go
Requirements
- Go 1.21 or higher
Quick Start
package main
import (
"context"
"fmt"
"log"
"github.com/lox-backup/lox-go/lox"
)
func main() {
// Create client
client := lox.NewClient("lox_key_xxx")
ctx := context.Background()
// Upload a backup
backup, err := client.Backups.Upload(ctx, "/path/to/backup.tar.gz", &lox.UploadOptions{
Name: "daily-backup",
Tags: []string{"production", "database"},
RetentionDays: 90,
Wait: true, // Wait for processing to complete
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Backup created: %s (status: %s)\n", backup.UUID, backup.Status)
// List backups
result, err := client.Backups.List(ctx, &lox.ListBackupsOptions{
Tags: []string{"production"},
PageSize: 10,
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found %d backups\n", result.Total)
}Configuration
// Custom base URL
client := lox.NewClient("lox_key_xxx",
lox.WithBaseURL("https://api.custom-backlox.com"),
)
// Custom timeout
client := lox.NewClient("lox_key_xxx",
lox.WithTimeout(60 * time.Second),
)
// Custom HTTP client
httpClient := &http.Client{
Transport: &http.Transport{
MaxIdleConns: 10,
},
}
client := lox.NewClient("lox_key_xxx",
lox.WithHTTPClient(httpClient),
)Backups
Upload
backup, err := client.Backups.Upload(ctx, "/path/to/file.tar.gz", &lox.UploadOptions{
Name: "my-backup",
Tags: []string{"production", "database"},
RetentionDays: 90,
Description: "Daily database backup",
Wait: true, // Wait for processing
})List
result, err := client.Backups.List(ctx, &lox.ListBackupsOptions{
Tags: []string{"production"},
Status: lox.BackupStatusCompleted,
PageSize: 20,
Page: 1,
})
for _, backup := range result.Items {
fmt.Printf("%s: %s (%d bytes)\n", backup.UUID, backup.Name, backup.SizeBytes)
}Download
// Download with progress callback
err := client.Backups.Download(ctx, uuid, "/tmp/restored.tar.gz",
func(downloaded, total int64) {
percent := float64(downloaded) / float64(total) * 100
fmt.Printf("Progress: %.1f%%\n", percent)
},
)
// Or just get the download URL
info, err := client.Backups.GetDownloadURL(ctx, uuid)
fmt.Printf("Download from: %s\n", info.URL)Other Operations
// Get single backup
backup, err := client.Backups.Get(ctx, uuid)
// Delete backup
err := client.Backups.Delete(ctx, uuid)
// Request restore
job, err := client.Backups.Restore(ctx, uuid, "")
// Wait for backup to complete
backup, err := client.Backups.WaitForCompletion(ctx, uuid, time.Hour, 5*time.Second)
// Get statistics
stats, err := client.Backups.GetStats(ctx)
fmt.Printf("Total: %d backups, %d bytes\n", stats.TotalBackups, stats.TotalSizeBytes)
// Get profiles (grouped by source/component)
profiles, err := client.Backups.GetProfiles(ctx, "wordpress")
// Get latest backup per component
latest, err := client.Backups.GetLatest(ctx, "wordpress", "")Storage Targets
// List storage targets
targets, err := client.Storage.List(ctx)
// Get single target
target, err := client.Storage.Get(ctx, id)
// Create target
target, err := client.Storage.Create(ctx, &lox.CreateStorageTargetOptions{
Name: "AWS Glacier",
StorageType: lox.StorageTypeS3Glacier,
Config: map[string]any{
"bucket": "my-bucket",
"region": "us-east-1",
},
})
// Update target
target, err := client.Storage.Update(ctx, id, &lox.UpdateStorageTargetOptions{
IsEnabled: boolPtr(false),
})
// Delete target
err := client.Storage.Delete(ctx, id)
// Test connectivity
result, err := client.Storage.Test(ctx, id)
// Health summary
summary, err := client.Storage.GetHealthSummary(ctx)
fmt.Printf("%d/%d targets healthy\n", summary.Healthy, summary.Total)Tenant
// Get current tenant
tenant, err := client.Tenant.GetCurrent(ctx)
fmt.Printf("Tenant: %s (%s)\n", tenant.Name, tenant.Slug)
// Get quota
quota, err := client.Tenant.GetQuota(ctx)
fmt.Printf("Used: %d / %d bytes\n", quota.UsedBytes, quota.QuotaBytes)Notification Channels
Manage notification channels for backup alerts via webhook, Slack, Discord, and more.
// Create a webhook channel
channel, err := client.NotificationChannels.Create(ctx, &lox.CreateChannelOptions{
Name: "Production Alerts",
ChannelType: lox.ChannelTypeWebhook,
Config: map[string]any{
"url": "https://example.com/webhook",
},
Events: []string{"backup_completed", "backup_failed"},
})
fmt.Printf("Webhook secret: %s\n", channel.Config["secret"])
// Create a Slack channel
slack, err := client.NotificationChannels.Create(ctx, &lox.CreateChannelOptions{
Name: "Slack Alerts",
ChannelType: lox.ChannelTypeSlack,
Config: map[string]any{
"webhook_url": "https://hooks.slack.com/services/...",
"channel": "#backup-alerts",
},
})
// List channels
channels, err := client.NotificationChannels.List(ctx)
for _, ch := range channels {
fmt.Printf("%s (%s): healthy=%v\n", ch.Name, ch.ChannelType, ch.IsHealthy)
}
// Test a channel
result, err := client.NotificationChannels.Test(ctx, channelUUID)
fmt.Printf("Test result: %s\n", result.Status)
// Get summary
summary, err := client.NotificationChannels.GetSummary(ctx)
fmt.Printf("Total: %d, Unhealthy: %d\n", summary.TotalChannels, summary.UnhealthyChannels)
// Enable/disable
channel, err := client.NotificationChannels.Enable(ctx, channelUUID)
channel, err := client.NotificationChannels.Disable(ctx, channelUUID)
// Delete
err := client.NotificationChannels.Delete(ctx, channelUUID)Backup Agents
Manage backup agents for Veeam-style machine backup with agent registration and monitoring.
// Register a new agent
reg, err := client.Agents.Register(ctx, &lox.RegisterAgentOptions{
Hostname: "server-01",
OSType: lox.OSTypeLinux,
DisplayName: "Production Server 01",
Capabilities: []string{"file", "block"},
HardwareInfo: map[string]any{
"cpu_cores": 8,
"memory_gb": 32,
},
})
fmt.Printf("Agent UUID: %s\n", reg.UUID)
fmt.Printf("Token: %s\n", reg.RegistrationToken)
// Get install command
cmd, err := client.Agents.GetInstallCommand(ctx, agentUUID)
fmt.Println(cmd.RecommendedCommand)
// List agents
agents, err := client.Agents.List(ctx)
for _, agent := range agents {
fmt.Printf("%s (%s): %s\n", agent.Hostname, agent.OSType, agent.Status)
}
// Get summary
summary, err := client.Agents.GetSummary(ctx)
fmt.Printf("Online: %d, Offline: %d\n", summary.OnlineAgents, summary.OfflineAgents)
// Update agent
agent, err := client.Agents.Update(ctx, agentUUID, &lox.UpdateAgentOptions{
DisplayName: strPtr("New Display Name"),
})
// Enable/disable
agent, err := client.Agents.Enable(ctx, agentUUID)
agent, err := client.Agents.Disable(ctx, agentUUID)
// Regenerate token
reg, err := client.Agents.RegenerateToken(ctx, agentUUID)
// Delete agent
err := client.Agents.Delete(ctx, agentUUID)Backup Jobs
Create and manage scheduled backup jobs for automated machine backups.
// Create a backup job
job, err := client.Jobs.Create(ctx, &lox.CreateJobOptions{
AgentUUID: agentUUID,
Name: "Daily Full Backup",
JobType: lox.JobTypeFile,
Sources: []lox.SourceConfig{
{Type: "path", Value: "/home"},
{Type: "path", Value: "/var/www"},
},
Exclusions: []string{"*.log", "*.tmp", "node_modules"},
BackupMode: lox.BackupModeFull,
ScheduleCron: "0 2 * * *", // Daily at 2 AM
ScheduleEnabled: true,
RetentionPolicy: &lox.RetentionPolicy{
Daily: 7,
Weekly: 4,
Monthly: 12,
},
Compression: "zstd",
CompressionLevel: 6,
EncryptionEnabled: true,
VerifyAfterBackup: true,
})
fmt.Printf("Job created: %s\n", job.UUID)
// List jobs (optionally filter by agent)
jobs, err := client.Jobs.List(ctx, "") // or agentUUID to filter
for _, j := range jobs {
fmt.Printf("%s: %s\n", j.Name, j.Status)
}
// Run job immediately
result, err := client.Jobs.Run(ctx, jobUUID, lox.BackupTypeFull)
fmt.Printf("Backup started: %s\n", result.BackupUUID)
// List job's backups
backups, err := client.Jobs.ListBackups(ctx, jobUUID)
// Update job
job, err := client.Jobs.Update(ctx, jobUUID, &lox.UpdateJobOptions{
Name: strPtr("New Job Name"),
ScheduleCron: strPtr("0 3 * * *"),
})
// Enable/disable
job, err := client.Jobs.Enable(ctx, jobUUID)
job, err := client.Jobs.Disable(ctx, jobUUID)
// Delete job and all its backups
err := client.Jobs.Delete(ctx, jobUUID)Machine Backups
Manage machine backup restore points created by backup jobs.
// List machine backups
backups, err := client.MachineBackups.List(ctx, &lox.ListMachineBackupsOptions{
Status: "completed",
Limit: 50,
})
for _, b := range backups {
fmt.Printf("%s: %s (%d bytes)\n", b.UUID, b.BackupType, b.SizeBytes)
}
// Get specific backup
backup, err := client.MachineBackups.Get(ctx, backupUUID)
fmt.Printf("Files: %d\n", backup.FilesCount)
// Restore backup
restore, err := client.MachineBackups.Restore(ctx, backupUUID, &lox.MachineRestoreOptions{
RestoreType: "full",
TargetType: "original",
OverwriteExisting: false,
PreservePermissions: true,
// For alternate restore:
// TargetAgentUUID: "other-agent-uuid",
// TargetPath: "/restore/path",
// For selective restore:
// SelectedItems: []string{"/home/user/documents"},
})
fmt.Printf("Restore job: %s\n", restore.UUID)
// Delete backup
err := client.MachineBackups.Delete(ctx, backupUUID)Error Handling
backup, err := client.Backups.Get(ctx, uuid)
if err != nil {
if lox.IsNotFound(err) {
log.Println("Backup not found")
} else if lox.IsUnauthorized(err) {
log.Println("Invalid API key")
} else if lox.IsQuotaExceeded(err) {
log.Println("Storage quota exceeded")
} else {
log.Printf("Error: %v", err)
}
}Error Helper Functions
| Function | Description |
|---|---|
| lox.IsNotFound(err) | Check if error is 404 |
| lox.IsUnauthorized(err) | Check if error is 401 |
| lox.IsQuotaExceeded(err) | Check if quota is exceeded |
| lox.IsRateLimited(err) | Check if rate limited (429) |