Solved

Automatic Backup Restore

Posted on 2016-09-26
2
46 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
2 Comments
 
LVL 23

Accepted Solution

by:
NVIT earned 500 total points
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

743 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

18 Experts available now in Live!

Get 1:1 Help Now