+ Post New Thread
Results 1 to 5 of 5
Windows Server 2000/2003 Thread, How to get day and date as filename in Technical; I am finally trying to get everything sorted with the backups here. What I use currently on each day is ...
  1. #1
    denon101's Avatar
    Join Date
    Jul 2008
    Location
    Stuck in the server room......
    Posts
    395
    Thank Post
    54
    Thanked 37 Times in 35 Posts
    Rep Power
    21

    How to get day and date as filename

    I am finally trying to get everything sorted with the backups here. What I use currently on each day is

    C:\WINDOWS\system32\ntbackup.exe backup "@C:\Documents and Settings\admin\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\daily.bks" /a /d "Set created %date:-=-%" /v:yes /r:no /hcff /m differential /j "Daily Diff Backup" /l:s /f "\\san\storage\backup\monday.bkf"

    Then for each day monday, becomes tuesday etc. But this means I need 4 scheduled tasks for Mon to Thur and a 5th for the Full backup on a Friday. What would be better is on task but it will put something like Monday_15/11/2010.bkf. Anyone have any ideas?

    Thanks

  2. #2
    denon101's Avatar
    Join Date
    Jul 2008
    Location
    Stuck in the server room......
    Posts
    395
    Thank Post
    54
    Thanked 37 Times in 35 Posts
    Rep Power
    21
    Can't get the monday, tuesday etc. But have managed to get the date working. It's better than nothing, but if someone does know how to get the day in there aswell that would be great.

  3. #3


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    8,877
    Thank Post
    226
    Thanked 2,669 Times in 1,968 Posts
    Rep Power
    786
    Quote Originally Posted by denon101 View Post
    if someone does know how to get the day in there as well that would be great.
    This will do it...


    DailyDiff.cmd
    Code:
    @echo off & setlocal ENABLEEXTENSIONS
    
    :: Functions
    call :GetDate y m d
    call :DateToDOW %y% %m% %d% dow
    call :DayName %dow% day
    
    :: Variables
    SET BKSPATH=%USERPROFILE%\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\Data\Daily.bks
    SET BKFPATH=\\SAN\Storage\Backup\%day%.bkf
    
    :: Start NTBackup
    ntbackup.exe backup "@%BKSPATH%" /a /d "Set created %Date:/=-%" /v:yes /r:no /hc:off /m differential /j "Daily Diff Backup" /l:s /f "%BKFPATH%"
    
    goto :EOF
    
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :GetDate yy mm dd
    ::
    :: Func: Loads local system date components into args 1 to 3.
    ::       For NT4/2000/XP/2003.
    :: 
    :: Args: %1 var to receive year, 4 digits (by ref)
    ::       %2 var to receive month, 2 digits, 01 to 12 (by ref)
    ::       %3 Var to receive day of month, 2 digits, 01 to 31 (by ref)
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    setlocal ENABLEEXTENSIONS
    set t=2&if "%date%z" LSS "A" set t=1
    for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo/^|date') do (
      for /f "tokens=%t%-4 delims=.-/ " %%d in ('date/t') do (
        set %%a=%%d&set %%b=%%e&set %%c=%%f))
    endlocal&set %1=%yy%&set %2=%mm%&set %3=%dd%&goto :EOF
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :DateToDOW %yy% %mm% %dd% dow
    ::
    :: Func: Creates a day of week number from a calendar date, where 1 = Mon
    ::       and 7 = Sun. For NT4/2000/XP/2003.
    :: 
    :: Args: %1 year component to be converted, 2 or 4 digits (by val)
    ::       %2 month component to be converted, leading zero ok (by val)
    ::       %3 day of month to be converted, leading zero ok (by val)
    ::       %4 var to receive day of week number, 1 to 7 (by ref)
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    setlocal ENABLEEXTENSIONS
    set yy=%1&set mm=%2&set dd=%3
    if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
    set /a dd=100%dd%%%100,mm=100%mm%%%100
    set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,dow=153*m+2
    set /a dow=dow/5+dd+y*365+y/4-y/100+y/400-2472630,dow%%=7,dow+=1
    endlocal&set %4=%dow%&goto :EOF
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :DayName %d% day
    ::
    :: Func: Returns the day of week from the day number, 1=Monday, 7=Sunday.
    ::       For NT4/2000/XP/2003.
    :: 
    :: Args: %1 day number to convert to name of day of week, 1 to 7 (by val)
    ::       %2 var to receive name of day of week (by ref)
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    setlocal ENABLEEXTENSIONS
    for /f "tokens=%1" %%a in ('echo/Monday Tuesday Wednesday Thursday Friday^
      Saturday Sunday') do endlocal&set %2=%%a&goto :EOF
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    
    :: N.B. The functions above are from commandline.co.uk

  4. Thanks to Arthur from:

    denon101 (13th November 2010)

  5. #4

    Join Date
    Dec 2007
    Location
    cumbria
    Posts
    182
    Thank Post
    7
    Thanked 43 Times in 39 Posts
    Rep Power
    25
    Just a thought, but with 'date-named' files, I always tend to use the ISO recommendations, most significant part first.
    So, today could be something like 2010-11-15--Monday.bkf
    Makes it easier to scan directories, script housekeeping, etc.

  6. #5


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    8,877
    Thank Post
    226
    Thanked 2,669 Times in 1,968 Posts
    Rep Power
    786
    Very good point. That's actually what I do too since it ensures Windows sorts the files properly. To do this in the batch file I posted above, just replace line 10 with the code below...

    Code:
    SET BKFPATH=\\SAN\Storage\Backup\%y%-%m%-%d%_%day%.bkf

    The filename for todays backup would become: 2010-11-15_Monday.bkf instead of just Monday.bkf.

SHARE:
+ Post New Thread

Similar Threads

  1. Stamping filename on images
    By Jobos in forum How do you do....it?
    Replies: 2
    Last Post: 9th August 2010, 03:48 AM
  2. User keeps getting 'Filename too long' and can't logon!
    By marsdenprimary in forum Wireless Networks
    Replies: 20
    Last Post: 1st April 2010, 01:53 PM
  3. make owner same as filename.
    By madcyryl in forum Scripts
    Replies: 0
    Last Post: 16th June 2009, 03:31 PM
  4. Windows 2003 date command and day name
    By webman in forum Windows
    Replies: 1
    Last Post: 19th November 2008, 01:12 PM
  5. MS Office XP - filename length
    By broc in forum Windows
    Replies: 0
    Last Post: 30th March 2006, 12:08 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •