Solved

USB backup batch file help needed.

Posted on 2016-09-13
6
65 Views
Last Modified: 2016-09-26
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
  • 4
6 Comments
 
LVL 83

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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 51

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

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
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 …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now