Everybody needs to copy something. Everybody needs to copy something automatically. From Linux it’s easy, just “cp”, “rsync” or similar. Then a crontab, and you’re done. But how do you do in on Windows? I’m a “lucky” person, and I have access to all a zoo of OSs, from Windows XP to Windows 10 (batteries not included). In principle, I will need to automate the data transfer from the Windows PCs to our Linux-based (RedHat) PB storage system. Let’s start from the easy one. We have the data on a local hard disk, let’s say on C:\Data, and we want to copy it to “S:”, our network-mounted drive storage. If we want to automate something, first is to have a working Windows script. Our script, ideally, also leaves some kind of track of what it does, on a txt file. Our skeletical script is this one:
echo %date% %time% >> S:\logs\transfer_log.txt echo " starting ----" >> S:\logs\transfer_log.txt Xcopy C:\Data S:\ /S/E/K/Y echo %date% %time% >> S:\logs\transfer_log.txt echo " done ---------" >> S:\logs\transfer_log.txt
We open the notepad, and write this or similar, then we record it as “copy_2_S.bat“. Double click on it will open a command window, that will flash away something and disappear, or stay depending of the size of the folder you want to copy to “S”. If your Windows 7 is one of the good ones, you’re done. Go to “S” and check the logs. It looks easy, isn’t? Wrong. I do the same for another Windows 7 and … yes, surprise, surprise! Nothing happens. To debug, I just take the “xcopy” line, and paste it on a command windows. The errors that appears are like these ones:
Invalid Drive Specification
0 File(s) copied
Since I don’t have time, as usual, I go for trying out another known solution, robocopy. Our robocopy version of the script looks like:
echo %date% %time% >> S:\logs\transfer_log.txt echo " starting ----" >> S:\logs\transfer_log.txt robocopy C:\Data S:\ /E echo %date% %time% >> S:\logs\transfer_log.txt echo " done ---------" >> S:\logs\transfer_log.txt
This seems to work, no error displayed. Note that the copying options (/E) are not the same. We will describe the effect of the change later, together with the automation. Keep an eye on the updates of this post, if possible.