[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ROBOCopy Script help

Posted on 2011-05-11
8
Medium Priority
?
442 Views
Last Modified: 2012-05-11
I need a way to pick up "Copy" a SQL job that has the latest time stamp on it with a file name that varies. Is there a way to do this?

thanks
0
Comment
Question by:dmanisit
  • 5
  • 3
8 Comments
 
LVL 85

Expert Comment

by:oBdA
ID: 35738496
This will only copy the latest file in a give folder; just adjust the source and target folders to your likings, and add any robocopy options you might need:
@echo off
setlocal
set SourceFolder=C:\Temp
set TargetFolder=D:\Temp
for /f "delims=" %%a in ('dir /o:d /a:-d /b "%SourceFolder%"') do set LatestFile=%%a
echo Latest file in %SourceFolder%: %LatestFile%
robocopy.exe "%SourceFolder%" "%TargetFolder%" "%LatestFile%"

Open in new window

0
 

Author Comment

by:dmanisit
ID: 35738550
thats awesome, I left one thing out, there are several file names in there and I only want the latest time stamp with file name Ntier_JSA_backup_201105100100. But I only need it to look at Ntier_JSA_backup, not the 201105100100
0
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 35738580
Try this then:
@echo off
setlocal
set SourceFolder=C:\Temp
set TargetFolder=D:\Temp
set FileMask=Ntier_JSA_backup*.*
for /f "delims=" %%a in ('dir /o:d /a:-d /b "%SourceFolder%\%FileMask%"') do set LatestFile=%%a
echo Latest file in %SourceFolder%: %LatestFile%
robocopy.exe "%SourceFolder%" "%TargetFolder%" "%LatestFile%"

Open in new window

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:dmanisit
ID: 35738624
LOL. You are good. So the last thing I promise, It is picking up the transaction log, I need the .BAK file
0
 

Author Comment

by:dmanisit
ID: 35738630
i got it, thank you
0
 

Author Closing Comment

by:dmanisit
ID: 35738634
GREAT Help
0
 

Author Comment

by:dmanisit
ID: 35738740
One last thing, can I copy this to a network share? Drive z:\?
0
 
LVL 85

Expert Comment

by:oBdA
ID: 35738779
Assuming that this is a scheduled task and normally not run by an interactive user, use a UNC path as target folder, and make sure that the account that is used for the task has write access to the target share.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Here's a look at newsworthy articles and community happenings during the last month.
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Suggested Courses

868 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