add log flag for sync command

This commit is contained in:
tickstep 2022-08-13 19:38:10 +08:00
parent d0ad94aa65
commit 9016c12c26
6 changed files with 34 additions and 5 deletions

View File

@ -59,6 +59,7 @@ ENV ALIYUNPAN_LOCAL_DIR=/home/app/data
ENV ALIYUNPAN_PAN_DIR=/sync_drive
ENV ALIYUNPAN_SYNC_MODE=upload
ENV ALIYUNPAN_SYNC_PRIORITY=time
ENV ALIYUNPAN_SYNC_LOG=false
# 运行
ENTRYPOINT ./app.sh

View File

@ -40,4 +40,4 @@ else
fi
./aliyunpan config set -transfer_url_type ${ALIYUNPAN_TRANSFER_URL_TYPE}
./aliyunpan sync start -dp ${ALIYUNPAN_DOWNLOAD_PARALLEL} -up ${ALIYUNPAN_UPLOAD_PARALLEL} -dbs ${ALIYUNPAN_DOWNLOAD_BLOCK_SIZE} -ubs ${ALIYUNPAN_UPLOAD_BLOCK_SIZE}
./aliyunpan sync start -dp ${ALIYUNPAN_DOWNLOAD_PARALLEL} -up ${ALIYUNPAN_UPLOAD_PARALLEL} -dbs ${ALIYUNPAN_DOWNLOAD_BLOCK_SIZE} -ubs ${ALIYUNPAN_UPLOAD_BLOCK_SIZE} -log ${ALIYUNPAN_SYNC_LOG}

View File

@ -31,5 +31,6 @@ services:
- ALIYUNPAN_SYNC_MODE=upload
# 优先级,只对双向同步备份模式有效。选项支持三种: time-时间优先local-本地优先pan-网盘优先
- ALIYUNPAN_SYNC_PRIORITY=time
# 是否显示文件备份过程日志true-显示false-不显示
- ALIYUNPAN_SYNC_LOG=true

View File

@ -94,8 +94,8 @@ priority - 优先级,只对双向同步备份模式有效。选项支持三种
aliyunpan sync start -ldir "D:\tickstep\Documents\设计文档" -pdir "/sync_drive/我的文档" -mode "download"
4. 使用命令行配置启动同步备份服务将云盘目录 /sync_drive/我的文档 和本地目录 D:\tickstep\Documents\设计文档 的文件进行双向同步
同时配置同步优先选项为本地文件优先
aliyunpan sync start -ldir "D:\tickstep\Documents\设计文档" -pdir "/sync_drive/我的文档" -mode "sync" -pri "local"
同时配置同步优先选项为本地文件优先并显示同步过程的日志
aliyunpan sync start -ldir "D:\tickstep\Documents\设计文档" -pdir "/sync_drive/我的文档" -mode "sync" -pri "local" -log true
5. 使用命令行配置启动同步备份服务将本地目录 D:\tickstep\Documents\设计文档 中的文件备份到云盘目录 /sync_drive/我的文档
同时配置下载并发为2上传并发为1下载分片大小为256KB上传分片大小为1MB
@ -115,6 +115,12 @@ priority - 优先级,只对双向同步备份模式有效。选项支持三种
}
activeUser := GetActiveUser()
if c.String("log") == "true" {
syncdrive.LogPrompt = true
} else {
syncdrive.LogPrompt = false
}
dp := c.Int("dp")
if dp == 0 {
dp = config.Config.MaxDownloadParallel
@ -242,6 +248,11 @@ priority - 优先级,只对双向同步备份模式有效。选项支持三种
Usage: "upload block size上传分片大小单位KB。推荐值1024 ~ 10240",
Value: 10240,
},
cli.StringFlag{
Name: "log",
Usage: "是否显示文件备份过程日志true-显示false-不显示",
Value: "false",
},
},
},
},
@ -319,7 +330,7 @@ func RunSync(defaultTask *syncdrive.SyncTask, fileDownloadParallel, fileUploadPa
} else {
// in cmd mode
c := ""
fmt.Print("本命令不会退出如需要结束同步备份进程请输入y然后按Enter键进行停止")
fmt.Println("本命令不会退出如需要结束同步备份进程请输入y然后按Enter键进行停止")
for strings.ToLower(c) != "y" {
fmt.Scan(&c)
}

View File

@ -41,6 +41,12 @@ type (
}
)
func (f *FileActionTask) prompt(msg string) {
if LogPrompt {
fmt.Println("[" + utils.NowTimeStr() + "] " + msg)
}
}
func (f *FileActionTask) HashCode() string {
postfix := ""
if f.syncItem.Action == SyncFileActionDownload {
@ -54,6 +60,7 @@ func (f *FileActionTask) HashCode() string {
func (f *FileActionTask) DoAction(ctx context.Context) error {
logger.Verboseln("file action task", utils.ObjectToJsonStr(f.syncItem, false))
if f.syncItem.Action == SyncFileActionUpload {
f.prompt("上传文件:" + f.syncItem.getLocalFileFullPath())
if e := f.uploadFile(ctx); e != nil {
// TODO: retry / cleanup downloading file
return e
@ -79,6 +86,7 @@ func (f *FileActionTask) DoAction(ctx context.Context) error {
}
if f.syncItem.Action == SyncFileActionDownload {
f.prompt("下载文件:" + f.syncItem.getPanFileFullPath())
if e := f.downloadFile(ctx); e != nil {
// TODO: retry / cleanup downloading file
return e
@ -121,6 +129,7 @@ func (f *FileActionTask) DoAction(ctx context.Context) error {
}
if f.syncItem.Action == SyncFileActionDeleteLocal {
f.prompt("删除本地文件:" + f.syncItem.getLocalFileFullPath())
if e := f.deleteLocalFile(ctx); e != nil {
// TODO: retry
return e
@ -132,6 +141,7 @@ func (f *FileActionTask) DoAction(ctx context.Context) error {
}
if f.syncItem.Action == SyncFileActionDeletePan {
f.prompt("删除云盘文件:" + f.syncItem.getPanFileFullPath())
if e := f.deletePanFile(ctx); e != nil {
// TODO: retry
return e
@ -143,6 +153,7 @@ func (f *FileActionTask) DoAction(ctx context.Context) error {
}
if f.syncItem.Action == SyncFileActionCreateLocalFolder {
f.prompt("创建本地文件夹:" + f.syncItem.getLocalFileFullPath())
if e := f.createLocalFolder(ctx); e != nil {
// TODO: retry
return e
@ -165,6 +176,7 @@ func (f *FileActionTask) DoAction(ctx context.Context) error {
}
if f.syncItem.Action == SyncFileActionCreatePanFolder {
f.prompt("创建云盘文件夹:" + f.syncItem.getPanFileFullPath())
if e := f.createPanFolder(ctx); e != nil {
// TODO: retry
return e

View File

@ -25,3 +25,7 @@ const (
// TimeSecondsOf60Minute 60分钟秒数
TimeSecondsOf60Minute int64 = 60 * TimeSecondsOfOneMinute
)
var (
LogPrompt = false
)