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

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

USB backup batch file help needed.

I need to create a simple batch file that will copy the entire content from c:\data to f: which is a thumb drive, it needs to create a new folder with the date and time each time when ran it so it won't overwrite the same folder under the f: destination. It also has to be completely silent  not need to interact with the user after initiated. Can someone here help me please.
0
jdff
Asked:
jdff
  • 6
  • 2
1 Solution
 
oBdACommented:
Something like this?
@echo off
setlocal enabledelayedexpansion
set Source=C:\Data
set TargetRoot=F:
REM The next line sets the following DateTime variables: DT_Day, DT_DayOfWeek, DT_Hour, DT_Minute, DT_Month, DT_Quarter, DT_Second, DT_WeekInMonth, DT_Year
for /f "delims=" %%a in ('wmic.exe Path Win32_LocalTime GET * /value') do (for /f "delims=" %%b in ("%%a") do set DT_%%b)
for %%a in (DT_Month DT_Day DT_Hour DT_Minute DT_Second) do (if !%%a! LSS 10 set %%a=0!%%a!)
set Timestamp=%DT_Year%%DT_Month%%DT_Day%_%DT_Hour%%DT_Minute%
set Target=%TargetRoot%\%Timestamp%
robocopy.exe "%Source%" "%Target%" /e /r:0 /w:0

Open in new window

0
 
jdffAuthor Commented:
oBda, it worked perfectly, thank you very much. Is it possible to construct a command now that will copy the most recent date-stamped folder created on the thumb drive back to the C drive just as the restore function? I would be delighted to find out. Thank you.
0
 
jdffAuthor Commented:
Obda, do you think that my question is doable? If so I can open another question for the answer. Please let me know. Thank you.
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
Bill PrewCommented:
Yes, what you are asking for seems very doable since the archived folders have a date stamp on them it is just a matter of sorting those in chronological order and getting the name of the latest backup.  Then copying that back to the C: drive.  Probably need to specify if files should be overwritten, etc, but I would suggest a new question for the restore piece, and link it to this one after awarding points here and closing.

~bp
0
 
jdffAuthor Commented:
Worked flawlessly. Than you.
0
 
jdffAuthor Commented:
0
 
jdffAuthor Commented:
Can we have this script to ask the user the destination drive?
0
 
oBdACommented:
@echo off
setlocal enabledelayedexpansion
set Source=C:\Data
set TargetRoot=
set /p TargetRoot=Destination drive:
if "%TargetRoot%"=="" goto :eof
REM The next line sets the following DateTime variables: DT_Day, DT_DayOfWeek, DT_Hour, DT_Minute, DT_Month, DT_Quarter, DT_Second, DT_WeekInMonth, DT_Year
for /f "delims=" %%a in ('wmic.exe Path Win32_LocalTime GET * /value') do (for /f "delims=" %%b in ("%%a") do set DT_%%b)
for %%a in (DT_Month DT_Day DT_Hour DT_Minute DT_Second) do (if !%%a! LSS 10 set %%a=0!%%a!)
set Timestamp=%DT_Year%%DT_Month%%DT_Day%_%DT_Hour%%DT_Minute%
set Target=%TargetRoot%\%Timestamp%
robocopy.exe "%Source%" "%Target%" /e /r:0 /w:0

Open in new window

0
 
jdffAuthor Commented:
Will try, thank you.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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