Solved

USB backup batch file help needed.

Posted on 2016-09-13
9
119 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
[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
  • 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 54

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

732 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