complete one time cycle mode

This commit is contained in:
tickstep 2024-04-21 18:37:46 +08:00
parent 465d8fa4e9
commit ebed4ff62f
3 changed files with 41 additions and 19 deletions

2
go.mod
View File

@ -38,4 +38,4 @@ require (
//replace github.com/boltdb/bolt => github.com/tickstep/bolt v1.3.4 //replace github.com/boltdb/bolt => github.com/tickstep/bolt v1.3.4
//replace github.com/tickstep/bolt => /Users/tickstep/Documents/Workspace/go/projects/bolt //replace github.com/tickstep/bolt => /Users/tickstep/Documents/Workspace/go/projects/bolt
//replace github.com/tickstep/library-go => /Users/tickstep/Documents/Workspace/go/projects/library-go //replace github.com/tickstep/library-go => /Users/tickstep/Documents/Workspace/go/projects/library-go
//replace github.com/tickstep/aliyunpan-api => /Users/tickstep/Documents/Workspace/go/projects/aliyunpan-api replace github.com/tickstep/aliyunpan-api => /Users/tickstep/Documents/Workspace/go/projects/aliyunpan-api

View File

@ -260,6 +260,11 @@ driveName - 网盘名称backup(备份盘)resource(资源盘)
Usage: "备份策略, 支持两种: exclusive(排他备份文件,目标目录多余的文件会被删除),increment(增量备份文件,目标目录多余的文件不会被删除)", Usage: "备份策略, 支持两种: exclusive(排他备份文件,目标目录多余的文件会被删除),increment(增量备份文件,目标目录多余的文件不会被删除)",
Value: "increment", Value: "increment",
}, },
//cli.StringFlag{
// Name: "pri",
// Usage: "同步优先级只对sync模式有效。当网盘和本地存在同名文件优先使用哪个选项支持三种: time-时间优先local-本地优先pan-网盘优先",
// Value: "time",
//},
cli.StringFlag{ cli.StringFlag{
Name: "cycle", Name: "cycle",
Usage: "备份周期, 支持两种: infinity(永久循环备份),onetime(只运行一次备份)", Usage: "备份周期, 支持两种: infinity(永久循环备份),onetime(只运行一次备份)",
@ -372,11 +377,21 @@ func RunSync(defaultTask *syncdrive.SyncTask, cycleMode syncdrive.CycleMode, fil
_, ok := os.LookupEnv("ALIYUNPAN_DOCKER") _, ok := os.LookupEnv("ALIYUNPAN_DOCKER")
if ok { if ok {
// in docker container // in docker container
if cycleMode == syncdrive.CycleInfiniteLoop {
// 使用休眠以节省CPU资源 // 使用休眠以节省CPU资源
fmt.Println("本命令不会退出程序正在以Docker的方式运行。如需退出请借助Docker提供的方式。") fmt.Println("本命令不会退出程序正在以Docker的方式运行。如需退出请借助Docker提供的方式。")
for { for {
time.Sleep(60 * time.Second) time.Sleep(60 * time.Second)
} }
} else {
for {
if syncMgr.IsAllTaskCompletely() {
fmt.Println("所有备份任务已完成")
break
}
time.Sleep(5 * time.Second)
}
}
} else { } else {
if cycleMode == syncdrive.CycleInfiniteLoop { if cycleMode == syncdrive.CycleInfiniteLoop {
if global.IsAppInCliMode { if global.IsAppInCliMode {

View File

@ -108,17 +108,7 @@ func (t *SyncTask) String() string {
mode = "备份云盘文件(下载)" mode = "备份云盘文件(下载)"
} }
builder.WriteString("同步模式: " + mode + "\n") builder.WriteString("同步模式: " + mode + "\n")
if t.Mode == SyncTwoWay {
priority := "时间优先"
if t.syncOption.SyncPriority == SyncPriorityLocalFirst {
priority = "本地文件优先"
} else if t.syncOption.SyncPriority == SyncPriorityPanFirst {
priority = "网盘文件优先"
} else {
priority = "时间优先"
}
builder.WriteString("优先选项: " + priority + "\n")
}
policy := "" policy := ""
if t.Policy == SyncPolicyExclusive { if t.Policy == SyncPolicyExclusive {
if t.Mode == Upload { if t.Mode == Upload {
@ -134,7 +124,25 @@ func (t *SyncTask) String() string {
policy = "增量备份(只下载)" policy = "增量备份(只下载)"
} }
} }
if t.Mode == SyncTwoWay {
priority := "时间优先"
if t.syncOption.SyncPriority == SyncPriorityLocalFirst {
priority = "本地文件优先"
} else if t.syncOption.SyncPriority == SyncPriorityPanFirst {
priority = "网盘文件优先"
} else {
priority = "时间优先"
}
builder.WriteString("同步策略: " + priority + "\n")
} else {
builder.WriteString("同步策略: " + policy + "\n") builder.WriteString("同步策略: " + policy + "\n")
}
cycleModeStr := "永久循环"
if t.CycleModeType == CycleOneTime {
cycleModeStr = "运行一次"
}
builder.WriteString("运行周期: " + cycleModeStr + "\n")
builder.WriteString("本地目录: " + t.LocalFolderPath + "\n") builder.WriteString("本地目录: " + t.LocalFolderPath + "\n")
builder.WriteString("云盘目录: " + t.PanFolderPath + "\n") builder.WriteString("云盘目录: " + t.PanFolderPath + "\n")
driveName := "备份盘" driveName := "备份盘"
@ -198,7 +206,6 @@ func (t *SyncTask) Start() error {
// setup sync db file // setup sync db file
t.setupDb() t.setupDb()
if t.fileActionTaskManager == nil { if t.fileActionTaskManager == nil {
t.fileActionTaskManager = NewFileActionTaskManager(t) t.fileActionTaskManager = NewFileActionTaskManager(t)
} }
@ -237,7 +244,7 @@ func (t *SyncTask) Start() error {
} else if t.Mode == Download { } else if t.Mode == Download {
go t.scanPanFile(t.ctx) go t.scanPanFile(t.ctx)
} else if t.Mode == SyncTwoWay { } else if t.Mode == SyncTwoWay {
go t.scanLocalFile(t.ctx) return fmt.Errorf("异常:暂不支持该模式。")
} else { } else {
return fmt.Errorf("异常:暂不支持该模式。") return fmt.Errorf("异常:暂不支持该模式。")
} }