@@ -17,17 +17,18 @@ import (
1717
1818// App 封装了备份应用的状态和依赖
1919type App struct {
20- cfg * config.Config
20+ cfg * config.Config
21+ Timestamp string
2122}
2223
2324// New 创建一个新的 App 实例
24- func New (cfg * config.Config ) * App {
25- return & App {cfg : cfg }
25+ func New (cfg * config.Config , startTime time. Time ) * App {
26+ return & App {cfg : cfg , Timestamp : startTime . Format ( "20060102_150405" ) }
2627}
2728
2829// Run 执行完整的备份和清理流程
2930func (a * App ) Run () error {
30- slog .Info ("开始备份流程" , "timestamp" , a .cfg . Timestamp )
31+ slog .Info ("开始备份流程" , "timestamp" , a .Timestamp )
3132
3233 // 1. 运行前检查
3334 if err := utils .ValidateDirectories (a .cfg ); err != nil {
@@ -218,7 +219,7 @@ func (a *App) createArchive() error {
218219 return fmt .Errorf ("备份目录为空" )
219220 }
220221
221- archiveFile := filepath .Join (a .cfg .BackupDir , fmt .Sprintf ("%s_%s.tar.gz" , a .cfg .Filename , a .cfg . Timestamp ))
222+ archiveFile := filepath .Join (a .cfg .BackupDir , fmt .Sprintf ("%s_%s.tar.gz" , a .cfg .Filename , a .Timestamp ))
222223 slog .Info ("创建加密压缩包" , "file" , archiveFile )
223224
224225 if err := archive .EncryptedBackup (a .cfg .BackupTmpDir , a .cfg .Password , archiveFile ); err != nil {
@@ -245,6 +246,7 @@ func (a *App) cleanupOldBackups() error {
245246 if err != nil {
246247 return fmt .Errorf ("查找旧备份失败: %w" , err )
247248 }
249+ slog .Info ("找到备份文件" , "count" , len (files ), "pattern" , globPattern )
248250
249251 cutoffTime := time .Now ().AddDate (0 , 0 , - a .cfg .RetentionDays )
250252 count := 0
0 commit comments