Backup a local folder to a network drive with user interaction (BAT)

Purpose: Create a small backup program that a user can launch as he likes

In a corporate environment, different methods of backups are used. However, there might be a need for a small group of people to create something special. The need might raise for those who use an application that requires the USERS to be able to backup the application themselves. This of course puts the backup process into different set of hands (the user) but if that is the wish – it can be done and most importantly – easily. This example assumes that the network drive is backuped with other methods.

Functionality

This application copies a folder of your choice to a network folder. Every launched instance of this application creates a backup subfolder based on the execution time and will return minimal output to user what was the outcome of the backup process.

The following variables create the “current date time-stamp”
var_year%_%var_month%_%var_day%_%var_hour%_%var_mins%_%var_secs%

You can use other batch variables as you see fit (like the %USERNAME%).

Place the program, for example, under C:\ProgramData\MyBackupProgram\
and drop a shortcut on the user desktop c:\Users\Public\Desktop\

Source code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
@echo off
 
echo ----------------------------------------------------------
echo -- BACKUP LOCAL FILES ------------------------------------
echo ----------------------------------------------------------
echo -- Guide your users what is about to happen here.
echo ----------------------------------------------------------
 
set var_year=%Date:~9,4%
set var_month=%DATE:~6,2%
set var_day=%date:~3,2%
set var_hour=%TIME:~0,2%
set var_mins=%TIME:~3,2%
set var_secs=%TIME:~6,2%
 
echo -- You are creating backup: %var_year%_%var_month%_%var_day%_%var_hour%_%var_mins%_%var_secs%
echo ----------------------------------------------------------
 
pause
 
if not exist "\\YOUR_TARGET_PATH\%var_year%_%var_month%_%var_day%_%var_hour%_%var_mins%_%var_secs%\" mkdir "\\YOUR_TARGET_PATH\%var_year%_%var_month%_%var_day%_%var_hour%_%var_mins%_%var_secs%\"
xcopy /Y "c:\YOUR_SOURCE_PATH\*.*" "\\YOUR_TARGET_PATH\%var_year%_%var_month%_%var_day%_%var_hour%_%var_mins%_%var_secs%\"
if %errorlevel% EQU 0 call:OK
if not %errorlevel% EQU 0 call:FAIL
 
GOTO:EOF
 
:OK
echo ----------------------------------------------------------
echo -- Backup finished successfully! -------------------------
echo -- You can now close this application. -------------------
echo ----------------------------------------------------------
 
pause
GOTO:EOF
 
:FAIL
echo ----------------------------------------------------------
echo *** Backup has finished with an ERROR: (%errorlevel%)
echo ----------------------------------------------------------
pause
GOTO:EOF
@echo off

echo ----------------------------------------------------------
echo -- BACKUP LOCAL FILES ------------------------------------
echo ----------------------------------------------------------
echo -- Guide your users what is about to happen here.
echo ----------------------------------------------------------

set var_year=%Date:~9,4%
set var_month=%DATE:~6,2%
set var_day=%date:~3,2%
set var_hour=%TIME:~0,2%
set var_mins=%TIME:~3,2%
set var_secs=%TIME:~6,2%

echo -- You are creating backup: %var_year%_%var_month%_%var_day%_%var_hour%_%var_mins%_%var_secs%
echo ----------------------------------------------------------

pause

if not exist "\\YOUR_TARGET_PATH\%var_year%_%var_month%_%var_day%_%var_hour%_%var_mins%_%var_secs%\" mkdir "\\YOUR_TARGET_PATH\%var_year%_%var_month%_%var_day%_%var_hour%_%var_mins%_%var_secs%\"
xcopy /Y "c:\YOUR_SOURCE_PATH\*.*" "\\YOUR_TARGET_PATH\%var_year%_%var_month%_%var_day%_%var_hour%_%var_mins%_%var_secs%\"
if %errorlevel% EQU 0 call:OK
if not %errorlevel% EQU 0 call:FAIL

GOTO:EOF

:OK
echo ----------------------------------------------------------
echo -- Backup finished successfully! -------------------------
echo -- You can now close this application. -------------------
echo ----------------------------------------------------------

pause
GOTO:EOF

:FAIL
echo ----------------------------------------------------------
echo *** Backup has finished with an ERROR: (%errorlevel%)
echo ----------------------------------------------------------
pause
GOTO:EOF

Leave a Reply

Your email address will not be published. Required fields are marked *


six + = thirteen

Post Navigation