【问题标题】:How to automate copy files from one server location to another and move from the source location?如何自动将文件从一个服务器位置复制到另一个位置并从源位置移动?
【发布时间】:2020-12-03 13:33:34
【问题描述】:

我有一个服务器位置(源),客户端整天经常提供大量文件。我的任务是将它们复制到另一个服务器位置(目标)并将这些复制的文件从源位置移动到源服务器中的另一个子目录。喜欢:

Before Copy:

Server A
/files
  --- /done
  --- File1.xml
  --- File2.xml
  --- File3.xml

Server B
/files

After Copy to Destination Server B and copied files moved to done folder of Source Server A:

Server B
/files
  --- File1.xml
  --- File2.xml
  --- File3.xml

Server A
/files 
  --- File4.xml
  --- /done
    --- File1.xml
    --- File2.xml
    --- File3.xml

我想自动化这个过程,我已经查看了 windows robocopy 来实现这一点。但是,在复制文件时,每当客户端提供像 File4.xml 这样的新文件并且没有完全复制时,我都会遇到问题,复制它们也有风险。如上所述,如何正确复制和移动文件?两台服务器都在 Windows 上运行。

【问题讨论】:

标签: java python bash rsync robocopy


【解决方案1】:

您可以从“A”目录运行以下 python 脚本,然后工作就完成了。您可以定义一些时间(参见注释部分),以便忽略刚刚添加的文件

import os
import time
from shutil import copy
   for i in os.listdir():
       if i !='done' and #(time.time()-os.stat(i).st_ctime > define_some_time_limit_to_avoid_copying_recent_files):
           copy('source_path_A'+i, 'destination_path_B'+i)
           copy('source_path_A'+i, 'destination_path_A_done'+i)
           os.remove('source_path'+i)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-02
    • 1970-01-01
    相关资源
    最近更新 更多