mysql:logrotatorformysqlwindows
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| mysql:logrotatorformysqlwindows [2013/10/09 09:25] – created rlunaro | mysql:logrotatorformysqlwindows [2024/10/05 17:07] (current) – removed rlunaro | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Log rotator for Mysql on Windows ====== | ||
| - | This rotator can rotate logs and roll over 10 log files. Moreover, it can be easily configured to | ||
| - | rotate as much logs as you want and to change the files to keep (10 by default). | ||
| - | |||
| - | <code vbs> | ||
| - | |||
| - | ' | ||
| - | ' logrotate.vbs - file rotate for mysql | ||
| - | ' | ||
| - | option explicit | ||
| - | |||
| - | rotateFile 10, " | ||
| - | rotateFile 10, " | ||
| - | |||
| - | wscript.quit | ||
| - | |||
| - | |||
| - | |||
| - | function rotateFile( byval filesToKeep, | ||
| - | |||
| - | dim index | ||
| - | dim fileFound | ||
| - | dim possibleNewName | ||
| - | |||
| - | index = 1 | ||
| - | fileFound = true | ||
| - | do while fileFound and index <= filesToKeep | ||
| - | |||
| - | possibleNewName = forgeRotateFile( logFile, index ) | ||
| - | fileFound = existsFile( possibleNewName ) | ||
| - | | ||
| - | index = index + 1 | ||
| - | loop ' fileFound | ||
| - | |||
| - | if fileFound then | ||
| - | ' destination file found, we have to discard the | ||
| - | ' last one and roll all the files | ||
| - | index = 1 | ||
| - | deleteFile forgeRotateFile( logFile, index ) | ||
| - | do while index < filesToKeep | ||
| - | ' the file index + 1 will be renamed to index | ||
| - | renameFile forgeRotateFile( logFile, index + 1 ), forgeRotateFile( logfile, index ) | ||
| - | index = index + 1 | ||
| - | loop ' index <= 0 | ||
| - | end if ' fileFound | ||
| - | |||
| - | ' move the file to the possibleNewName | ||
| - | ' is possible | ||
| - | renameFile logFile, possibleNewName | ||
| - | |||
| - | end function ' rotateFile | ||
| - | |||
| - | ' creates a new file by | ||
| - | ' adding a number. Example: | ||
| - | ' forgeRotateFile( " | ||
| - | function forgeRotateFile( byval filename, byval index ) | ||
| - | |||
| - | dim fso | ||
| - | dim path | ||
| - | dim basename | ||
| - | dim extension | ||
| - | | ||
| - | set fso = createobject( " | ||
| - | | ||
| - | path = fso.getParentFolderName( filename ) | ||
| - | basename = fso.getBaseName( filename ) | ||
| - | extension = fso.getExtensionName( filename ) | ||
| - | |||
| - | ' append a " | ||
| - | if path <> "" | ||
| - | path = path & " | ||
| - | end if ' path <> "" | ||
| - | ' append a " | ||
| - | if extension <> "" | ||
| - | extension = " | ||
| - | end if ' extension <> "" | ||
| - | forgeRotateFile = path & basename & " | ||
| - | | ||
| - | end function ' forgeRotateFile | ||
| - | |||
| - | function renameFile( byval sourceFile, byval destFile ) | ||
| - | dim fso | ||
| - | |||
| - | on error resume next | ||
| - | | ||
| - | set fso = createobject( " | ||
| - | |||
| - | if not fso.fileExists( destFile ) then | ||
| - | fso.moveFile sourceFile, destFile | ||
| - | end if ' file exists | ||
| - | |||
| - | end function ' renameFile | ||
| - | |||
| - | |||
| - | |||
| - | function existsFile( byval filename ) | ||
| - | dim out | ||
| - | dim fso | ||
| - | |||
| - | on error resume next | ||
| - | | ||
| - | set fso = createobject( " | ||
| - | |||
| - | out = false | ||
| - | if fso.fileExists( filename ) then | ||
| - | out = true | ||
| - | end if ' | ||
| - | |||
| - | existsFile = out | ||
| - | end function ' existFile | ||
| - | |||
| - | |||
| - | function deleteFile( byval filename ) | ||
| - | dim fso | ||
| - | | ||
| - | on error resume next | ||
| - | | ||
| - | set fso = createobject( " | ||
| - | |||
| - | if fso.fileExists( filename ) then | ||
| - | fso.deleteFile filename | ||
| - | end if ' file exists | ||
| - | |||
| - | end function ' deleteFile | ||
| - | |||
| - | </ | ||
mysql/logrotatorformysqlwindows.1381310715.txt.gz · Last modified: 2022/12/02 21:02 (external edit)
