新手问题:如何编写程序/脚本来自动将目录复制到远程计算机?

发布于 2024-08-08 12:59:37 字数 794 浏览 7 评论 0 原文

首先,我对程序员和程序员怀有最大的尊重。 IT 专业人员。我是一个新手/想要成为的人。我正在寻求开发一个小程序/脚本的帮助,以帮助我完成下面详细介绍的任务。我不会将此作为作业提交。这是与工作相关的,但我并不是要求你做我的工作。我以此为契机,通过完成我需要完成的任务来了解更多有关编程的知识。您可能提供的任何代码都会有所帮助,但我对核心概念、步骤以及您关于如何最好地解决此任务的建议(哪些工具、语言等)非常感兴趣。

以下是我所拥有的: XP 机器(本地和远程) 批处理文件的一些基础知识 使用 Visual Basic 2008 Express 的一点经验 一点点 C++ 经验(并且有代码块编译器)

这就是我想做的:

每个周一至周五的午夜,我想要一台我将设置并可以访问的异地计算机 (#1) 1.从休眠中唤醒 2. 通过 ftp 连接或 Internet 将目录 (\Server\remoteBackup) 及其所有内容从办公室(将打开)的选定计算机 (#2) 复制(或 xcopy)到异地计算机 (C:\远程备份) 3. 将“successfulCopy.txt”文件放在另一台选定的计算机上 (#3) (\machine3\log)。每个“successfulCopy.txt”文件应检查是否存在“successfulCopy.txt”,如果存在,请将新文件重命名为“successfulCopy(2).txt”或其他名称。 4. 返回休眠状态(完成后或按计时器)

这基本上是一个远程备份系统。你有什么想法?如果您提供的任何想法都以一种方式命名,那么如果我有进一步的问题,我可以通过谷歌搜索您的答案以了解更多信息,那将是最有帮助的。我感谢您能提供的任何帮助。我想这样做是因为我想这样做,没有其他原因。

Firstly, I have the utmost respect for programmers & IT professionals. I'm a newby/wanna-be. I'm looking for help on developing a small program/script that helps me with the task I have detailed below. I am NOT submitting this as homework. This is work-related, but I'm NOT asking you to do my job. I'm taking this as an opportunity to learn more about programming by doing a task that I need done. Any code you may provide will be helpful but I'm very interested in core concepts, steps, and your advice on how best to tackle this task (which tools, language, etc.)

Here's what I have:
XP machines (local and remote)
Some basic knowledge of batch files
A tiny bit of experience with Visual Basic 2008 Express
A TINY bit of C++ experience (and have the Code Blocks compiler)

Here's what I want to do:

Every Mon-Fri at midnight, I want an offsite machine (#1) that I will set up and can access to
1. wake up from hibernate
2. copy (or xcopy) a directory (\Server\remoteBackup) with all its contents from a selected machine (#2) at the office (that will be on) through an ftp connection or internet to the offsite machine (C:\remoteBackup)
3. put a "successfulCopy.txt"file on another selected machine (#3) (\machine3\log). Each "successfulCopy.txt" file should check to see if exists "successfulCopy.txt" and if so, rename the new to "successfulCopy(2).txt" or whatever.
4. go back into hibernate (either when finished or on a timer)

This is basically a remote backup system. What are your thoughts? Any ideas you provide would be most helpful if you name them in a way that I could Google your answer to learn more if I have further questions. I appreciate any help you can provide. I want to do this because I WANT to do this and for no other reason.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

多孤肩上扛 2024-08-15 12:59:37

这就是 rsync 的用途。您可以安装 cygwin (如何使用 Rsync 安装 Cygwin)。然后你可以启动“cron”调度程序(如何在 Cygwin 中启动 cron),它应该很简单......对于馅饼的价值,不幸的是,馅饼人在所有这些东西上都有经验。好吧,如果你有兴趣,你可以执行上述操作,但我必须承认,这对新手不友好。

您可能可以使用批处理文件完成整个事情:不需要在实际的编程语言中做太多事情。我会使用类似 7zip 来打包目录...7zip 是命令行友好的,并且具有“更新”功能,通过允许增量“备份”可以节省您大量时间。

然后,一旦获得该文件,您就可以使用命令行友好的 FTP 程序(例如 WinSCP )将文件发送到您喜欢的任何地方。将这两个放在一起,您最终会得到一个 2 行批处理文件,尽管您仍然需要唤醒机器。

This is the sort of thing that rsync was made for. You can install cygwin (How to install Cygwin with Rsync). Then you can start up the "cron" scheduler (How to start cron in Cygwin), and it should be easy as pie...For values of pie where the pie person is experienced in all this stuff, unfortunately. Okay, if you're interested, you can do the above, but it's not newbie friendly, I have to admit.

You can probably do the whole thing with a batch file: no need to much around in actual programming languages. I'd use something like 7zip to package the directories...7zip is command line friendly, and has an "update" function, which could save you a lot of time by allowing incremental "backups."

Then, once you have the file, you can use a command line friendly FTP program (like WinSCP) to send the file where ever you like. Put both of those together, and you'll end up with a 2 line batch file, though you'll still have to wake the machine up.

小清晰的声音 2024-08-15 12:59:37

#1 嗯...在控制面板的任务部分中规划工作就可以了。

#2 xcopy 有多个选项,例如 /S 和 /Q 等,甚至还有一个仅用于获取较新的文件。由于我没有任何 Windows,目前无法检查。 xcopy 支持 UNC 路径,但如果我是对的,ftp 不起作用。您可以尝试使用符号 ftp://user:[ email protected]:port/folder/file.txt

#3 可以使用 echo "" > 创建文件successCopy.txt,并且文件现有功能/特性也应该存在于 Windows-Shell 中。

#4 Hibernate可以通过调用带有特殊参数的shutdown.exe来实现。在这里,您可以通过在 cmd 窗口中输入 shutdown /? 来查看参数列表。

这意味着 Windows .bat 文件足以完成您的工作。也许您想用 VB-Script 编写它,这需要更多的工作,但也应该可以。

祝你好运。

#1 Well... Planning the job in the Tasks-part of your Control Panel will do fine.

#2 xcopy has several options like /S and /Q etc. and there's even one for only taking newer files. As I don't got any Windows anymore, I cannot currently check. xcopy supports UNC-paths but ftp doesn't work if I'm right. You might try to write to a location using the notation ftp://user:[email protected]:port/folder/file.txt

#3 a file can be created using echo "" > successfulCopy.txt, and file existing functions/features should exist as well in Windows-Shell.

#4 Hibernate can be achieved by calling the shutdown.exe with special parameters. Here you can see a list of parameters by typing shutdown /? into a cmd-window.

This means a windows .bat-file is sufficiently enough to do your job. Maybe you want to write it in VB-Script, this would take some more work but should do as well.

good luck.

棒棒糖 2024-08-15 12:59:37

过去我使用 Windows 实用程序:robocopy。但现在您可以使用 Google 云端硬盘。

In the past i used the Windows utility : robocopy. But now you can use Google Drive.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文