mirror of
https://github.com/tickstep/aliyunpan.git
synced 2025-01-23 14:32:14 +08:00
add priority for sync to fix issue #131
This commit is contained in:
parent
5f10365604
commit
6787269751
@ -91,14 +91,18 @@ mode - 模式,支持三种: upload(备份本地文件到云盘),download(备
|
||||
3. 使用命令行配置启动同步备份服务,将云盘目录 /sync_drive/我的文档 中的文件备份下载到本地目录 D:\tickstep\Documents\设计文档
|
||||
aliyunpan sync start -ldir "D:\tickstep\Documents\设计文档" -pdir "/sync_drive/我的文档" -mode "download"
|
||||
|
||||
4. 使用命令行配置启动同步备份服务,将本地目录 D:\tickstep\Documents\设计文档 中的文件备份到云盘目录 /sync_drive/我的文档
|
||||
4. 使用命令行配置启动同步备份服务,将云盘目录 /sync_drive/我的文档 和本地目录 D:\tickstep\Documents\设计文档 的文件进行双向同步
|
||||
同时配置同步优先选项为本地文件优先
|
||||
aliyunpan sync start -ldir "D:\tickstep\Documents\设计文档" -pdir "/sync_drive/我的文档" -mode "sync" -pri "local"
|
||||
|
||||
5. 使用命令行配置启动同步备份服务,将本地目录 D:\tickstep\Documents\设计文档 中的文件备份到云盘目录 /sync_drive/我的文档
|
||||
同时配置下载并发为2,上传并发为1,下载分片大小为256KB,上传分片大小为1MB
|
||||
aliyunpan sync start -ldir "D:\tickstep\Documents\设计文档" -pdir "/sync_drive/我的文档" -mode "upload" -dp 2 -up 1 -dbs 256 -ubs 1024
|
||||
|
||||
5. 使用配置文件启动同步备份服务,使用配置文件可以支持同时启动多个备份任务。配置文件必须存在,否则启动失败。
|
||||
6. 使用配置文件启动同步备份服务,使用配置文件可以支持同时启动多个备份任务。配置文件必须存在,否则启动失败。
|
||||
aliyunpan sync start
|
||||
|
||||
6. 使用配置文件启动同步备份服务,并配置下载并发为2,上传并发为1,下载分片大小为256KB,上传分片大小为1MB
|
||||
7. 使用配置文件启动同步备份服务,并配置下载并发为2,上传并发为1,下载分片大小为256KB,上传分片大小为1MB
|
||||
aliyunpan sync start -dp 2 -up 1 -dbs 256 -ubs 1024
|
||||
|
||||
`,
|
||||
@ -182,8 +186,17 @@ mode - 模式,支持三种: upload(备份本地文件到云盘),download(备
|
||||
task.Name = path.Base(task.LocalFolderPath)
|
||||
task.Id = utils.Md5Str(task.LocalFolderPath)
|
||||
}
|
||||
opt := c.String("pri")
|
||||
var syncOpt syncdrive.SyncPriorityOption = syncdrive.SyncPriorityTimestampFirst
|
||||
if opt == "local" {
|
||||
syncOpt = syncdrive.SyncPriorityLocalFirst
|
||||
} else if opt == "pan" {
|
||||
syncOpt = syncdrive.SyncPriorityPanFirst
|
||||
} else {
|
||||
syncOpt = syncdrive.SyncPriorityTimestampFirst
|
||||
}
|
||||
|
||||
RunSync(task, dp, up, downloadBlockSize, uploadBlockSize)
|
||||
RunSync(task, dp, up, downloadBlockSize, uploadBlockSize, syncOpt)
|
||||
return nil
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
@ -200,6 +213,11 @@ mode - 模式,支持三种: upload(备份本地文件到云盘),download(备
|
||||
Usage: "备份模式, 支持三种: upload(备份本地文件到云盘),download(备份云盘文件到本地),sync(双向同步备份)",
|
||||
Value: "upload",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "pri",
|
||||
Usage: "优先级priority,只对双向同步备份模式有效。当网盘和本地存在同名文件,优先使用哪个,选项支持三种: time-时间优先,local-本地优先,pan-网盘优先",
|
||||
Value: "time",
|
||||
},
|
||||
cli.IntFlag{
|
||||
Name: "dp",
|
||||
Usage: "download parallel, 下载并发数量,即可以同时并发下载多少个文件。0代表跟从配置文件设置(取值范围:1 ~ 10)",
|
||||
@ -226,7 +244,8 @@ mode - 模式,支持三种: upload(备份本地文件到云盘),download(备
|
||||
}
|
||||
}
|
||||
|
||||
func RunSync(defaultTask *syncdrive.SyncTask, fileDownloadParallel, fileUploadParallel int, downloadBlockSize, uploadBlockSize int64) {
|
||||
func RunSync(defaultTask *syncdrive.SyncTask, fileDownloadParallel, fileUploadParallel int, downloadBlockSize, uploadBlockSize int64,
|
||||
flag syncdrive.SyncPriorityOption) {
|
||||
useInternalUrl := config.Config.TransferUrlType == 2
|
||||
maxDownloadRate := config.Config.MaxDownloadRate
|
||||
maxUploadRate := config.Config.MaxUploadRate
|
||||
@ -271,6 +290,7 @@ func RunSync(defaultTask *syncdrive.SyncTask, fileDownloadParallel, fileUploadPa
|
||||
UseInternalUrl: useInternalUrl,
|
||||
MaxDownloadRate: maxDownloadRate,
|
||||
MaxUploadRate: maxUploadRate,
|
||||
SyncPriority: flag,
|
||||
}
|
||||
syncMgr := syncdrive.NewSyncTaskManager(activeUser, activeUser.DriveList.GetFileDriveId(), panClient, syncFolderRootPath, option)
|
||||
syncConfigFile := syncMgr.ConfigFilePath()
|
||||
|
@ -572,7 +572,22 @@ func (f *FileActionTaskManager) doFileDiffRoutine(panFiles PanFileList, localFil
|
||||
}
|
||||
f.addToSyncDb(downloadPanFile)
|
||||
} else if f.task.Mode == SyncTwoWay {
|
||||
if localFile.UpdateTimeUnix() > panFile.UpdateTimeUnix() { // upload file
|
||||
actFlag := "unknown"
|
||||
if f.syncOption.SyncPriority == SyncPriorityTimestampFirst { // 时间优先
|
||||
if localFile.UpdateTimeUnix() > panFile.UpdateTimeUnix() { // upload file
|
||||
actFlag = "upload"
|
||||
} else if localFile.UpdateTimeUnix() < panFile.UpdateTimeUnix() { // download file
|
||||
actFlag = "download"
|
||||
}
|
||||
} else if f.syncOption.SyncPriority == SyncPriorityLocalFirst { // 本地文件优先
|
||||
actFlag = "upload"
|
||||
} else if f.syncOption.SyncPriority == SyncPriorityPanFirst { // 网盘文件优先
|
||||
actFlag = "download"
|
||||
} else {
|
||||
// unsupported, do nothing
|
||||
}
|
||||
|
||||
if actFlag == "upload" { // upload file
|
||||
uploadLocalFile := &FileActionTask{
|
||||
syncItem: &SyncFileItem{
|
||||
Action: SyncFileActionUpload,
|
||||
@ -589,7 +604,7 @@ func (f *FileActionTaskManager) doFileDiffRoutine(panFiles PanFileList, localFil
|
||||
},
|
||||
}
|
||||
f.addToSyncDb(uploadLocalFile)
|
||||
} else if localFile.UpdateTimeUnix() < panFile.UpdateTimeUnix() { // download file
|
||||
} else if actFlag == "download" { // download file
|
||||
downloadPanFile := &FileActionTask{
|
||||
syncItem: &SyncFileItem{
|
||||
Action: SyncFileActionDownload,
|
||||
|
@ -11,6 +11,9 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
// SyncPriorityOption 同步优先级选项
|
||||
SyncPriorityOption string
|
||||
|
||||
// ScanStatus 扫描状态
|
||||
ScanStatus string
|
||||
|
||||
@ -179,6 +182,13 @@ const (
|
||||
ScanStatusNormal ScanStatus = "normal"
|
||||
// ScanStatusDiscard 已过期,已删除
|
||||
ScanStatusDiscard ScanStatus = "discard"
|
||||
|
||||
// SyncPriorityTimestampFirst 最新时间优先
|
||||
SyncPriorityTimestampFirst = "time_first"
|
||||
// SyncPriorityLocalFirst 本地文件优先
|
||||
SyncPriorityLocalFirst = "local_first"
|
||||
// SyncPriorityPanFirst 网盘文件优先
|
||||
SyncPriorityPanFirst = "pan_first"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -84,6 +84,17 @@ func (t *SyncTask) String() string {
|
||||
mode = "备份云盘文件(只下载)"
|
||||
}
|
||||
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")
|
||||
}
|
||||
builder.WriteString("本地目录: " + t.LocalFolderPath + "\n")
|
||||
builder.WriteString("云盘目录: " + t.PanFolderPath + "\n")
|
||||
return builder.String()
|
||||
|
@ -23,6 +23,9 @@ type (
|
||||
|
||||
MaxDownloadRate int64 // 限制最大下载速度
|
||||
MaxUploadRate int64 // 限制最大上传速度
|
||||
|
||||
// 优先级选项
|
||||
SyncPriority SyncPriorityOption
|
||||
}
|
||||
|
||||
// SyncTaskManager 同步任务管理器
|
||||
|
Loading…
Reference in New Issue
Block a user