add more log for sync

This commit is contained in:
tickstep 2022-06-12 17:44:16 +08:00
parent 38a7f63cc6
commit d1836d3df8
4 changed files with 13 additions and 8 deletions

View File

@ -34,13 +34,13 @@ func CmdSync() cli.Command {
Usage: "同步备份功能(Beta)",
UsageText: cmder.App().Name + " sync",
Description: `
备份功能指定本地目录和对应的一个网盘目录以备份文件
备份功能指定本地目录和对应的一个网盘目录以备份文件网盘目录必须和本地目录独占使用不要用作其他他用途不然备份可能会有问题
备份功能支持以下三种模式
1. upload
备份本地文件即上传本地文件到网盘始终保持本地文件有一个完整的备份在网盘
2. download
备份云盘文件即下载网盘文件到本地始终保持网盘的文件有一个完整的备份在本地
3. sync
3. sync慎用双向备份过程会删除文件
双向备份保持网盘文件和本地文件严格一致
请输入以下命令查看如何配置和启动

View File

@ -51,8 +51,7 @@ func (f *FileActionTask) HashCode() string {
}
func (f *FileActionTask) DoAction(ctx context.Context) error {
logger.Verboseln("file action task")
logger.Verboseln(f.syncItem)
logger.Verboseln("file action task", utils.ObjectToJsonStr(f.syncItem, false))
if f.syncItem.Action == SyncFileActionUpload {
if e := f.uploadFile(ctx); e != nil {
// TODO: retry / cleanup downloading file

View File

@ -144,7 +144,7 @@ func (f *FileActionTaskManager) doLocalFileDiffRoutine(ctx context.Context) {
continue
}
}
logger.Verboseln("do file diff process")
//logger.Verboseln("do file diff process")
localFiles := LocalFileList{}
panFiles := PanFileList{}
var err error
@ -195,7 +195,7 @@ func (f *FileActionTaskManager) doPanFileDiffRoutine(ctx context.Context) {
continue
}
}
logger.Verboseln("do file diff process")
//logger.Verboseln("do file diff process")
localFiles := LocalFileList{}
panFiles := PanFileList{}
var err error
@ -445,7 +445,7 @@ func (f *FileActionTaskManager) doFileDiffRoutine(panFiles PanFileList, localFil
if strings.ToLower(panFile.Sha1Hash) == strings.ToLower(localFile.Sha1Hash) {
// do nothing
logger.Verboseln("no need to update file: ", localFile.Path)
logger.Verboseln("file is the same, no need to update file: ", localFile.Path)
continue
}
@ -647,7 +647,7 @@ func (f *FileActionTaskManager) fileActionTaskExecutor(ctx context.Context) {
downloadWaitGroup.Wait()
return
default:
logger.Verboseln("do file executor process")
//logger.Verboseln("do file executor process")
// do upload
uploadItem := f.getFromSyncDb(SyncFileActionUpload)

View File

@ -222,6 +222,7 @@ func (t *SyncTask) discardLocalFileDb(filePath string, startTimeUnix int64) {
// label file discard
file.ScanStatus = ScanStatusDiscard
t.localFileDb.Update(file)
logger.Verboseln("label local file discard: ", utils.ObjectToJsonStr(file, false))
} else {
if file.IsFolder() {
t.discardLocalFileDb(file.Path, startTimeUnix)
@ -323,6 +324,7 @@ func (t *SyncTask) scanLocalFile(ctx context.Context) {
// append
localFile.ScanTimeAt = utils.NowTimeStr()
localFileAppendList = append(localFileAppendList, localFile)
logger.Verboseln("add local file to db: ", utils.ObjectToJsonStr(localFile, false))
} else {
// update newest info into DB
if localFile.UpdateTimeUnix() > localFileInDb.UpdateTimeUnix() {
@ -334,6 +336,7 @@ func (t *SyncTask) scanLocalFile(ctx context.Context) {
localFileInDb.FileType = localFile.FileType
localFileInDb.ScanTimeAt = utils.NowTimeStr()
localFileInDb.ScanStatus = ScanStatusNormal
logger.Verboseln("update local file to db: ", utils.ObjectToJsonStr(localFileInDb, false))
if _, er := t.localFileDb.Update(localFileInDb); er != nil {
logger.Verboseln("local db update error ", er)
}
@ -370,6 +373,7 @@ func (t *SyncTask) discardPanFileDb(filePath string, startTimeUnix int64) {
// label file discard
file.ScanStatus = ScanStatusDiscard
t.panFileDb.Update(file)
logger.Verboseln("label pan file discard: ", utils.ObjectToJsonStr(file, false))
} else {
if file.IsFolder() {
t.discardPanFileDb(file.Path, startTimeUnix)
@ -455,6 +459,7 @@ func (t *SyncTask) scanPanFile(ctx context.Context) {
pFile1 := NewPanFileItem(file)
pFile1.ScanTimeAt = utils.NowTimeStr()
panFileList = append(panFileList, pFile1)
logger.Verboseln("add pan file to db: ", utils.ObjectToJsonStr(pFile1, false))
} else {
// update newest info into DB
panFileInDb.DomainId = file.DomainId
@ -468,6 +473,7 @@ func (t *SyncTask) scanPanFile(ctx context.Context) {
panFileInDb.CreatedAt = file.CreatedAt
panFileInDb.ScanTimeAt = utils.NowTimeStr()
panFileInDb.ScanStatus = ScanStatusNormal
logger.Verboseln("update pan file to db: ", utils.ObjectToJsonStr(panFileInDb, false))
t.panFileDb.Update(panFileInDb)
}