vba - I run log but log is clean -
i run command in cmd:
cscript d:\new.vbs > output.log
but when open log clean:
microsoft (r) windows script host version 5.8 copyright (c) microsoft corporation.
i need simple log system vbs backup.
source code of new.vbs (from internet):
' backup folder using 7-zip ' written steve allison 2014 - steve@allison.im dim fso, rs, shell ' file system object set fso = createobject("scripting.filesystemobject") ' recordset set rs = createobject("ador.recordset") ' shell set shell = createobject("wscript.shell") const advarchar = 200 const addate = 7 srcfolder="c:\customer" dstfolder="s:\backup" backupname="backup" zipexe="c:\program files\7-zip\7z.exe" ' number of files keep inum = 5 ' date in correct order. why vbscript suck hard @ date formatting? function getdatestring() d = zeropad(day(now()), 2) m = zeropad(month(now()), 2) y = year(now()) getdatestring = y & m & d end function ' no printf() in vbscript seems function zeropad(int, length) if len(int) < length zeropad = right(string(length, "0") & int, length) end if end function ' sanity checking if not fso.folderexists(srcfolder) wscript.echo "aborted. source folder not exist: " & srcfolder wscript.quit end if if not fso.folderexists(dstfolder) wscript.echo "aborted. destination folder not exist: " & dstfolder wscript.quit end if if not fso.fileexists(zipexe) wscript.echo "aborted. 7-zip program not exist: " & zipexe wscript.quit end if ' create suffix of date-time backupfiledate = getdatestring() & "-" & replace(formatdatetime(now,4),":","") ' file extension backupfileext = ".7z" ' backup path without extension backupfilepre = dstfolder & "/" & backupname & "_" & backupfiledate ' full backup path backupfile = backupfilepre & backupfileext ' more sanity checking n = 1 while fso.fileexists(backupfile) ' add integeer file, loop until doesn't exist backupfile = backupfilepre & "_" & zeropad(n, 2) & backupfileext n = n + 1 loop '''' zip source folder ' create shell command shcommand = """" & zipexe & """ -r """ & backupfile & """" ' change source directory shell.currentdirectory = srcfolder & "/" ' run 7-zip in shell shval = shell.run(shcommand,4,true) ' check 7-zip exit code if shval > 1 wscript.echo "7-zip failed error code: " & shval wscript.quit end if '''' remove old backup files ' add required fields recordset rs.fields .append "filepath", advarchar, 255 .append "datelastmodified", addate end ' folder object set rsfolder=fso.getfolder(dstfolder) ' list folder contents recordset rs .open each rsfile in rsfolder.files .addnew array("filepath","datelastmodified"), array(rsfile.path,rsfile.datelastmodified) .update next end ' loop through folder listing recordset i=0 if not (rs.eof , rs.bof) ' sort last modified, newest first rs.sort = "datelastmodified desc" ' move recordset pointer first record rs.movefirst ' loop through recordset while not rs.eof ' path recordset dfile = fso.getfile(rs.fields("filepath")) ' filename path dfilename = fso.getfilename(dfile) ' check if backupname in filename if instr(1, dfilename, backupname, 1) i=i+1 ' wait until >inum matches if > inum ' delete file, ignore errors on error resume next fso.deletefile rs.fields("filepath"), true on error goto 0 end if end if rs.movenext loop end if wscript.echo "backup complete @ " & backupfile
this code okay, works want log because run new.vbs when leaving computer , later want check if ok. can me?
- assumption:
output.log
@ isn'toutput.log
command writes to. check timestamps,output.log
in current directory, delete , see if re-created, use full file spec after>
. - assumption: last line of script isn't reached. put
wscript.echo "backup started
@ top of script. - assumption: else goes wrong. debug script using
cscript //x ...
.
Comments
Post a Comment