[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 875
  • Last Modified:

Specify filename in Robocopy script

Hi

I asked a question here about Robocopy on Windows 2003 server that Experts were really helpful on (thanks again!)

http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_26411867.html#a33467962

To summarise, here is the situation:

"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 was planning on using this command to copy the previous day's log files;

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

But, I notice that the app also creates some other files in each day's log folder that I don't need - all I need is the txt file starting with "log_<date>" - does anyone know how/if I can configure Robocopy to only copy over files that start with a certain name?
0
chuckp2010
Asked:
chuckp2010
  • 3
  • 2
  • 2
  • +3
3 Solutions
 
belowzerotechCommented:
you can probably use an asterisk as a wildcard. for example, C:\logs\2010*
0
 
SysExpertCommented:
there are options for include and exclude certain files in robocopy.
0
 
SysExpertCommented:
for excluding

 
/XF file [file]      Excludes files with the specified names, paths, or wildcard characters.         
/XD dir [dir]      Excludes directories with the specified names, paths, or wildcard characters.       

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
athomsfereCommented:
If they are only .txt files for example, then add *.txt and it will only copy the .txt files, as well as search for all .txt files in the folder.
0
 
chuckp2010Author Commented:
Thanks guys - I saw the switches to exclude, but not to include?
0
 
SysExpertCommented:
No Include option- default is everything.

C:\logs\20*\*.txt  or C:\logs\20*\Log*.txt  may work

you need to test

0
 
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
Here you are. =)

Robocopy "\\Server\C$\Logs" "\\Server2\C$\Copied" *LOG_* /ZB /MINAGE:1 /MAXAGE:2 /S
0
 
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
looks like you don;t even need *LOG_* since it always starts log, so I would change it to this:

Robocopy "\\Server\C$\Logs" "\\Server2\C$\Copied" LOG_* /ZB /MINAGE:1 /MAXAGE:2 /S



Robocopy "\\Server\C$\Logs" "\\Server2\C$\Copied" LOG_* /ZB /MINAGE:1 /MAXAGE:2 /S

Open in new window

0
 
t0t0Commented:
robocopy \\server\c$\logs\\ \\server2\c$\copied\\ log_* /maxage:2 /minage:1 /s
0
 
t0t0Commented:
wow! there were only THREE replies a mo ago. ah well, better late than never!
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

  • 3
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now