SQLBkup 3 - SQL Backup log files aren't deleted

Brian DonahueBrian Donahue Posts: 6,590 New member
edited February 15, 2006 12:00PM in Knowledge Base
  • Date: 20 Jul 2005
  • Versions affected: SQL Backup 3.0-3.2
SQL Backup creates a log file for every backup and restore option that it performs. Each log is a small text file and is stored in the %ALLUSERSPROFILE%\Application Data\Red Gate\SQL Backup\Data folder on your hard disk. These files are never deleted, and can result in many thousands of small files building up in this folder. The ERASEFILES options in SQL Backup only affect SQL Backup files, not the log files.

Understandably, these files can cause an annoyance. This will be addressed in the next major version of SQL Backup.

In the meantime, you may want to use this script to delete old log files from your hard disk. Copy the following script, paste it into notepad.exe, and save the file as DeleteOldSQBLogs.js
usage: cscript //NOLOGO DeleteOldSQBLogs.js /days:x 
where x=the number of days you want to retain the log files.
if (!WScript.Arguments.Named.Exists("days")) {
	WScript.Echo("must specify date criteria!\r\n(/days:x)")
var age=WScript.Arguments.Named("days");
        /* Get the log file folder name */
var obShell=new ActiveXObject("WScript.Shell");
var obEnvironment=obShell.Environment("PROCESS");
var sqbLogsFolderName=obEnvironment("ALLUSERSPROFILE")+"\\Application Data\\Red Gate\\Sql Backup\\Log";

        /* Create an instance of the FileSystemObject */
var FS=new ActiveXObject("Scripting.FileSystemObject");
        /* Delete the old log files */
DeleteOldFiles(sqbLogsFolderName, age);
       /* Function to delete the old files */
function DeleteOldFiles(folderName, daysOld) {
var obFolder=FS.GetFolder(folderName);
var f=new Enumerator(obFolder.Files)
var d = new Date();

var oldDate=new Date(d.getYear(), d.getMonth(), d.getDate()-daysOld);

	for (;!f.atEnd();f.moveNext()) {
		var file=f.item();
		if (file.DateLastModified < oldDate)
Next, schedule this as a scheduled task to run every day. You can use the Windows Control Panel Scheduled Tasks or the AT command from the command prompt:
at 00:01 /every:M,T,W,Th,F,S,Su "cscript c:\scripts\DeleteOldSQBLogs.js /days:30"


Sign In or Register to comment.