Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Automatic Backup Restore

Posted on 2016-09-26
2
Medium Priority
?
105 Views
Last Modified: 2016-10-14
I need some help to restore the last backup folder from the USB pen drive based on the code below.

@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
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
2 Comments
 
LVL 25

Accepted Solution

by:
NVIT earned 2000 total points
ID: 41817275
Currently in test mode for debugging reasons. To run for real, remove the ECHO on line 16.
Adjust Source and TargetRoot values per your needs.

@echo off
setlocal enabledelayedexpansion
REM Copies the newest folder to target.
REM Assumes Source folders have names like:
REM   YYYYMMDDHHMM
REM e.g.
REM   200805032247
REM   201210110353
REM   201610110353

REM Adjust Source and TargetRoot values per your needs

set Source=F:\
set TargetRoot=C:\target
set Timestamp=%DT_Year%%DT_Month%%DT_Day%_%DT_Hour%%DT_Minute%
set Target=%TargetRoot%
for /f "tokens=1*" %%a in ('dir /o-d /b "%Source%"') do (
  ECHO robocopy.exe "%Source%\%%~na" "%Target%\%%~na" /e /r:0 /w:0
  exit /b
)

Open in new window

0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

715 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