Newby question: how could I write a program/script to automatically copy directories to a remote computer?
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 开发者_JAVA技巧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.
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.
#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:pass@ftp.host.com: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.
In the past i used the Windows utility : robocopy. But now you can use Google Drive.
精彩评论