[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

USB backup batch file help needed.

Posted on 2016-09-13
9
Medium Priority
?
149 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 85

Accepted Solution

by:
oBdA earned 2000 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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 57

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 85

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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

649 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