feat: improve local demo and documentation

This commit is contained in:
Awuqing
2026-08-11 13:34:42 +08:00
parent 50ce6587d8
commit 3a181c7416
19 changed files with 114 additions and 44 deletions
@@ -721,7 +721,8 @@ func (s *BackupExecutionService) executeTask(ctx context.Context, task *model.Ba
return
}
defer os.RemoveAll(result.TempDir)
// 依据运行器产出判定实际类型:产出清单 → 全量(记录清单供后续差异比对);否则为差异。
// 依据运行器产出判定实际类型:文件全量会产出清单;只有明确启用差异模式且
// 未产出清单时才是差异备份。数据库运行器本身不产出文件清单,但仍属于全量。
if result.Manifest != nil {
backupKind = model.BackupKindFull
if data, encErr := backup.EncodeManifest(*result.Manifest); encErr == nil {
@@ -729,8 +730,10 @@ func (s *BackupExecutionService) executeTask(ctx context.Context, task *model.Ba
} else {
logger.Warnf("备份清单序列化失败(不影响本次备份,但将禁用后续差异):%v", encErr)
}
} else {
} else if spec.Differential {
backupKind = model.BackupKindDifferential
} else {
backupKind = model.BackupKindFull
}
finalPath := result.ArtifactPath
if strings.EqualFold(task.Compression, "gzip") && !strings.HasSuffix(strings.ToLower(finalPath), ".gz") {
@@ -107,6 +107,11 @@ func newExecutionTestServices(t *testing.T) (*BackupExecutionService, *BackupRec
if err != nil {
t.Fatalf("database.Open returned error: %v", err)
}
sqlDB, err := db.DB()
if err != nil {
t.Fatalf("db.DB returned error: %v", err)
}
t.Cleanup(func() { _ = sqlDB.Close() })
cipher := codec.NewConfigCipher("execution-secret")
tasks := repository.NewBackupTaskRepository(db)
targets := repository.NewStorageTargetRepository(db)
@@ -155,6 +160,34 @@ func TestBackupExecutionServiceRunTaskByIDSync(t *testing.T) {
}
}
func TestBackupExecutionServiceSQLiteBackupRemainsFull(t *testing.T) {
executionService, _, tasks, _, records, sourceDir, _ := newExecutionTestServices(t)
dbPath := filepath.Join(sourceDir, "finance.db")
if err := os.WriteFile(dbPath, []byte("sqlite-demo"), 0o644); err != nil {
t.Fatalf("WriteFile sqlite fixture returned error: %v", err)
}
task := &model.BackupTask{
Name: "finance-db", Type: model.BackupTaskTypeSQLite, Enabled: true,
DBPath: dbPath, StorageTargetID: 1, RetentionDays: 30,
Compression: "none", MaxBackups: 10, LastStatus: "idle",
}
if err := tasks.Create(context.Background(), task); err != nil {
t.Fatalf("Create sqlite task returned error: %v", err)
}
detail, err := executionService.RunTaskByIDSync(context.Background(), task.ID)
if err != nil {
t.Fatalf("RunTaskByIDSync sqlite returned error: %v", err)
}
stored, err := records.FindByID(context.Background(), detail.ID)
if err != nil {
t.Fatalf("FindByID sqlite record returned error: %v", err)
}
if stored == nil || stored.BackupKind != model.BackupKindFull {
t.Fatalf("expected sqlite backup kind full, got %#v", stored)
}
}
func TestBackupExecutionServiceNodePoolSelectionDoesNotPersistTaskNodeID(t *testing.T) {
executionService, _, tasks, _, records, _, _ := newExecutionTestServices(t)
ctx := context.Background()
+11 -12
View File
@@ -8,10 +8,11 @@ import (
"path/filepath"
"runtime"
"strings"
"syscall"
"time"
"backupx/server/internal/config"
"github.com/shirou/gopsutil/v4/disk"
)
type SystemInfo struct {
@@ -74,11 +75,11 @@ func (s *SystemService) CheckUpdate(ctx context.Context) (*UpdateCheckResult, er
}
var release struct {
TagName string `json:"tag_name"`
HTMLURL string `json:"html_url"`
Body string `json:"body"`
Published string `json:"published_at"`
Assets []struct {
TagName string `json:"tag_name"`
HTMLURL string `json:"html_url"`
Body string `json:"body"`
Published string `json:"published_at"`
Assets []struct {
Name string `json:"name"`
BrowserDownloadURL string `json:"browser_download_url"`
} `json:"assets"`
@@ -124,12 +125,10 @@ func (s *SystemService) GetInfo(_ context.Context) *SystemInfo {
if dir == "" {
dir = "."
}
var stat syscall.Statfs_t
if err := syscall.Statfs(dir, &stat); err == nil {
info.DiskTotal = int64(stat.Blocks) * int64(stat.Bsize)
info.DiskFree = int64(stat.Bavail) * int64(stat.Bsize)
info.DiskUsed = info.DiskTotal - info.DiskFree
if stat, err := disk.Usage(dir); err == nil {
info.DiskTotal = int64(stat.Total)
info.DiskFree = int64(stat.Free)
info.DiskUsed = int64(stat.Used)
}
return info
}