0

this is my first time posting here so I'll do my best. Basically I want to automatically backup my USB when it's plugged in, what I have set up at the moment is three files, backup.bat, silent backup.vbs, and backup watch.bat

Backup.bat

@echo off
Set _TS=        
Set _Source=C:\NMIT
Set _Dest=I:\Users\The Beast\SkyDrive\School\NMIT
Set _Log=I:\Users\The Beast\Documents\NMIT USB Backup Log.txt
robocopy "%_Source%" "%_Dest%" /E /ZB /B /V /PURGE /LOG:"I:\Users\The Beast\Documents\NMIT USB Backup Log.txt"
echo Backup complete, please remove USB
pause

Silent backup.vbs

Set WshShell = CreateObject("WScript.Shell") 
WshShell.Run chr(34) & "I:\Users\The Beast\Desktop\testing bat\backup watch.bat" & Chr(34), 0
Set WshShell = Nothing

Backup watch.bat

@echo off

    IF EXIST "C:/NMIT" call "I:\Users\The Beast\Desktop\testing bat\backup.bat"

Everything works fine, runs, copies new files, and writes to the log file, also it runs silently thanks to the vbs scipt I found online, the only problem is I have no idea if it's done backing up or not, the script runs every 5 minutes by task scheduler. What I want to do is have the watch script run silently, but show a notification when the backup is done. I guess the easiest way to do that would be to edit backup.bat to include an echo and a pause, but if I do that now it's invisible, so how can I have the watch script run silent, but the backup script run normal? Thanks guys, I hope my post is descriptive enough.

JDogg1329
  • 1
  • 4

1 Answers1

0

To create a notification, create a new file called notify.bat in the same directory:

@echo off
cls
set seconds=5
echo Backup complete, please remove USB
ping -n %seconds% 127.0.0.1 > NUL 2>&1
exit 0

Now change your Backup.bat script to:

@echo off
Set "_TS="        
Set _Source=C:\NMIT
Set _Dest=I:\Users\The Beast\SkyDrive\School\NMIT
Set _Log=I:\Users\The Beast\Documents\NMIT USB Backup Log.txt
robocopy "%_Source%" "%_Dest%" /E /ZB /B /V /PURGE /LOG:"I:\Users\The Beast\Documents\NMIT USB Backup Log.txt"
start notify.bat

The Backup.bat script will be hidden when called through the vbs file, but notify.bat will be visible since it's being called from the bat file instead.

Also, a small tip, to escape a quote inside of quotes, use double quotes. In Silent backup.vbs that would look like:

Set WshShell = CreateObject("WScript.Shell") 
WshShell.Run """I:\Users\The Beast\Desktop\testing bat\backup watch.bat""", 0
Set WshShell = Nothing
Kevin Brotcke
  • 3,765
  • 26
  • 34