midiboy Posted August 17, 2006 Posted August 17, 2006 Hi everyone.I am trying to develop a backup script using the command line. I am thinking of something like this:Script should check the day of the week, then create (if not already exist) a folder with that variable and then start ntbackup with the bkf file set in that folder. That way I only have one script but it runs Mo-Sa and drops bkf files into separate folders. (which overwrites the one inside).Only problem is ... how do I get the day of the week into a variable ? The %date% var. does not seem to help here.any ideas ?Ah ... and as a bonus it would be nice if the script could email the backup logs afterwards. Any small comandline smtp program available somewhere ?Thanks for your help !Alex
Yzöwl Posted August 17, 2006 Posted August 17, 2006 This is a batch file which will give you the day of the week, however it needs to use a vbscript to do it.@ECHO OFF &SETLOCAL ENABLEEXTENSIONSSET "TM_=%TEMP%\_TMP$.VBS">%TM_% ECHO/WSCRIPT.ECHO WEEKDAYNAME(WEEKDAY(DATE),TRUE)FOR /F %%? IN ('CSCRIPT //NOLOGO %TM_%') DO (SET "WD_=%%?" &&(DEL %TM_%))ECHO/Weekday is %WD_%ENDLOCAL &GOTO :EOFI would also suggest that your entire project is a vbscript one too.
midiboy Posted August 17, 2006 Author Posted August 17, 2006 Hey Yzöwl!wow, you are such a genius !!! This idea of using a temp vbscript is soo cool, thanks a lot !your skills are wonderful, I wish I could do something like this !Thanks very much !Alex
midiboy Posted August 17, 2006 Author Posted August 17, 2006 (edited) Hi again,well, I have already based a small backupscript upon your idea. Maybe it helps someone else too. I also found a small freeware smtp send app here which I am using inside the script to email the logfile-@ECHO OFF &SETLOCAL ENABLEEXTENSIONSREM define variables:REM variable path eg: D: or D:\Backup (without "\" at the end!) set DL=D:\BackupREM DELETE OLD BACKUP LOGS ( Only works on a german system. On an english system change "Anwendungsdaten" into "program data" (I think)if exist "%TMP%\..\Anwendungsdaten\Microsoft\Windows NT\NTBackup\data\*.log" del "%TMP%\..\Anwendungsdaten\Microsoft\Windows NT\NTBackup\data\*.log"REM FIND weekdaySET "TM_=%TEMP%\_TMP$.VBS">%TM_% ECHO/WSCRIPT.ECHO WEEKDAYNAME(WEEKDAY(DATE),TRUE)FOR /F %%? IN ('CSCRIPT //NOLOGO %TM_%') DO (SET "WD_=%%?" &&(DEL %TM_%))REM CREATE FOLDERSif not exist "%DL%\%WD_%" md "%DL%\%WD_%"REM START NTBACKUP (BKS SELECTION FILE HAS TO BE CREATED BEFORE !)"%WINDIR%\System32\NTBACKUP.EXE" backup "@C:\Unbenannt.bks" /d "Description" /v:yes /r:no /rs:no /hc:off /m normal /l:s /f "%DL%\%WD_%\Sicherung_Test_%WD_%.bkf"REM MOVE LOGFILE TO BACKUPLOCATION ( Only works on a german system. On an english system change "Anwendungsdaten" into "program data" (I think)move /Y "%TMP%\..\Anwendungsdaten\Microsoft\Windows NT\NTBackup\data\*.log" "%DL%\%WD_%\Sicherung_Test_%WD_%.bkf.log"REM MAIL THE LOGFILE USING BMAILbmail.exe -s mailserveradress -t toemailadress -f fromemailadress -a "Test Backup Results" -m "%DL%\%WD_%\Sicherung_Test_%WD_%.bkf.log" -cREM REPEAT THE ABOVE STEPS FOR A SECOND BACKUPJOB"%WINDIR%\System32\NTBACKUP.EXE" backup systemstate /d "Systemstate" /v:yes /r:no /rs:no /hc:off /m normal /l:s /f "%DL%\%WD_%\Systemstate_%WD_%.bkf"move /Y "%TMP%\..\Anwendungsdaten\Microsoft\Windows NT\NTBackup\data\*.log" "%DL%\%WD_%\Systemstate_%WD_%.bkf.log"bmail.exe -s mailserveradress -t toemailadress -f fromemailadress -a "Test Backup Results" -m "%DL%\%WD_%\Systemstate_%WD_%.bkf.log" -cENDLOCAL &GOTO :EOFIt works here. But maybe it could be refined. For instance it would be nicer if all the backupjobs including the moving of the backuplog and the mailing could run in some loop with variables for the bks, bkf, logfilenames and backup description. However, I am not very good at loops (yet) :-)I am not good at scripting at all Bye,Alex Edited August 17, 2006 by midiboy
uid0 Posted August 18, 2006 Posted August 18, 2006 (edited) If you didn't want to use vbscript you can get the day withFOR /F "TOKENS=1 DELIMS=/ " %%A IN ('DATE /T') DO (SET day=%%A)edit: just noticed this is the xp forum, seem to remember date output changed since w2k, so this may not work Edited August 18, 2006 by uid0
gunsmokingman Posted August 18, 2006 Posted August 18, 2006 (edited) Here is a VBS scripts to get the day nameDim Act : Set Act = CreateObject("Wscript.Shell")Dim LT, Msg : LT = "day to run the script"'------------------------------------------------------------------------------------------------------------>'/-> vbSunday = 1, vbMonday = 2, vbTuesday = 3, vbWednesday = 4, vbThursday = 5, vbFriday = 6, vbSaturday = 7 If Weekday(Date) = vbMonday Then '/-> Change To Suit Your Needs, You can Use The Number Values To Check Msg = "This is the correct " & LT & Space(5) &_ vbcrlf & Space(3) & "Number Code " & vbTab & Weekday(Date) &_ vbCrLf & Space(3) & "Short Name " & vbTab & WeekdayName(Weekday(Date),True) &_ vbCrLf & Space(3) & "Long Name " & vbTab & WeekdayName(Weekday(Date)) Act.Popup Space(9) & "Confirm Correct Day" & vbCrLf & Msg , 5, "Return Values", 0 + 48 + 4096 Else Msg = "Today, " & WeekdayName(Weekday(Date)) & " is not the " & LT Act.Popup Msg, 5, "Wrong Day", 0 + 48 + 4096 End If Edited August 21, 2006 by gunsmokingman
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now