View Full Version : Windows cmd/batch monkeys (Robocopy and Del)
LeperousDust
01-05-2008, 01:25
Right well i fully except the usual people to appear in this thread :p ;D
Two problems: First i've got robocopy set up luuurvely and its mirroring happily see below:
robocopy.exe "D:\Documents" "E:\Backup\Documents" /S /ZB /COPYALL /LOG:E:\Backup\Documents.txt /DCOPY:T /R:10 /TEE
robocopy.exe "D:\Pictures" "E:\Backup\Pictures" /S /ZB /COPYALL /LOG:E:\Backup\Pictures.txt /DCOPY:T /R:10 /TEE
robocopy.exe "D:\Videos" "E:\Backup\Videos" /S /ZB /COPYALL /LOG:E:\Backup\Videos.txt /DCOPY:T /R:10 /TEE
robocopy.exe "D:\Music" "E:\Backup\Music" /S /ZB /COPYALL /LOG:E:\Backup\Music.txt /PURGE /DCOPY:T /R:10 /TEE
PAUSE
EXIT
I'm happy to have a carbon copy type process for my music as its a huge collection, but as you can see from the others, its more of an accumulation of files over time. What i'm kinda after is a way to make the documents robocopy process Incremental or Differential, is this feasible?
Second problem:
I want to make my downloads folder temporary, so files with certain attributes date/size/type etc... are deleted, and/or moved, but i have no idea where to start properly with if statement regarding attributes in batch files.... :confused:
A lot of this is over my head! Googling is drawing blanks annoyingly so a little nudge in the right direction would be appreciated :)
OK - for the first one, robocopy should be (sort of) incremental (i.e. only copy the files that have changed) - unless you tell it not to be. There is, however, a caveat to this - and that is if the copy is between two different filesystem types.
This problem arises because different filesystems have different 'granularity' in the way they store file times. For example, NTFS is accurate to milliseconds, but FAT is accurate to two seconds. Robocopy doesn't account for this by default, but adding the /FFT switch may help with that. Looks like I need this switch too so this research has been useful for me. :)
PS - you could have also considered using the /M switch here, but that relies on well-behaved applications, and some of them aren't well-behaved (guilty :o).
As for the second, I don't think you can do that with an IF statement, but maybe robocopy to the rescue here - look at combining the /MOVE and /MINAGE options, for example.
/MINAGE
I sniggered for a few seconds before noticing the 'A' there.
I sniggered for a few seconds before noticing the 'A' there.
Child.
(joins in with the sniggering)
ERROR : Invalid Parameter #1 : "/MINGE"
Sorry. :'(
LeperousDust
01-05-2008, 12:33
Get this filth out of here :p
The problem with robocopy is it write to the same destination file all the time, so although it writes a differential backup, i'm still left with only one backup copy. How can i write a script to say every x times its run write over the main folder again and delete the two extras, and every other time make a new folder and copy in there...
Robocopy for my download folder is possibly genius actually i hadn't thought of that, move them all to one folder and erase that instead, i'll look into that...
Ah, those. :)
You'll need two scripts - one to do the main backups and one for the incrementals. Use /MAXAGE or /A (not /M) on the incrementals and delete them in the main backup script (after completing the backup).
Another trick you can do with smaller backups (not the media library) is to robocopy the main backup to another backup (backup2) before updating the main backup. This gives you some history a bit like Apple's Time Machine. You can do this ad infinitum (backup3/4/5/6...) for as much disk space (or patience) as you have. :)
LeperousDust
01-05-2008, 12:57
Right so let me get this straight (as so far my head is pretty fudged with robocopy scripts :D).
I need a main backup script which rewrites the primary backup folders ever x times.
Another script which makes a new folder (called "one" we'll say) how does this compare source with destination and then write only the changed files into "one"?
Then i need another backup script that covers the two drives before, etc... yeah? I can't see in my head how i can do this, becuase roboycopy compares source with destination right?
I'm having more luck with the tempory folder though ;) :D
OK - the easiest way to do this with robocopy as follows...
Script One...
The backup script as you have it now (does the main backup). However, at the end of the script, for each backed up folder, you need to add:
attrib -a <foldername> /s
And then delete the incremental backup directory ("one").
Script Two...
The original backup script as you had it (i.e. without the attrib commands), but change the destination directory of each robocopy (so it goes in "one") and add the /A option on the end.
This does rely on progams being good and setting the archive bit, which most do but some may not. YMMV - experiment with it.
The other option is use of /MAXAGE to catch any files modified within the last 'x' days (x being a number that is at least the interval between full backups - and adding an extra day may not be a bad idea). To do this, you don't need the attrib changes from step 1, and you should replace /A with /MAXAGE:x in step 2. This avoids 'broken' software forgetting to set the attribute bit. It may backup a few more files than you need, however.
LeperousDust
01-05-2008, 13:42
Ahhh i see where you're going now :) I looked at max age, but i don't backup to a scehdule, its a removable drive and the contents don't change that often on this laptop to workout a schedule really, i just plug in as and when... So basically some software may mess up the archive bit i'm leaving behind on some of my documents depending on how the software was written... As i though this is turning out a little more complicated than first though :p :D Not too sure if its worth the hassle of probably not working properly, i'm not sure how much i will gain from being able to see back the last 3-5 copies of a file... I don't change all that much...
Thanks a load for the help though Mark :) I've got my temr download script working as it should i think just a little more testing but its there!
MarcLister
01-05-2008, 23:25
Alex you sodding genius! This is what I needed for my final year project dissertation. I got a bit obsessive compulsive with backing it up. :D
Had a copy on my D:\ drive which is the main location, then a copy in my My Documents on C:\ which is a different physical disk. Then another copy on my external HDD and two more on my two USB pendrives. ;D
I really wanted a batch file to copy the fyp.docx file to each of the backup locations. I'm guessing I couldn't make one command copy the file five times but need five different lines of code each with a different location?
Also does the batch file need to be in the same folder as the robocopy.exe?
I really wanted a batch file to copy the fyp.docx file to each of the backup locations. I'm guessing I couldn't make one command copy the file five times but need five different lines of code each with a different location?
I think you can add multiple desinations to a single line, it has been a while since I've used it (and I'm using the Macbook so can't check) though. From memory the Robocopy GUI (http://technet.microsoft.com/en-us/magazine/cc160891.aspx) is useful in situations like these.
Also does the batch file need to be in the same folder as the robocopy.exe?
Nope, as long as robocopy.exe is in your PATH the batch file can be anywhere.
MarcLister
01-05-2008, 23:47
Cheers Burble. Perhaps you can explain my real problem then. :)
I run my robocopy.bat file which is in the same folder as robocopy.exe. However the command prompt says that '`╗┐robocopy.exe' is not recognized as an internal or external command, operable program or batch file.
Is it just that I need to add robocopy.exe to my PATH or is something silly going on in Notepad++?
That's because you called both things 'robocopy', you doofus. :p ;D
Rename the batch file to something else (something will probably bleat at you at some random future date if you rename robocopy.exe).
Oh, and only one destination at a time, so you'll need multiple commands. :)
MarcLister
02-05-2008, 09:06
Who are you calling doofus? Me, oh Ok. :D
Cheers. :)
MarcLister
03-05-2008, 16:24
Got it working. Woo. :D
Now to add Robocopy to my PATH. Would adding ";C:\Program Files\Robocopy\Robocopy.exe" work? I put the ";" in because of the preceding entry in the PATH list. :)
copy robocopy.exe C:\Windows\System32 would work too.
Yeah, I know - trés naughty, but sue me. :p :evil:
No need to name the exe Marc, just the directory.
And yes Mark, tres naughty :p
Like I said. And besides, it's an official Microsoft utility (they even put it there themselves with Vista).
MarcLister
03-05-2008, 17:29
No need to name the exe Marc, just the directory.Ta muchly. :D
MarcLister
09-03-2009, 16:48
Super-mega-licious-bumpeh!
Finally got this to work. I wanted to copy my music from my PC to my external HDD so I was up until 4am this morning getting my batch file to work.
First problem was the old "'`╗┐robocopy.exe' is not recognized as an internal or external command, operable program or batch file" from a few posts back. Since the bat file WASN'T called robocopy.bat I knew this was a silly error somewhere. I finally fixed that but when I twigged I could get robocopy to export a log to a text file AND show me the progress on screen I couldn't understand why whatever file I selected, at random for testing, couldn't be accessed. The 'source' files were there, weren't hidden or read only. So I tried the /B and /ZB flags. Robocopy now tells me I don't have the backup privileges. Cue muchos "Huh? Je suis le admin de la ordinateur merci bien!". So I checked out my account just to be sure. Yup I'm OK. So I tried more files to copy over and still can't access them. Then something tells me that since I'm sure the source is OK, I might want to check the destination. Spent a few minutes fiddling and faddling around. Then I check my permissions on the external HDD. Hmm, nothing ticked in the boxes at all. Theoretically I can't write or read to this damned external HDD. So I tick all the boxes and run Robocopy again. IT WORKS!!!!
So I then copy my 37.7Gb of music from source to destination in almost exactly about 30 minutes. :D
vBulletin® v3.7.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.