Solved

Automatic Backup Restore

Posted on 2016-09-26
2
63 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 24

Accepted Solution

by:
NVIT earned 500 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
The viewer will learn how to dynamically set the form action using jQuery.
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)

777 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