Hi.
On my work, I use a W10 computer and to simplify things, I've made a simple batch file in order to update the backup on a external hdd.
Earlier, I've had two very simple bat files, one for a set of two directories and another bat file for the images folder. This is because I don't always want to spend the extra time running backup of images (the other folders are more important).
This works very well for me, but I've tried to merge those bat files into one, and to get the user to choose if want to include the images folder in the backup process.
However, I ran into a wall here. The problem lies at line 74, where I want to test if the variable BILDESYNK contains 1 or not. It turns out (by testing and putting some echo lines and pause below) that the vat files never executes the lines below, no matter what the user input was (from line 53).
It's a very long time since I played around using bat files, so there may be some obvious things I just haven't picked up on.
Here is the content of the bat file - I've put comments in it and translated to English to make it as easy to understand as possible.
On my work, I use a W10 computer and to simplify things, I've made a simple batch file in order to update the backup on a external hdd.
Earlier, I've had two very simple bat files, one for a set of two directories and another bat file for the images folder. This is because I don't always want to spend the extra time running backup of images (the other folders are more important).
This works very well for me, but I've tried to merge those bat files into one, and to get the user to choose if want to include the images folder in the backup process.
However, I ran into a wall here. The problem lies at line 74, where I want to test if the variable BILDESYNK contains 1 or not. It turns out (by testing and putting some echo lines and pause below) that the vat files never executes the lines below, no matter what the user input was (from line 53).
It's a very long time since I played around using bat files, so there may be some obvious things I just haven't picked up on.
Here is the content of the bat file - I've put comments in it and translated to English to make it as easy to understand as possible.
Code:
@echo off
REM Original charset Western European (DOS-850) (because correctly appearance of norwegian characters)
REM Text editor for bat files in Windows Notepad2-mod
REM
REM Because the computer in question is not at home, I use Linux/Xed text editor and also manually translated
REM all text from norwegian so that the intension should be clear for all readers.
REM
REM Simple translation of some targets used in this file
REM fortsett=Continue ; BILDER=Images ; IKKEBILDER=(not an actual word but basically means no images)
REM
REM
REM - Make sure all involved folders exists (stop the script if one doesn't exists).
if not exist U:\local-folder-a\ goto nonexisting
if not exist D:\remote-folder-a\ goto nonexisting
if not exist U:\local-folder-b\ goto nonexisting
if not exist D:\remote-folder-b\ goto nonexisting
echo .......
echo Test completed - Alle folders exists and the job may start.
echo .......
echo This job is to synchronize from internal HDD to a usb slimdrive
echo .......
echo WARNING : "Purge" argument are given, therefore it can delete files on the slim drive.
echo .......
CHOICE /C AN123Y /M "Press Y to start the syncronisation process"
IF ERRORLEVEL 6 GOTO fortsett
echo ... MESSAGE....
echo The job is being canselled by user.
echo ...............
pause
EXIT
REM Go here if one of the given folders doesn't exists'.
:nonexisting
echo .... ERROR ....
echo At least one of the following folders is not to be found
echo - U:\local-folder-a
echo - D:\remote-folder-a
echo - U:\local-folder-b
echo - D:\remote-folder-b
echo ................
echo Tips: Make sure the usb slim drive are attached.
pause
EXIT
:fortsett
CHOICE /C AN123Y /M "Do you also want image folder to be synchronized (can take long time) ?"
IF ERRORLEVEL 6 set /A BILDESYNK=1
echo .......
echo Synchronizing from source folder "U:\local-folder-a"
echo .......
REM robocopy "U:\local-folder-a" "D:\remote-folder-a" /S /purge /eta /COPY:DT /XF Thumbs.db .~lock* *.tmp /r:5 /w:3
echo .......
echo Synchronizing from source folder "U:\local-folder-b"
echo .......
REM robocopy "U:\local-folder-b" "D:\remote-folder-b" /S /purge /eta /COPY:DT /XF Thumbs.db .~lock* *.tmp /r:5 /w:3
REM
REM This bat file are incomplete - because I never found a workaround for the issue mantioned below.
REM Among the missing things are the robocopy command itself and the check for folders existence.
REM
REM
IF /I %BILDESYNK% EQU "1" goto BILDER else goto IKKEBILDER
REM NEVER EXECUTE THIS LINE IF ANY COMMAND SPECIFIED.
:IKKEBILDER
pause
EXIT
:BILDER
echo .......
echo Synchronizing from source folder "U:\local-folder-b"
echo .......
REM /COPY:DT
REM just copy files & date/time stamps.
REM /ZB tells robocopy to use restartable mode (which you want for large files, especially over WAN/unstable connections
REM /R:1 /W:3 are two switches you probably want to use together to tell
REM robocopy how many times to retry accessing a file (1 in this example), and
REM how long to wait between retries (3 seconds in this example).
REM If you leave this out, it?ll retry 1 million times with a 30 second wait between each one when it encounters a file it can?t access!!!
REM /s Copies subdirectories. This option automatically excludes empty directories.
REM /purge Deletes destination files and directories that no longer exist in the source.
REM Logging options
REM /eta Shows the estimated time of arrival (ETA) of the copied files.
pause