Solved

USB backup batch file help needed.

Posted on 2016-09-13
9
106 Views
Last Modified: 2016-12-24
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
Comment
Question by:jdff
  • 6
  • 2
9 Comments
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 41797319
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
 

Author Comment

by:jdff
ID: 41805865
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
 

Author Comment

by:jdff
ID: 41815237
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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 53

Expert Comment

by:Bill Prew
ID: 41815878
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
 

Author Closing Comment

by:jdff
ID: 41817180
Worked flawlessly. Than you.
0
 

Author Comment

by:jdff
ID: 41817182
0
 

Author Comment

by:jdff
ID: 41936947
Can we have this script to ask the user the destination drive?
0
 
LVL 84

Expert Comment

by:oBdA
ID: 41936996
@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
 

Author Comment

by:jdff
ID: 41936999
Will try, thank you.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

839 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