mirror of
https://github.com/tickstep/aliyunpan.git
synced 2025-01-23 14:32:14 +08:00
add log flag for sync command
This commit is contained in:
parent
d0ad94aa65
commit
9016c12c26
@ -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
|
@ -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}
|
||||
|
@ -31,5 +31,6 @@ services:
|
||||
- ALIYUNPAN_SYNC_MODE=upload
|
||||
# 优先级,只对双向同步备份模式有效。选项支持三种: time-时间优先,local-本地优先,pan-网盘优先
|
||||
- ALIYUNPAN_SYNC_PRIORITY=time
|
||||
|
||||
# 是否显示文件备份过程日志,true-显示,false-不显示
|
||||
- ALIYUNPAN_SYNC_LOG=true
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -25,3 +25,7 @@ const (
|
||||
// TimeSecondsOf60Minute 60分钟秒数
|
||||
TimeSecondsOf60Minute int64 = 60 * TimeSecondsOfOneMinute
|
||||
)
|
||||
|
||||
var (
|
||||
LogPrompt = false
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user