Automatically Name Log Files With the Current Date and Time

A script to automatically name log files with the current date and time, which solves the problem of NT Backup overwriting previous days' logs.

Bret A. Bennett

January 21, 2002

1 Min Read
ITPro Today logo in a gray background | ITPro Today


Editor's Note: Share your Windows and .NET discoveries, comments, problems, solutions, and experiences with products and reach out to other Windows & .NET Magazine readers (including Microsoft). Email your contributions (400 words or less) to [email protected]. Please include your phone number. We edit submissions for style, grammar, and length. If we print your submission, you'll get $100. Submissions and listings are available online at http://www.winnetmag.com/articles. Enter the InstantDoc ID number in the InstantDoc ID text box.

When Windows NT Backup writes a log file, the program always uses the same name. This method overwrites previous days' logs and thus leaves administrators wondering whether their backups have been working. To solve this problem, I wrote the script that Listing 1 shows to automatically name log files with the current date and time.

I used ntdate.exe, which is in Jeffrey Harris's freeware AINTX Toolset (available at http://user.mc.net/~jlh/nttools/html/download_aintx.htm), and the form of the for /f command that parses command outputs. Ntdate provides the parsed system date to the for command.

I put the command file in NT's Scheduler. You can use REM statements (i.e., ::) on the line containing the Ntbackup command to specify whether you want full or incremental backups. This script is for NT 4.0 and includes optional lines to accommodate Microsoft Small Business Server (SBS) 4.5.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like