如何使用批处理脚本将文件从一台 Windows 机器复制到特定驱动器中的另一台 Windows 机器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9598868/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 09:19:58  来源:igfitidea点击:

How to copy the file from one windows machine to another windows machine in a particular drive using batch script?

windows

提问by Hymansantho

In my windows server, am taking SQL DB backup in C drive. I wants to copy this .bak file to some other client windows machine in a particular drive with the current date using batch script. So that i can schedule this batch script using scheduled task. please help me out.

在我的 Windows 服务器中,我在 C 驱动器中进行 SQL DB 备份。我想使用批处理脚本将此 .bak 文件复制到具有当前日期的特定驱动器中的其他客户端 Windows 机器。这样我就可以使用计划任务来安排这个批处理脚本。请帮帮我。

Can anyone, give a script to run this. thanks

任何人都可以,给一个脚本来运行这个。谢谢

回答by Ben Russell

Batch files are always tricky to get just right. First I'd open a command line and see if you can copy between two machines using the following syntax:

批处理文件总是很难做到恰到好处。首先,我会打开一个命令行,看看您是否可以使用以下语法在两台机器之间进行复制:

copy C:\localfile.bak \remotemachine\c$\Path\remotefile.bak

(where "remotemachine" is the name of the remote machine and "c$" is the drive you wish to copy to). You can then copy this into a batch file and set up a scheduled task.

(其中“remotemachine”是远程机器的名称,“c$”是您希望复制到的驱动器)。然后,您可以将其复制到批处理文件中并设置计划任务。

As for renaming the file to have the current date and time, I suggest you start with this questionas it may involve some effort to get it into a format you want.

至于重命名文件以具有当前日期和时间,我建议您从这个问题开始,因为它可能需要一些努力才能将其转换为您想要的格式。