[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Help with Robocopy script

Posted on 2010-08-18
16
Medium Priority
?
862 Views
Last Modified: 2012-05-10
Hi

I have a Windows 2003 server where I have an application that logs daily files. The folder is C:\Logs, and each day, a folder with the date is created and, within this, a log file with the date too.

For example:

C:\Logs\20100812\Log_20100812.txt

This process continues. So, after a week, I would have folders such as:

C:\Logs\20100813
C:\Logs\20100814
C:\Logs\20100815

etc, each with their own log file within.

I would like to copy each day's log file to another server and was going to use Robocopy via a scheduled task. Basically, each day, I would want to upload the previous day's log file. But I'm not sure how to upload the previous day's log file only, and leave the rest alone? Does anyone know what sort of switches I could use?
0
Comment
Question by:chuckp2010
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
  • 2
  • +1
16 Comments
 
LVL 1

Accepted Solution

by:
Sheshiro earned 1000 total points
ID: 33466335
/MAXAGE:n :: MAXimum file AGE – exclude files older than n days/date.

If you want only the last days files:

Robocopy   /MAXAGE:1

0
 
LVL 14

Assisted Solution

by:athomsfere
athomsfere earned 1000 total points
ID: 33466457
A vbscript or Batch file could help load the data, but XCopy or even XXCopy might be better...

For the best flexibility check out xxcopy
http://www.xxcopy.com/xxcopy17.htm
0
 

Author Comment

by:chuckp2010
ID: 33466636
Thanks both....I'll check out xxcopy.

Regarding:
"
/MAXAGE:n :: MAXimum file AGE – exclude files older than n days/date.

If you want only the last days files:

Robocopy <source> <destination> /MAXAGE:1"

Let's say that I set that up as a scheduled task today (Wed). Remember that I want to upload the -previous- day's files every day, i.e. on a Thursday, I want to upload Wednesday's files etc.

So I set up the scheduled Robocopy command above to run at 01:00 every day. So on Thursday morning at 01:00, I want Wednesday's log file copied over.

But - because I specifying to exclude folders older than one day, am I not going to upload Thursday's file (i.e. a file that has an age of 0)?

Hope my q makes sense :)
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
LVL 1

Expert Comment

by:Sheshiro
ID: 33466747
So there is both a Wed and Thurs file, but you only want to grab Wed?
If that's the case then you would need to play with /MINAGE as well
I believe that you can set minage to 0 and it will exclude the last 24 hours, but you'd need to play with it to get your timestamps the way you want them.
0
 
LVL 14

Expert Comment

by:athomsfere
ID: 33466789
Yes, makes sense!

You should be able to also use the /minage:1 switch to say the folder/ file needs to be at a minimum 1 day old.
0
 

Author Comment

by:chuckp2010
ID: 33467152
Hmm, still not working. The problem is that for yesterday, the log could have been written to last at any point in that 24 hour period, depending on the application's activity.

Is there anyway with Robocopy to just say - "if the file was written to at any point yesterday, then copy it to xx"
0
 

Author Comment

by:chuckp2010
ID: 33467474
Actually

From testing, this seems to work:

robocopy \\server\c$\logs\\ \\server2\c$\copied\\  /maxage:2 /minage:1 /s

I just want to be sure though :) The previous day's log file can be written to any time in yesterday's 24 hour period, depending on the app usage, so would maxage:2 and minage:1 cover all bases?
0
 
LVL 1

Expert Comment

by:Sheshiro
ID: 33467618
I just tested it:
MAXAGE:2 will give you the previous 24 hours (i.e. the 24 hours prior to the current 24 hour period)
MINAGE:1 will skip anything from the current 24 hours
0
 

Author Comment

by:chuckp2010
ID: 33467682
Thanks..but when you say 24 period, do you mean "day"?

So say I wanted the script to run at 01:00 every day.

On Thursday 01:00, the script runs with /maxage:2 and minage:1

The last time the Wed log file was updated was Wed 22:00

Would Wed's file still be copied over?
0
 
LVL 17

Expert Comment

by:aflockhart
ID: 33467743
If you know the exact folder name that you want to copy  - which you do, it';s yesterdays date in yyyymmdd format - you could build a string variable in a batch file to consist of the year, month and day; then Robocopy from the folder of that name, without switches.

I've used a similar code snippet for a while in a similar situiation, creating folders for a specific day's backup.   The batch file code is a bit obscure, but seems to work OK.  Note that the details are sensitive to the date format that is configured on your system

Where I got it:  http://www.tech-recipes.com/rx/956/windows-batch-file-bat-to-get-current-date-in-mmddyyyy-format/


REM to test your date format - see what order things come out
For /f "tokens=1,2,3,4,5 delims=/. " %%a in ('date/T') do set CDate=%%a-%%b-%%c-%%d-%%e
@echo testdate = %CDate%

rem Once you know the order, Combine them in whatever way suits you - this works on mine but may be 

different on yours
For /f "tokens=1,2,3,4,5 delims=/. " %%a in ('date/T') do set CDate=%%c%%b%%a
@echo date = %CDate%

md \\newserver\logs\%Cdate%
robocopy c:\logs\%Cdate%  \\newserver\logs\%Cdate%

Open in new window

0
 
LVL 17

Expert Comment

by:aflockhart
ID: 33467782
note - some line breaks have been corrupted in the code I posted: LINE 7 should be attached to the end of line 5.  You can lose all the testing and ECHO commands after you know it iis working.
0
 
LVL 1

Expert Comment

by:Sheshiro
ID: 33467877
It's a rolling 24 hour period, so no, a file that was timestamped with 22:00 Wed would not get copied on Thurs 01:00 task as it's only 3 hours old.
0
 

Author Comment

by:chuckp2010
ID: 33467962
Thanks both -

Sheshiro - if I ran the task on Friday at 00:00, then I guess that would cover it? The last 24 hours would exclude all of Thursday, and the previous 24 hours would include all of Wednesday?

aflockhart - thanks, I will check that out!
0
 
LVL 1

Expert Comment

by:Sheshiro
ID: 33468002
"Sheshiro - if I ran the task on Friday at 00:00, then I guess that would cover it? The last 24 hours would exclude all of Thursday, and the previous 24 hours would include all of Wednesday?"
- Correct, the wed 22:00 file is 26 hours old and would be picked up on Friday 00:00
0
 

Author Comment

by:chuckp2010
ID: 33468333
Thanks Sheshiro.

Can you think of anyway that I can perform the same objective (i.e copy over the previous day's [Wed] file only), but have the Robocopy run at some point on the next day (Thurs) rather than Friday 00:00?
0
 
LVL 1

Expert Comment

by:Sheshiro
ID: 33468371
If the file stops getting written to @ 22:00 Wed, then setting the robocopy to run @ 22:15 Thursday would do it.

Other than that, I'm sure there's a For loop that could do it... but I'm not a codemonkey :-)
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question