ListBackup.cmd - Simple scripts for Backup in Windows using MSDOS
Once we have backup our files there will be the occasion we need to recover a file, but, what file to restore?
Using this script we can list the contents of all available backup (RAR) files, looking for a given file name.
Within the script, we first set local variables, after that, we find the fin the backup directory and every directory within; each inner directory represents a backup day. This is easy task because the backup directory has a fixed name and a DIR command gives us the internal directories
FOR /F "usebackq delims==" %%i IN (`dir /oe-n/b/ad %backupDir%`) do (
For each directory, we find the containing RAR files, again a DIR command helps us with it.
FOR /F "usebackq delims==" %%x IN (`dir "%backupDir%\%%i\*.rar" /oen/b`) do (
The format of RAR files, when they are split in several archives is:
<main RAR name>[.part<consecutive number>].rar
For example, for a single file: temp.rar
First file of a sequence: temp.part1.rar
In case we find “part” as part of the name, it is almost sure we need to skip that file, unless is the first one of the sequence. The first file of the sequence is named as:
<main RAR name>.part<several zeroes>1.rar
Looking for the word “part” in the file name will be:
if "!fileName:~-10,5!"==".part" set process=0
if "!fileName:~-11,5!"==".part" set process=0
if "!fileName:~-12,5!"==".part" set process=0
if "!fileName:~-13,5!"==".part" set process=0
if "!fileName:~-14,5!"==".part" set process=0
if "!fileName:~-10,6!"==".part1" set process=1
if "!fileName:~-11,7!"==".part01" set process=1
if "!fileName:~-12,8!"==".part001" set process=1
if "!fileName:~-13,9!"==".part0001" set process=1
if "!fileName:~-14,10!"==".part00001" set process=1
We set process to 0 when the file is a split file, but set it to 1 when is the first one.
If the file is suitable for process we execute the WinRAR command to list contents given a filter name.
if "!process!"=="1" (
"%rarPath%\rar.exe" vb "%backupDir%\%%i\%%x" "%processfile%"
)
The parameters user are:
C:\Program Files\WinRAR>rar
RAR 3.51 Copyright (c) 1993-2005 Alexander Roshal 7 Oct 2005
Shareware version Type RAR -? for help
Usage: rar <command> -<switch 1> -<switch N> <archive> <files...>
<@listfiles...> <path_to_extract\>
<Commands>
v[t,b] Verbosely list archive [technical,bare]
The usage is:
D:\>ListBackup.cmd local*
Where local* is the file name we are looking for. The file can contain wildcards.
Comments