Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Automatic Backup Restore

Posted on 2016-09-26
2
Medium Priority
?
116 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 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
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 the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
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

927 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