Hi guys,<\/p>\n
I am still new on this community and I need your help to build a robocopy script that can be used for do some tasks in one time only. Is it possible?<\/p>\n
So, here are the tasks that I want to perform by using robocopy script:<\/p>\n
1- Move files older than x days to another folder.
\n2- Take those files and zip them up. (name zipped file with the date stamp).
\n3- Delete the files that just got zipped.
\n4- Move Zipped files to another directory.<\/p>\n
Are there any of you guys here know how to do it?please help me and I will appreciating all of your suggestion or ideas. Thanks<\/p>","upvoteCount":7,"answerCount":28,"datePublished":"2012-11-22T17:42:56.000Z","author":{"@type":"Person","name":"gindonagarihenry8561","url":"https://community.spiceworks.com/u/gindonagarihenry8561"},"acceptedAnswer":{"@type":"Answer","text":"
So what you are saying is it does all the files in a folder, but not subfolders, is that correct?<\/p>\n
At which stage is it missing the subdirectories - when you are zipping the files, or when you are robocopying them?<\/p>\n
if it is at the 7zip stage, try adding “-r” (without quotes) which tells 7zip to recurse directories<\/p>\n
if it is at the robocopy stage, try adding /S which recurses directories<\/p>","upvoteCount":1,"datePublished":"2012-12-06T00:02:40.000Z","url":"https://community.spiceworks.com/t/solved-need-an-ultimate-robocopy-script/178463/25","author":{"@type":"Person","name":"jatus","url":"https://community.spiceworks.com/u/jatus"}},"suggestedAnswer":[{"@type":"Answer","text":"
Hi guys,<\/p>\n
I am still new on this community and I need your help to build a robocopy script that can be used for do some tasks in one time only. Is it possible?<\/p>\n
So, here are the tasks that I want to perform by using robocopy script:<\/p>\n
1- Move files older than x days to another folder.
\n2- Take those files and zip them up. (name zipped file with the date stamp).
\n3- Delete the files that just got zipped.
\n4- Move Zipped files to another directory.<\/p>\n
Are there any of you guys here know how to do it?please help me and I will appreciating all of your suggestion or ideas. Thanks<\/p>","upvoteCount":7,"datePublished":"2012-11-22T17:42:56.000Z","url":"https://community.spiceworks.com/t/solved-need-an-ultimate-robocopy-script/178463/1","author":{"@type":"Person","name":"gindonagarihenry8561","url":"https://community.spiceworks.com/u/gindonagarihenry8561"}},{"@type":"Answer","text":"
for robocopy move older than 10 days - chnage as you see to fit<\/p>\n
robocopy %source% %destination% /MOV /COPYALL /MAXAGE:10 /R:5 /W:30 /LOG+:log.txt<\/p>\n
and here you have entire script to zip files with date stamp and move<\/p>\n
http://community.spiceworks.com/scripts/show/835-zip-7zip-files-with-date-and-move-very-simple-and-works<\/a><\/p>","upvoteCount":2,"datePublished":"2012-11-22T18:32:49.000Z","url":"https://community.spiceworks.com/t/solved-need-an-ultimate-robocopy-script/178463/2","author":{"@type":"Person","name":"romankluka3758","url":"https://community.spiceworks.com/u/romankluka3758"}},{"@type":"Answer","text":" Thank you so much for responding my problem, but I still wondering if the scripts could be merged or combined in one file. Is it possible?do you know how to make it?<\/p>","upvoteCount":0,"datePublished":"2012-11-22T19:05:10.000Z","url":"https://community.spiceworks.com/t/solved-need-an-ultimate-robocopy-script/178463/3","author":{"@type":"Person","name":"gindonagarihenry8561","url":"https://community.spiceworks.com/u/gindonagarihenry8561"}},{"@type":"Answer","text":" yes it could be easily merged together as one batch file<\/p>","upvoteCount":2,"datePublished":"2012-11-22T19:30:23.000Z","url":"https://community.spiceworks.com/t/solved-need-an-ultimate-robocopy-script/178463/4","author":{"@type":"Person","name":"romankluka3758","url":"https://community.spiceworks.com/u/romankluka3758"}},{"@type":"Answer","text":" OK, but how to do that?I never using robocopy script before. so, please tell me in details. thanks<\/p>","upvoteCount":0,"datePublished":"2012-11-22T19:37:24.000Z","url":"https://community.spiceworks.com/t/solved-need-an-ultimate-robocopy-script/178463/5","author":{"@type":"Person","name":"gindonagarihenry8561","url":"https://community.spiceworks.com/u/gindonagarihenry8561"}},{"@type":"Answer","text":" Have you not done a batch file before?<\/p>\n They’re quite simple, just one line after another. They will complete in order, and won’t start until another is finished. (REM = comment)<\/p>\n REM Set locations<\/p>\n SET source = “”<\/p>\n SET destination = “”<\/p>\n SET finallocation = “”<\/p>\n REM Move files older than x days to another folder.<\/p>\n robocopy %source% %destination% /MOV /COPYALL /MAXAGE:10 /R:5 /W:30 /LOG+:log.txt<\/p>\n REM Take those files and zip them up. (name zipped file with the date stamp).<\/p>\n (See link from CloudMan)<\/p>\n REM Delete the files that just got zipped.<\/p>\n DELTREE /Y %desitination%<\/p>\n REM Move Zipped files to another directory.<\/p>\n MOVE /Y %destination% %finallocation%<\/p>\n After you have all this working, you might want to work on logging to help with any errors that may appear…<\/p>","upvoteCount":4,"datePublished":"2012-11-23T01:03:08.000Z","url":"https://community.spiceworks.com/t/solved-need-an-ultimate-robocopy-script/178463/6","author":{"@type":"Person","name":"jamessmith9657","url":"https://community.spiceworks.com/u/jamessmith9657"}},{"@type":"Answer","text":" To create a batch file, open Notepad, type the lines of code, then save as *.cmd extension. .bat works as well but is deprecated and some (more complex) functions do not work in .bat files, so it is good practice to always use .cmd unless you really know what you are doing and why.<\/p>","upvoteCount":2,"datePublished":"2012-11-23T05:54:33.000Z","url":"https://community.spiceworks.com/t/solved-need-an-ultimate-robocopy-script/178463/7","author":{"@type":"Person","name":"jatus","url":"https://community.spiceworks.com/u/jatus"}},{"@type":"Answer","text":" I haven’t had done any kind of robocopy script or any of batch files when working in network area. Usually I just configure some IPs or basic networking stuff. So, its my first time working with batch or cmd scripting. Anyway, thanks guys for all of your suggestion and help. I will testing the code and see if there are any error or problem, then I will let you know. Thanks<\/p>","upvoteCount":0,"datePublished":"2012-11-23T22:09:35.000Z","url":"https://community.spiceworks.com/t/solved-need-an-ultimate-robocopy-script/178463/8","author":{"@type":"Person","name":"gindonagarihenry8561","url":"https://community.spiceworks.com/u/gindonagarihenry8561"}},{"@type":"Answer","text":" Hi,<\/p>\n I have written the script as Smitro has been explained and I got an error. Here I have attached the script file and below is the error that I got recently :<\/p>\n ERROR : No Destination Directory Specified.<\/p>\n Simple Usage :: ROBOCOPY source destination /MIR<\/p>\n source :: Source Directory (drive:\\path or \\server\\share\\path). For more usage information run ROBOCOPY /?<\/p>\n **** /MIR can DELETE files as well as copy them !<\/p>\n Is that mean I have misconfigured any path?Please help me identify the error and again so sorry I still newbie in this scripting stuff as I have been so long not work with this kind of thing. Thanks<\/p>\n BackUp_3.rar<\/a> (513 Bytes)<\/p>","upvoteCount":0,"datePublished":"2012-11-23T22:51:23.000Z","url":"https://community.spiceworks.com/t/solved-need-an-ultimate-robocopy-script/178463/9","author":{"@type":"Person","name":"gindonagarihenry8561","url":"https://community.spiceworks.com/u/gindonagarihenry8561"}},{"@type":"Answer","text":" Hey mate. I just had a very quick looks at your script as I’m on my phone. Please kindly post the code in your repsonse instead of zipping it as it’s hard to access.<\/p>\n I can immediately see ay least part of your problem. You have to put the variable names in the %<\/p>\n For example: Apply the same principle to your code and you see how you go<\/p>","upvoteCount":1,"datePublished":"2012-11-25T09:35:03.000Z","url":"https://community.spiceworks.com/t/solved-need-an-ultimate-robocopy-script/178463/10","author":{"@type":"Person","name":"jatus","url":"https://community.spiceworks.com/u/jatus"}},{"@type":"Answer","text":" Yes, I have the same problem, I don’t have anything to open a rar file. If you don’t post it in line, a text file would be good.<\/p>","upvoteCount":1,"datePublished":"2012-11-25T22:18:35.000Z","url":"https://community.spiceworks.com/t/solved-need-an-ultimate-robocopy-script/178463/11","author":{"@type":"Person","name":"jamessmith9657","url":"https://community.spiceworks.com/u/jamessmith9657"}},{"@type":"Answer","text":" Hi guys,<\/p>\n So sorry for the problem, that’s my bad. I thought you guys always working with pc instead of phone. Okay here I show you the script that I have created recently based on Smitro guidance:<\/p>\n REM Set Destination Login Authentication<\/p>\n net use \\10.0.0.219\\Test Tsunami247 /user:10.0.0.219\\ITTest<\/p>\n REM Set locations<\/p>\n SET source = D:\\SafetyLineVoiceMsg<\/p>\n SET destination = \\10.0.0.219\\Test<\/p>\n SET finallocation = z:\\<\/p>\n REM Move files older than x days to another folder.<\/p>\n robocopy %D:\\SafetyLineVoiceMsg% %\\10.0.0.219\\Test% /MOV /COPYALL /MAXAGE:10 /R:5 /W:30 /LOG+:log.txt<\/p>\n REM Take those files and zip them up. (name zipped file with the date stamp).<\/p>\n 7z a \\10.0.0.219\\Test\\newFileName%date:~4,2%-%date:~7,2%-%date:~10%.7z @\\l10.0.0.219\\Test\\files_to_backup.txt<\/p>\n REM Delete the files that just got zipped.<\/p>\n DELTREE /Y %\\10.0.0.219\\Test%<\/p>\n REM Move Zipped files to another directory.<\/p>\n MOVE /Y %\\10.0.0.219\\Test*.*% %z:%<\/p>\n I named the file “BackUp_3.cmd”, but the script itself not working successfully. What the problem actually with it?<\/p>\n I was tested and ran the script on two machine like the following:<\/p>\n Source: D:\\SafetyLineVoiceMsg – contains some tested files to be backed up and its stored in windows 8 x64 (physical machine)<\/p>\n<\/li>\n Destination: \\10.0.0.219\\Test – this is a network folder that stored in windows 7 ultimate x64 (virtual machine using vitualbox)<\/p>\n<\/li>\n<\/ul>\n Those all some explanation related to my problem and if you need some more detail, let me know and again please guy I very need your help. Thanks<\/p>\n log.txt<\/a> (23.6 KB)<\/p>","upvoteCount":0,"datePublished":"2012-11-27T18:21:05.000Z","url":"https://community.spiceworks.com/t/solved-need-an-ultimate-robocopy-script/178463/12","author":{"@type":"Person","name":"gindonagarihenry8561","url":"https://community.spiceworks.com/u/gindonagarihenry8561"}},{"@type":"Answer","text":" @James<\/a>: I have tried your solutions but I still cannot run the script properly and got another new error like could not find any specific destination. See the log file and script that I have been included recently on my previous post. Thanks<\/p>","upvoteCount":0,"datePublished":"2012-11-27T21:51:50.000Z","url":"https://community.spiceworks.com/t/solved-need-an-ultimate-robocopy-script/178463/13","author":{"@type":"Person","name":"gindonagarihenry8561","url":"https://community.spiceworks.com/u/gindonagarihenry8561"}},{"@type":"Answer","text":" just briefly … change this line:<\/p>\n robocopy %D:\\SafetyLineVoiceMsg% %\\10.0.0.219\\Test% /MOV /COPYALL /MAXAGE:10 /R:5 /W:30 /LOG+:log.txt<\/p>\n to<\/p>\n robocopy %source% %destination%<\/strong> /MOV /COPYALL /MAXAGE:10 /R:5 /W:30 /LOG+:log.txt<\/p>","upvoteCount":0,"datePublished":"2012-11-27T22:12:06.000Z","url":"https://community.spiceworks.com/t/solved-need-an-ultimate-robocopy-script/178463/14","author":{"@type":"Person","name":"romankluka3758","url":"https://community.spiceworks.com/u/romankluka3758"}},{"@type":"Answer","text":" I already did it,but still not working. Here is my recent update of my script:<\/p>\n REM Set Destination Login Authentication REM Set locations SET destination = \\10.0.0.219\\Test REM Move files older than x days to another folder. REM Take those files and zip them up. (name zipped file with the date stamp). REM Delete the files that just got zipped. REM Move Zipped files to another directory. Is there any of above script still incorrectly typed or something?<\/p>\n log.txt<\/a> (26.4 KB)<\/p>","upvoteCount":0,"datePublished":"2012-11-27T22:23:04.000Z","url":"https://community.spiceworks.com/t/solved-need-an-ultimate-robocopy-script/178463/15","author":{"@type":"Person","name":"gindonagarihenry8561","url":"https://community.spiceworks.com/u/gindonagarihenry8561"}},{"@type":"Answer","text":" Please, after every change you make and test, paste the entire script in, and also the error message you received. Net use x: \\server1\\share1 /user:contoso\\james mypassword Here is my recent script that i have modified and still getting an error, check it:<\/p>\n REM Set Destination Login Authentication<\/p>\n net use c: \\10.0.0.219\\Test /user:10.0.0.219\\ITTest Tsunami247<\/strong><\/p>\n REM Set locations<\/p>\n SET source = D:\\SafetyLineVoiceMsg SET destination = \\10.0.0.219\\Test SET finallocation = z: REM Move files older than x days to another folder.<\/p>\n robocopy %source% %destination% /MOV /COPYALL /MAXAGE:10 /R:5 /W:30 /LOG+:log.txt<\/p>\n REM Take those files and zip them up. (name zipped file with the date stamp).<\/p>\n 7z a \\10.0.0.219\\Test\\newFileName%date:~4,2%-%date:~7,2%-%date:~10%.7z @\\10.0.0.219\\Test\\files_to_backup.txt REM Delete the files that just got zipped.<\/p>\n DELTREE /Y %desitination%<\/p>\n REM Move Zipped files to another directory.<\/p>\n MOVE /Y %destination% %finallocation%<\/p>\n and I don’t understand with your previous post. Which part or which lines contain that symbol I need to remove?<\/p>\n
\n
\ndestination :: Destination Dir (drive:\\path or \\server\\share\\path).
\n/MIR :: Mirror a complete directory tree.<\/p>\n
\nSET source = c:\\data
\nEcho %source%<\/p>\n\n
\nnet use \\10.0.0.219\\Test Tsunami247 /user:10.0.0.219\\ITTest<\/p>\n
\nSET source = D:\\SafetyLineVoiceMsg
\nEcho %source%<\/p>\n
\nEcho %destination%
\nSET finallocation = z:
\nEcho %finallocation%<\/p>\n
\nrobocopy %source% %destination% /MOV /COPYALL /MAXAGE:10 /R:5 /W:30 /LOG+:log.txt<\/p>\n
\n7z a \\10.0.0.219\\Test\\newFileName%date:~4,2%-%date:~7,2%-%date:~10%.7z @\\l10.0.0.219\\Test\\files_to_backup.txt
\nmove \\10.0.0.219\\Test*.* z:\\<\/p>\n
\nDELTREE /Y %desitination%<\/p>\n
\nMOVE /Y %destination% %finallocation%<\/p>\n
\nOtherwise we can’t tell what is wrong
\nOther than that, your net use line looks wrong. The format of net use is [net use] (optional drive letter) [path] (optional user) (optional password)
\nE.g.<\/p>\n
\nOr
\nNet use \\server1\\share1 /user:james
\nEtc<\/p>","upvoteCount":0,"datePublished":"2012-11-27T23:13:29.000Z","url":"https://community.spiceworks.com/t/solved-need-an-ultimate-robocopy-script/178463/16","author":{"@type":"Person","name":"jatus","url":"https://community.spiceworks.com/u/jatus"}},{"@type":"Answer","text":"
\nEcho %source%<\/p>\n
\nEcho %destination%<\/p>\n
\nEcho %finallocation%<\/p>\n
\nmove \\10.0.0.219\\Test*.* z:\\<\/p>\n