I am trying to make a batch operation that backs up files but I don't always want to back them all up so I've split it into choices. I tried searching and found some examples which I followed, but still mine is not working. The problem is it automatically selects option 9 and begins to shutdown the computer... fixes?
@echo off
ECHO MyBackup Batch Beta
ECHO ==================================================================
ECHO 1. Copy DOCUMENTS to local backup only
ECHO 2. Create archive of DOCUMENTS only
ECHO 3. Create archive of HTDOCS only
ECHO 4. Create archives of both Documents and HTDOCS
ECHO 5. Move archives to ROBOSAM and delete from local backup
ECHO 6. Copy documents to local, archive, and move archives to RS
ECHO 7. Clean up all files in Local Backup (deletes permanently!)
ECHO 8. Quit
ECHO 9. Shutdown the computer
ECHO ==================================================================
ECHO Please make a choice.
CHOICE /C:123456789 Pick a number.
IF ERRORLEVEL ==9 GOTO EXIT_WIN
IF ERRORLEVEL ==8 GOTO EXIT_B
IF ERRORLEVEL ==7 GOTO CLEAN_LB
IF ERRORLEVEL ==6 GOTO DO_ALL
IF ERRORLEVEL ==5 GOTO MOVE_ZIP
IF ERRORLEVEL ==4 GOTO ZIP_ALL
IF ERRORLEVEL ==3 GOTO ZIP_HT
IF ERRORLEVEL ==2 GOTO ZIP_D
IF ERRORLEVEL ==1 GOTO QUICK_B
:QUICK_B
CALL qb.bat
GOTO :EOF
:ZIP_D
CALL zipdocs.bat
GOTO :EOF
:ZIP_HT
CALL ziphtdocs.bat
GOTO :EOF
:ZIP_ALL
CALL zipall.bat
GOTO :EOF
:MOVE_ZIP
CALL movezips.bat
GOTO :EOF
:DO_ALL
CALL doall.bat
GOTO :EOF
:CLEAN_LB
CALL cleanlb.bat
GOTO :EOF
:EXIT_B
EXIT
GOTO :EOF
:EXIT_WIN
CALL shutdown.bat
GOTO :EOF
I added the GOTO :EOFs because I read the commands might be "falling through" but still it just displays the list and runs choice 9 right away. I should note, I've tried adding /T:1,5
after CHOICE /C:123456789, and it still runs the shutdown.
If you want to try it but don't want your computer shutdown, you can type shutdown.exe /a and it shouldn't, but come again shouldn't run the shutdown anyways since the shutdown.bat I made would have to be there.
edit: i've added a :BEGIN
section to the file now, made the linked bat files all inline (replacing CALL
... with what was is those bat files and removed all but the last two GOTO :EOFs, replacing them with GOTO :BEGIN. It still runs #9 without giving me a chance to choose, all that was just to simplify it into one file.
New, more complicated code (user name redacted):
You WILL need to type shutdown.exe /a in the command to abort shut down if you try to run this version.
@echo off
:BEGIN
ECHO MyBackup Batch Beta v2
ECHO ==================================================================
ECHO 1. Copy documents to local backup only
ECHO 2. Create archive of documents only
ECHO 3. Create archive of htdocs only
ECHO 4. Create archives of both documents and htdocs
ECHO 5. Move archives to ROBOSAM and delete from local
ECHO 6. Copy documents to local, archive, and move archives to RS
ECHO 7. Clean up all files in Local Backup (deletes permanently!)
ECHO 8. Quit
ECHO 9. Shutdown the computer
ECHO ==================================================================
ECHO Please make a choice.
CHOICE /C:123456789 Pick a number.
IF ERRORLEVEL ==9 GOTO EXIT_WIN
IF ERRORLEVEL ==8 GOTO EXIT_B
IF ERRORLEVEL ==7 GOTO CLEAN_LB
IF ERRORLEVEL ==6 GOTO DO_ALL
IF ERRORLEVEL ==5 GOTO MOVE_ZIP
IF ERRORLEVEL ==4 GOTO ZIP_ALL
IF ERRORLEVEL ==3 GOTO ZIP_HT
IF ERRORLEVEL ==2 GOTO ZIP_D
IF ERRORLEVEL ==1 GOTO QUICK_B
:QUICK_B
xcopy /D /E /Q /G /R /K /Y "C:\Users\---\Documents" "C:\Users\---\Local Backup\Folders\Documents"
xcopy /D /E /Q /G /R /K /Y "C:\Users\---\Downloads" "C:\Users\---\Local Backup\Folders\Downloads"
GOTO :BEGIN
:ZIP_D
cd C:\Users\---\Roaming\PortableApps\Toucan
Toucan.exe -j ziplb /w
GOTO :BEGIN
:ZIP_HT
cd C:\Users\---\Roaming\PortableApps\Toucan
Toucan.exe /w -j ziphtdocs
GOTO :BEGIN
:ZIP_ALL
cd C:\Users\---\Roaming\PortableApps\Toucan
Toucan.exe /w -j ziplb
Toucan.exe /w -j ziphtdocs
GOTO :BEGIN
:MOVE_ZIP
cd C:\Windows\system32
xcopy /D /E /Q /G /R /K /Y "C:\Users\---\Local Backup\Zips" "E:\Backups"
del /q /f "C:\Users\---\Local Backup\Zips\*.*"
GOTO :BEGIN
:DO_ALL
xcopy /D /E /Q /G /R /K /Y "C:\Users\---\Documents" "C:\Users\---\Local Backup\Folders\Documents"
xcopy /D /E /Q /G /R /K /Y "C:\Users\---\Downloads" "C:\Users\---\Local Backup\Folders\Downloads"
cd C:\Users\---\Roaming\PortableApps\Toucan
Toucan.exe /w -j ziplb
Toucan.exe /w -j ziphtdocs
cd C:\Windows\system32
xcopy /D /E /Q /G /R /K /Y "C:\Users\---\Local Backup\Zips" "E:\Backups"
del /q /f "C:\Users\---\Local Backup\Zips\*.*"
GOTO :BEGIN
:CLEAN_LB
cd C:\Windows\System32
del /q /f "C:\Users\---\Local Backup\*.*"
GOTO :BEGIN
:EXIT_B
EXIT
GOTO :EOF
:EXIT_WIN
cd C:\Windows\System32
shutdown.exe /s
GOTO :EOF
The Toucan command call jobs I have saved in that program that zip certain folders for me. Any suggestions on my #9 problem? If you see any other problems too, let me know.