Home All Groups Group Topic Archive Search About

modify incremental_backup

Author
16 Feb 2009 9:41 PM
Joe King
this code (by Mark Minasi) creates a batch file to run ntbackup:


================================================================
Option Explicit

Dim objFileSystem
Dim objOutputFile
Dim strOutputFile : strOutputFile = "C:\BatchFiles\NetworkBackup\Auto-
NetBackup.bat"
Dim strDayOfWeekText
Dim strMyDate
Dim strstrMyMonth
Dim oWSH
Dim sCommand
Dim strDelBackup
Dim strMoveBackup
Dim strBackup
Dim strType : strType = "INCREMENTAL"
Dim strIntHDD : strIntHDD = "D:\NetworkBackup"
Dim strExtHDD : strExtHDD = "F:"


strDayOfWeekText = WeekDayName(WeekDay(Date), True)



If strDayOfWeekText = "Sat" Then
    strType = "NORMAL"
    strDayOfWeekText = "Week"
End If


strMyDate = Year(Date) & Right("0" &Month(Date),2) & Right("0" &Day
(Date),2)



If strDayOfWeekText = "Week" Then
    ' keep last three full backups
    strDelBackup = "del /F /S /Q " &strIntHDD&"\04-"
&strDayOfWeekText&"\*.*"
    strMoveBackup = "move "&strIntHDD&"\03-"&strDayOfWeekText&"\*.*
"&strIntHDD&"\04-"&strDayOfWeekText&"\" 
    strMoveBackup = "move "&strIntHDD&"\02-"&strDayOfWeekText&"\*.*
"&strIntHDD&"\03-"&strDayOfWeekText&"\" 
    strMoveBackup = "move "&strIntHDD&"\01-"&strDayOfWeekText&"\*.*
"&strIntHDD&"\02-"&strDayOfWeekText&"\" 
Else
    ' keep last weeks incremental backup
    strDelBackup = "del /F /S /Q " &strIntHDD&"\02-"
&strDayOfWeekText&"\*.*"
    strMoveBackup = "move " &strIntHDD&"\01-" &strDayOfWeekText&"\*.*
" &strIntHDD&"\02-" &strDayOfWeekText&"\" 
End If




Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objOutputFile = objFileSystem.CreateTextFile(strOutputFile, True)
objOutputFile.WriteLine("REM " &strDayOfWeekText&" - " &strMyDate&" - "
&Time &" - " &Date)

If strDayOfWeekText <> "Sun" And strDayOfWeekText <> "Mon" Then

    objOutputFile.WriteLine(strDelBackup)
    objOutputFile.WriteLine(strMoveBackup)
    'backup 1
    'strBackup = "ntbackup backup \\act01\d$ /j "&strMyDate&" /f
"""&strIntHDD&"\01-"&strDayOfWeekText&"\act01-"&strMyDate&".bkf"" /L:S /M
"&strType
    'objOutputFile.WriteLine(strBackup)
    'backup 2
    'strBackup = "ntbackup backup \\nas01\c$\act /j "&strMyDate&" /f
"""&strIntHDD&"\01-"&strDayOfWeekText&"\nas01-
act-"&strMyDate&".bkf"" /L:S /M "&strType
    'objOutputFile.WriteLine(strBackup)

    'copy backup to removable drive
    strBackup = "xcopy "&strIntHDD&"\01-"&strDayOfWeekText&"\*.*
"&strExtHDD&"\01-"&strDayOfWeekText&"\*.* /F /H /R /V /Y"
    objOutputFile.WriteLine(strBackup)

End If

objOutputFile.Close
Set objFileSystem = Nothing


Set oWSH = CreateObject("WScript.Shell")
sCommand = strOutputFile
Call oWSH.Run(sCommand)
Set oWSH = Nothing
================================================================


While I like the idea in concept, I do not like its' execution

I'd like to bypass ntbackup completely, and just call xcopy to backup to
a folder (01-mmddyy), keep 4 (one per week) of these, then at week 5
start overwriting week 1

could you folks assist to get me started? (this will not scope-creep,
btw)


cheers.

jk

Author
16 Feb 2009 10:05 PM
Pegasus (MVP)
Show quote Hide quote
"Joe King" <br25***@aol.co.uk> wrote in message
news:Xns9BB4A9DD0CECCjoekingaolcouk@74.209.136.81...
> this code (by Mark Minasi) creates a batch file to run ntbackup:
>
>
> ================================================================
> Option Explicit
>
> Dim objFileSystem
> Dim objOutputFile
> Dim strOutputFile : strOutputFile = "C:\BatchFiles\NetworkBackup\Auto-
> NetBackup.bat"
> Dim strDayOfWeekText
> Dim strMyDate
> Dim strstrMyMonth
> Dim oWSH
> Dim sCommand
> Dim strDelBackup
> Dim strMoveBackup
> Dim strBackup
> Dim strType : strType = "INCREMENTAL"
> Dim strIntHDD : strIntHDD = "D:\NetworkBackup"
> Dim strExtHDD : strExtHDD = "F:"
>
>
> strDayOfWeekText = WeekDayName(WeekDay(Date), True)
>
>
>
> If strDayOfWeekText = "Sat" Then
> strType = "NORMAL"
> strDayOfWeekText = "Week"
> End If
>
>
> strMyDate = Year(Date) & Right("0" &Month(Date),2) & Right("0" &Day
> (Date),2)
>
>
>
> If strDayOfWeekText = "Week" Then
> ' keep last three full backups
> strDelBackup = "del /F /S /Q " &strIntHDD&"\04-"
> &strDayOfWeekText&"\*.*"
> strMoveBackup = "move "&strIntHDD&"\03-"&strDayOfWeekText&"\*.*
> "&strIntHDD&"\04-"&strDayOfWeekText&"\"
> strMoveBackup = "move "&strIntHDD&"\02-"&strDayOfWeekText&"\*.*
> "&strIntHDD&"\03-"&strDayOfWeekText&"\"
> strMoveBackup = "move "&strIntHDD&"\01-"&strDayOfWeekText&"\*.*
> "&strIntHDD&"\02-"&strDayOfWeekText&"\"
> Else
> ' keep last weeks incremental backup
> strDelBackup = "del /F /S /Q " &strIntHDD&"\02-"
> &strDayOfWeekText&"\*.*"
> strMoveBackup = "move " &strIntHDD&"\01-" &strDayOfWeekText&"\*.*
> " &strIntHDD&"\02-" &strDayOfWeekText&"\"
> End If
>
>
>
>
> Set objFileSystem = CreateObject("Scripting.fileSystemObject")
> Set objOutputFile = objFileSystem.CreateTextFile(strOutputFile, True)
> objOutputFile.WriteLine("REM " &strDayOfWeekText&" - " &strMyDate&" - "
> &Time &" - " &Date)
>
> If strDayOfWeekText <> "Sun" And strDayOfWeekText <> "Mon" Then
>
> objOutputFile.WriteLine(strDelBackup)
> objOutputFile.WriteLine(strMoveBackup)
> 'backup 1
> 'strBackup = "ntbackup backup \\act01\d$ /j "&strMyDate&" /f
> """&strIntHDD&"\01-"&strDayOfWeekText&"\act01-"&strMyDate&".bkf"" /L:S /M
> "&strType
> 'objOutputFile.WriteLine(strBackup)
> 'backup 2
> 'strBackup = "ntbackup backup \\nas01\c$\act /j "&strMyDate&" /f
> """&strIntHDD&"\01-"&strDayOfWeekText&"\nas01-
> act-"&strMyDate&".bkf"" /L:S /M "&strType
> 'objOutputFile.WriteLine(strBackup)
>
> 'copy backup to removable drive
> strBackup = "xcopy "&strIntHDD&"\01-"&strDayOfWeekText&"\*.*
> "&strExtHDD&"\01-"&strDayOfWeekText&"\*.* /F /H /R /V /Y"
> objOutputFile.WriteLine(strBackup)
>
> End If
>
> objOutputFile.Close
> Set objFileSystem = Nothing
>
>
> Set oWSH = CreateObject("WScript.Shell")
> sCommand = strOutputFile
> Call oWSH.Run(sCommand)
> Set oWSH = Nothing
> ================================================================
>
>
> While I like the idea in concept, I do not like its' execution
>
> I'd like to bypass ntbackup completely, and just call xcopy to backup to
> a folder (01-mmddyy), keep 4 (one per week) of these, then at week 5
> start overwriting week 1
>
> could you folks assist to get me started? (this will not scope-creep,
> btw)
>
>
> cheers.
>
> jk

A couple of thoughts for starters:
- Microsoft has officially deprecated xcopy.exe. Robocopy is the recommended
replacement product.
- Since you intend to invoke a console command (xcopy or robocopy) and since
your logic is well within the grasp of a batch file, I suggest you drop the
idea of using the hybrid solution of a script that invokes console commands.
A batch file would require far fewer lines of code which means less
debugging and easier maintenance.

A few questions:
- You mention "backup to a folder (01-mmddyy)". What's the "01" bit for?
Does it vary? Wouldn't the date code uniquely identify the folder?
- Do you back up each day or each week?
- What do you get when you type the following command at a Command Prompt?
  echo %date%
Are all your drivers up to date? click for free checkup

Author
16 Feb 2009 10:56 PM
Joe King
Show quote Hide quote
"Pegasus \(MVP\)" <I.***@fly.com.oz> wrote in
news:OqiPnKIkJHA.4976@TK2MSFTNGP06.phx.gbl:

>
> "Joe King" <br25***@aol.co.uk> wrote in message
> news:Xns9BB4A9DD0CECCjoekingaolcouk@74.209.136.81...
>> this code (by Mark Minasi) creates a batch file to run ntbackup:
>>
>>
>> ================================================================
>> Option Explicit
>>
>> Dim objFileSystem
>> Dim objOutputFile
>> Dim strOutputFile : strOutputFile =
>> "C:\BatchFiles\NetworkBackup\Auto- NetBackup.bat"
>> Dim strDayOfWeekText
>> Dim strMyDate
>> Dim strstrMyMonth
>> Dim oWSH
>> Dim sCommand
>> Dim strDelBackup
>> Dim strMoveBackup
>> Dim strBackup
>> Dim strType : strType = "INCREMENTAL"
>> Dim strIntHDD : strIntHDD = "D:\NetworkBackup"
>> Dim strExtHDD : strExtHDD = "F:"
>>
>>
>> strDayOfWeekText = WeekDayName(WeekDay(Date), True)
>>
>>
>>
>> If strDayOfWeekText = "Sat" Then
>> strType = "NORMAL"
>> strDayOfWeekText = "Week"
>> End If
>>
>>
>> strMyDate = Year(Date) & Right("0" &Month(Date),2) & Right("0" &Day
>> (Date),2)
>>
>>
>>
>> If strDayOfWeekText = "Week" Then
>> ' keep last three full backups
>> strDelBackup = "del /F /S /Q " &strIntHDD&"\04-"
>> &strDayOfWeekText&"\*.*"
>> strMoveBackup = "move "&strIntHDD&"\03-"&strDayOfWeekText&"\*.*
>> "&strIntHDD&"\04-"&strDayOfWeekText&"\"
>> strMoveBackup = "move "&strIntHDD&"\02-"&strDayOfWeekText&"\*.*
>> "&strIntHDD&"\03-"&strDayOfWeekText&"\"
>> strMoveBackup = "move "&strIntHDD&"\01-"&strDayOfWeekText&"\*.*
>> "&strIntHDD&"\02-"&strDayOfWeekText&"\"
>> Else
>> ' keep last weeks incremental backup
>> strDelBackup = "del /F /S /Q " &strIntHDD&"\02-"
>> &strDayOfWeekText&"\*.*"
>> strMoveBackup = "move " &strIntHDD&"\01-" &strDayOfWeekText&"\*.*
>> " &strIntHDD&"\02-" &strDayOfWeekText&"\"
>> End If
>>
>>
>>
>>
>> Set objFileSystem = CreateObject("Scripting.fileSystemObject")
>> Set objOutputFile = objFileSystem.CreateTextFile(strOutputFile, True)
>> objOutputFile.WriteLine("REM " &strDayOfWeekText&" - " &strMyDate&" -
>> " &Time &" - " &Date)
>>
>> If strDayOfWeekText <> "Sun" And strDayOfWeekText <> "Mon" Then
>>
>> objOutputFile.WriteLine(strDelBackup)
>> objOutputFile.WriteLine(strMoveBackup)
>> 'backup 1
>> 'strBackup = "ntbackup backup \\act01\d$ /j "&strMyDate&" /f
>> """&strIntHDD&"\01-"&strDayOfWeekText&"\act01-"&strMyDate&".bkf""
>> /L:S /M "&strType
>> 'objOutputFile.WriteLine(strBackup)
>> 'backup 2
>> 'strBackup = "ntbackup backup \\nas01\c$\act /j "&strMyDate&" /f
>> """&strIntHDD&"\01-"&strDayOfWeekText&"\nas01-
>> act-"&strMyDate&".bkf"" /L:S /M "&strType
>> 'objOutputFile.WriteLine(strBackup)
>>
>> 'copy backup to removable drive
>> strBackup = "xcopy "&strIntHDD&"\01-"&strDayOfWeekText&"\*.*
>> "&strExtHDD&"\01-"&strDayOfWeekText&"\*.* /F /H /R /V /Y"
>> objOutputFile.WriteLine(strBackup)
>>
>> End If
>>
>> objOutputFile.Close
>> Set objFileSystem = Nothing
>>
>>
>> Set oWSH = CreateObject("WScript.Shell")
>> sCommand = strOutputFile
>> Call oWSH.Run(sCommand)
>> Set oWSH = Nothing
>> ================================================================
>>
>>
>> While I like the idea in concept, I do not like its' execution
>>
>> I'd like to bypass ntbackup completely, and just call xcopy to backup
>> to a folder (01-mmddyy), keep 4 (one per week) of these, then at week
>> 5 start overwriting week 1
>>
>> could you folks assist to get me started? (this will not scope-creep,
>> btw)
>>
>>
>> cheers.
>>
>> jk
>
> A couple of thoughts for starters:
> - Microsoft has officially deprecated xcopy.exe. Robocopy is the
> recommended replacement product.
> - Since you intend to invoke a console command (xcopy or robocopy) and
> since your logic is well within the grasp of a batch file, I suggest
> you drop the idea of using the hybrid solution of a script that
> invokes console commands. A batch file would require far fewer lines
> of code which means less debugging and easier maintenance.
>
> A few questions:
> - You mention "backup to a folder (01-mmddyy)". What's the "01" bit
> for? Does it vary? Wouldn't the date code uniquely identify the
> folder? - Do you back up each day or each week?
> - What do you get when you type the following command at a Command
> Prompt?
>   echo %date%
>
>
>

xcopy has been just ducky in my context
I just need to keep 3 additional increments, as opposed to the single
weekly backup.

the 01 would represent the first of 4 backups, 02, 03, 04 would follow. The
fifth would be written into the 01 container

ex

01-021609
02-022309
03-030209
04-030909
then, 01-021609 would be deleted, and replaced by 01-031609

yes, I suppose the datecode would accurately represent the folder.

but - if I were to get hit by a bus, this may make it clearer for
subsequent operators.

i get: Mon 02/16/09
Author
16 Feb 2009 11:39 PM
Pegasus (MVP)
Show quote Hide quote
"Joe King" <br25***@aol.co.uk> wrote in message
news:Xns9BB4B694858EAjoekingaolcouk@74.209.136.81...
> "Pegasus \(MVP\)" <I.***@fly.com.oz> wrote in
> news:OqiPnKIkJHA.4976@TK2MSFTNGP06.phx.gbl:
>
>>
>> "Joe King" <br25***@aol.co.uk> wrote in message
>> news:Xns9BB4A9DD0CECCjoekingaolcouk@74.209.136.81...
>>> this code (by Mark Minasi) creates a batch file to run ntbackup:
>>>
>>>
>>> ================================================================
>>> Option Explicit
>>>
>>> Dim objFileSystem
>>> Dim objOutputFile
>>> Dim strOutputFile : strOutputFile =
>>> "C:\BatchFiles\NetworkBackup\Auto- NetBackup.bat"
>>> Dim strDayOfWeekText
>>> Dim strMyDate
>>> Dim strstrMyMonth
>>> Dim oWSH
>>> Dim sCommand
>>> Dim strDelBackup
>>> Dim strMoveBackup
>>> Dim strBackup
>>> Dim strType : strType = "INCREMENTAL"
>>> Dim strIntHDD : strIntHDD = "D:\NetworkBackup"
>>> Dim strExtHDD : strExtHDD = "F:"
>>>
>>>
>>> strDayOfWeekText = WeekDayName(WeekDay(Date), True)
>>>
>>>
>>>
>>> If strDayOfWeekText = "Sat" Then
>>> strType = "NORMAL"
>>> strDayOfWeekText = "Week"
>>> End If
>>>
>>>
>>> strMyDate = Year(Date) & Right("0" &Month(Date),2) & Right("0" &Day
>>> (Date),2)
>>>
>>>
>>>
>>> If strDayOfWeekText = "Week" Then
>>> ' keep last three full backups
>>> strDelBackup = "del /F /S /Q " &strIntHDD&"\04-"
>>> &strDayOfWeekText&"\*.*"
>>> strMoveBackup = "move "&strIntHDD&"\03-"&strDayOfWeekText&"\*.*
>>> "&strIntHDD&"\04-"&strDayOfWeekText&"\"
>>> strMoveBackup = "move "&strIntHDD&"\02-"&strDayOfWeekText&"\*.*
>>> "&strIntHDD&"\03-"&strDayOfWeekText&"\"
>>> strMoveBackup = "move "&strIntHDD&"\01-"&strDayOfWeekText&"\*.*
>>> "&strIntHDD&"\02-"&strDayOfWeekText&"\"
>>> Else
>>> ' keep last weeks incremental backup
>>> strDelBackup = "del /F /S /Q " &strIntHDD&"\02-"
>>> &strDayOfWeekText&"\*.*"
>>> strMoveBackup = "move " &strIntHDD&"\01-" &strDayOfWeekText&"\*.*
>>> " &strIntHDD&"\02-" &strDayOfWeekText&"\"
>>> End If
>>>
>>>
>>>
>>>
>>> Set objFileSystem = CreateObject("Scripting.fileSystemObject")
>>> Set objOutputFile = objFileSystem.CreateTextFile(strOutputFile, True)
>>> objOutputFile.WriteLine("REM " &strDayOfWeekText&" - " &strMyDate&" -
>>> " &Time &" - " &Date)
>>>
>>> If strDayOfWeekText <> "Sun" And strDayOfWeekText <> "Mon" Then
>>>
>>> objOutputFile.WriteLine(strDelBackup)
>>> objOutputFile.WriteLine(strMoveBackup)
>>> 'backup 1
>>> 'strBackup = "ntbackup backup \\act01\d$ /j "&strMyDate&" /f
>>> """&strIntHDD&"\01-"&strDayOfWeekText&"\act01-"&strMyDate&".bkf""
>>> /L:S /M "&strType
>>> 'objOutputFile.WriteLine(strBackup)
>>> 'backup 2
>>> 'strBackup = "ntbackup backup \\nas01\c$\act /j "&strMyDate&" /f
>>> """&strIntHDD&"\01-"&strDayOfWeekText&"\nas01-
>>> act-"&strMyDate&".bkf"" /L:S /M "&strType
>>> 'objOutputFile.WriteLine(strBackup)
>>>
>>> 'copy backup to removable drive
>>> strBackup = "xcopy "&strIntHDD&"\01-"&strDayOfWeekText&"\*.*
>>> "&strExtHDD&"\01-"&strDayOfWeekText&"\*.* /F /H /R /V /Y"
>>> objOutputFile.WriteLine(strBackup)
>>>
>>> End If
>>>
>>> objOutputFile.Close
>>> Set objFileSystem = Nothing
>>>
>>>
>>> Set oWSH = CreateObject("WScript.Shell")
>>> sCommand = strOutputFile
>>> Call oWSH.Run(sCommand)
>>> Set oWSH = Nothing
>>> ================================================================
>>>
>>>
>>> While I like the idea in concept, I do not like its' execution
>>>
>>> I'd like to bypass ntbackup completely, and just call xcopy to backup
>>> to a folder (01-mmddyy), keep 4 (one per week) of these, then at week
>>> 5 start overwriting week 1
>>>
>>> could you folks assist to get me started? (this will not scope-creep,
>>> btw)
>>>
>>>
>>> cheers.
>>>
>>> jk
>>
>> A couple of thoughts for starters:
>> - Microsoft has officially deprecated xcopy.exe. Robocopy is the
>> recommended replacement product.
>> - Since you intend to invoke a console command (xcopy or robocopy) and
>> since your logic is well within the grasp of a batch file, I suggest
>> you drop the idea of using the hybrid solution of a script that
>> invokes console commands. A batch file would require far fewer lines
>> of code which means less debugging and easier maintenance.
>>
>> A few questions:
>> - You mention "backup to a folder (01-mmddyy)". What's the "01" bit
>> for? Does it vary? Wouldn't the date code uniquely identify the
>> folder? - Do you back up each day or each week?
>> - What do you get when you type the following command at a Command
>> Prompt?
>>   echo %date%
>>
>>
>>
>
> xcopy has been just ducky in my context
> I just need to keep 3 additional increments, as opposed to the single
> weekly backup.
>
> the 01 would represent the first of 4 backups, 02, 03, 04 would follow.
> The
> fifth would be written into the 01 container
>
> ex
>
> 01-021609
> 02-022309
> 03-030209
> 04-030909
> then, 01-021609 would be deleted, and replaced by 01-031609
>
> yes, I suppose the datecode would accurately represent the folder.
>
> but - if I were to get hit by a bus, this may make it clearer for
> subsequent operators.
>
> i get: Mon 02/16/09

I think if you get run over by a bus then your successors would be quite
puzzled about the numbers 01..04. The folder 01-.. might be the most recent
folder, or the oldest folder, or any one in between . . . Much better to
stick to your original idea of using dates only.

Try the following batch file:
01. @echo off
02. set Source=d:\My Data
03. set BackupFolder=e:\My Backups
04.
05. for %%a in (%date%) do set MyDate=%%a
06. set Dest=%BackupFolder%\%MyDate:/=-%
07. if not exist "%BackupFolder%" md "%BackupFolder%"
08. set MyDate=%date:/=%
09. for /F "skip=4 delims=" %%a in ('dir /b /ad /o-d "%Folder%"') do (
10.   echo rd /s /q "%BackupFolder%\%%a")
11. echo robocopy "%Source%" "%Dest%" *.*

Instructions:
- Copy & paste the file into c:\MyBackup.bat. Do NOT retype it.
- Adjust lines 02 and 03 to suit your environment.
- Adjust line 11 by adding the appropriate switches for robocopy.
- Remove the line numbers.
- Open a Command Prompt.
- Run the file from the Command Prompt as it is and check if it
   would do what you expect.
- Remove the word "echo" in line 11 to activate the backup feature.
- Run the file for 5 or six weeks.
- Run the file from the Command Prompt and check if it would
  remove the appropriate backup folders.
- Remove the word "echo" in line 10 to activate the folder deletion feature.
And for fun: Compare the size of the above batch file with the size of your
original VB Script file.
Author
16 Feb 2009 11:57 PM
Joe King
Show quote Hide quote
"Pegasus \(MVP\)" <I.***@fly.com.oz> wrote in
news:e8cYE$IkJHA.5812@TK2MSFTNGP06.phx.gbl:

>
> Try the following batch file:
> 01. @echo off
> 02. set Source=d:\My Data
> 03. set BackupFolder=e:\My Backups
> 04.
> 05. for %%a in (%date%) do set MyDate=%%a
> 06. set Dest=%BackupFolder%\%MyDate:/=-%
> 07. if not exist "%BackupFolder%" md "%BackupFolder%"
> 08. set MyDate=%date:/=%
> 09. for /F "skip=4 delims=" %%a in ('dir /b /ad /o-d "%Folder%"') do (
> 10.   echo rd /s /q "%BackupFolder%\%%a")
> 11. echo robocopy "%Source%" "%Dest%" *.*
>
> Instructions:
> - Copy & paste the file into c:\MyBackup.bat. Do NOT retype it.
> - Adjust lines 02 and 03 to suit your environment.
> - Adjust line 11 by adding the appropriate switches for robocopy.
> - Remove the line numbers.
> - Open a Command Prompt.
> - Run the file from the Command Prompt as it is and check if it
>    would do what you expect.
> - Remove the word "echo" in line 11 to activate the backup feature.
> - Run the file for 5 or six weeks.
> - Run the file from the Command Prompt and check if it would
>   remove the appropriate backup folders.
> - Remove the word "echo" in line 10 to activate the folder deletion
> feature. And for fun: Compare the size of the above batch file with
> the size of your original VB Script file.



line 4 is intentionally blank?
Author
17 Feb 2009 2:20 AM
Joe King
Show quote Hide quote
"Pegasus \(MVP\)" <I.***@fly.com.oz> wrote in
news:e8cYE$IkJHA.5812@TK2MSFTNGP06.phx.gbl:

>
> "Joe King" <br25***@aol.co.uk> wrote in message
> news:Xns9BB4B694858EAjoekingaolcouk@74.209.136.81...
>> "Pegasus \(MVP\)" <I.***@fly.com.oz> wrote in
>> news:OqiPnKIkJHA.4976@TK2MSFTNGP06.phx.gbl:
>>
>>>
>>> "Joe King" <br25***@aol.co.uk> wrote in message
>>> news:Xns9BB4A9DD0CECCjoekingaolcouk@74.209.136.81...
>>>> this code (by Mark Minasi) creates a batch file to run ntbackup:
>>>>
>>>>
>>>> ================================================================
>>>> Option Explicit
>>>>
>>>> Dim objFileSystem
>>>> Dim objOutputFile
>>>> Dim strOutputFile : strOutputFile =
>>>> "C:\BatchFiles\NetworkBackup\Auto- NetBackup.bat"
>>>> Dim strDayOfWeekText
>>>> Dim strMyDate
>>>> Dim strstrMyMonth
>>>> Dim oWSH
>>>> Dim sCommand
>>>> Dim strDelBackup
>>>> Dim strMoveBackup
>>>> Dim strBackup
>>>> Dim strType : strType = "INCREMENTAL"
>>>> Dim strIntHDD : strIntHDD = "D:\NetworkBackup"
>>>> Dim strExtHDD : strExtHDD = "F:"
>>>>
>>>>
>>>> strDayOfWeekText = WeekDayName(WeekDay(Date), True)
>>>>
>>>>
>>>>
>>>> If strDayOfWeekText = "Sat" Then
>>>> strType = "NORMAL"
>>>> strDayOfWeekText = "Week"
>>>> End If
>>>>
>>>>
>>>> strMyDate = Year(Date) & Right("0" &Month(Date),2) & Right("0" &Day
>>>> (Date),2)
>>>>
>>>>
>>>>
>>>> If strDayOfWeekText = "Week" Then
>>>> ' keep last three full backups
>>>> strDelBackup = "del /F /S /Q " &strIntHDD&"\04-"
>>>> &strDayOfWeekText&"\*.*"
>>>> strMoveBackup = "move "&strIntHDD&"\03-"&strDayOfWeekText&"\*.*
>>>> "&strIntHDD&"\04-"&strDayOfWeekText&"\"
>>>> strMoveBackup = "move "&strIntHDD&"\02-"&strDayOfWeekText&"\*.*
>>>> "&strIntHDD&"\03-"&strDayOfWeekText&"\"
>>>> strMoveBackup = "move "&strIntHDD&"\01-"&strDayOfWeekText&"\*.*
>>>> "&strIntHDD&"\02-"&strDayOfWeekText&"\"
>>>> Else
>>>> ' keep last weeks incremental backup
>>>> strDelBackup = "del /F /S /Q " &strIntHDD&"\02-"
>>>> &strDayOfWeekText&"\*.*"
>>>> strMoveBackup = "move " &strIntHDD&"\01-" &strDayOfWeekText&"\*.*
>>>> " &strIntHDD&"\02-" &strDayOfWeekText&"\"
>>>> End If
>>>>
>>>>
>>>>
>>>>
>>>> Set objFileSystem = CreateObject("Scripting.fileSystemObject")
>>>> Set objOutputFile = objFileSystem.CreateTextFile(strOutputFile,
>>>> True) objOutputFile.WriteLine("REM " &strDayOfWeekText&" - "
>>>> &strMyDate&" - " &Time &" - " &Date)
>>>>
>>>> If strDayOfWeekText <> "Sun" And strDayOfWeekText <> "Mon" Then
>>>>
>>>> objOutputFile.WriteLine(strDelBackup)
>>>> objOutputFile.WriteLine(strMoveBackup)
>>>> 'backup 1
>>>> 'strBackup = "ntbackup backup \\act01\d$ /j "&strMyDate&" /f
>>>> """&strIntHDD&"\01-"&strDayOfWeekText&"\act01-"&strMyDate&".bkf""
>>>> /L:S /M "&strType
>>>> 'objOutputFile.WriteLine(strBackup)
>>>> 'backup 2
>>>> 'strBackup = "ntbackup backup \\nas01\c$\act /j "&strMyDate&" /f
>>>> """&strIntHDD&"\01-"&strDayOfWeekText&"\nas01-
>>>> act-"&strMyDate&".bkf"" /L:S /M "&strType
>>>> 'objOutputFile.WriteLine(strBackup)
>>>>
>>>> 'copy backup to removable drive
>>>> strBackup = "xcopy "&strIntHDD&"\01-"&strDayOfWeekText&"\*.*
>>>> "&strExtHDD&"\01-"&strDayOfWeekText&"\*.* /F /H /R /V /Y"
>>>> objOutputFile.WriteLine(strBackup)
>>>>
>>>> End If
>>>>
>>>> objOutputFile.Close
>>>> Set objFileSystem = Nothing
>>>>
>>>>
>>>> Set oWSH = CreateObject("WScript.Shell")
>>>> sCommand = strOutputFile
>>>> Call oWSH.Run(sCommand)
>>>> Set oWSH = Nothing
>>>> ================================================================
>>>>
>>>>
>>>> While I like the idea in concept, I do not like its' execution
>>>>
>>>> I'd like to bypass ntbackup completely, and just call xcopy to
>>>> backup to a folder (01-mmddyy), keep 4 (one per week) of these,
>>>> then at week 5 start overwriting week 1
>>>>
>>>> could you folks assist to get me started? (this will not
>>>> scope-creep, btw)
>>>>
>>>>
>>>> cheers.
>>>>
>>>> jk
>>>
>>> A couple of thoughts for starters:
>>> - Microsoft has officially deprecated xcopy.exe. Robocopy is the
>>> recommended replacement product.
>>> - Since you intend to invoke a console command (xcopy or robocopy)
>>> and since your logic is well within the grasp of a batch file, I
>>> suggest you drop the idea of using the hybrid solution of a script
>>> that invokes console commands. A batch file would require far fewer
>>> lines of code which means less debugging and easier maintenance.
>>>
>>> A few questions:
>>> - You mention "backup to a folder (01-mmddyy)". What's the "01" bit
>>> for? Does it vary? Wouldn't the date code uniquely identify the
>>> folder? - Do you back up each day or each week?
>>> - What do you get when you type the following command at a Command
>>> Prompt?
>>>   echo %date%
>>>
>>>
>>>
>>
>> xcopy has been just ducky in my context
>> I just need to keep 3 additional increments, as opposed to the single
>> weekly backup.
>>
>> the 01 would represent the first of 4 backups, 02, 03, 04 would
>> follow. The
>> fifth would be written into the 01 container
>>
>> ex
>>
>> 01-021609
>> 02-022309
>> 03-030209
>> 04-030909
>> then, 01-021609 would be deleted, and replaced by 01-031609
>>
>> yes, I suppose the datecode would accurately represent the folder.
>>
>> but - if I were to get hit by a bus, this may make it clearer for
>> subsequent operators.
>>
>> i get: Mon 02/16/09
>
> I think if you get run over by a bus then your successors would be
> quite puzzled about the numbers 01..04. The folder 01-.. might be the
> most recent folder, or the oldest folder, or any one in between . . .
> Much better to stick to your original idea of using dates only.
>
> Try the following batch file:
> 01. @echo off
> 02. set Source=d:\My Data
> 03. set BackupFolder=e:\My Backups
> 04.
> 05. for %%a in (%date%) do set MyDate=%%a
> 06. set Dest=%BackupFolder%\%MyDate:/=-%
> 07. if not exist "%BackupFolder%" md "%BackupFolder%"
> 08. set MyDate=%date:/=%
> 09. for /F "skip=4 delims=" %%a in ('dir /b /ad /o-d "%Folder%"') do (
> 10.   echo rd /s /q "%BackupFolder%\%%a")
> 11. echo robocopy "%Source%" "%Dest%" *.*
>
> Instructions:
> - Copy & paste the file into c:\MyBackup.bat. Do NOT retype it.
> - Adjust lines 02 and 03 to suit your environment.
> - Adjust line 11 by adding the appropriate switches for robocopy.
> - Remove the line numbers.
> - Open a Command Prompt.
> - Run the file from the Command Prompt as it is and check if it
>    would do what you expect.
> - Remove the word "echo" in line 11 to activate the backup feature.
> - Run the file for 5 or six weeks.
> - Run the file from the Command Prompt and check if it would
>   remove the appropriate backup folders.
> - Remove the word "echo" in line 10 to activate the folder deletion
> feature. And for fun: Compare the size of the above batch file with
> the size of your original VB Script file.
>
>
>

close.

However

there's no removal of folders pre 4 backups.
I simulated 7 weeks of running, and nothing was removed.
Author
17 Feb 2009 6:49 AM
Pegasus (MVP)
"Joe King" <br25***@aol.co.uk> wrote in message
news:Xns9BB4D91DB6AF0joekingaolcouk@74.209.136.81...

> there's no removal of folders pre 4 backups.
> I simulated 7 weeks of running, and nothing was removed.

This would be because you ignored my last instruction:
"- Remove the word "echo" in line 10 to activate the folder deletion
feature."
Author
17 Feb 2009 1:04 PM
Joe King
"Pegasus \(MVP\)" <I.***@fly.com.oz> wrote in news:edaalvMkJHA.5964
@TK2MSFTNGP03.phx.gbl:

>
> "Joe King" <br25***@aol.co.uk> wrote in message
> news:Xns9BB4D91DB6AF0joekingaolcouk@74.209.136.81...
>
>> there's no removal of folders pre 4 backups.
>> I simulated 7 weeks of running, and nothing was removed.
>
> This would be because you ignored my last instruction:
> "- Remove the word "echo" in line 10 to activate the folder deletion
> feature."
>
>

ummm - I'd like to concur, but I just can't.


@echo off
set Source=d:\test\misc
set BackupFolder=H:\BU_test
for %%a in (%date%) do set MyDate=%%a
set Dest=%BackupFolder%\%MyDate:/=-%
if not exist "%BackupFolder%" md "%BackupFolder%"
set MyDate=%date:/=%
for /F "skip=4 delims=" %%a in ('dir /b /ad /o-d "%Folder%"') do (rd /s /q
"%BackupFolder%\%%a")
robocopy "%Source%" "%Dest%" *.* /E /COPYALL



I'll figger it out

thnax for the assist
Author
17 Feb 2009 2:52 PM
Pegasus (MVP)
Show quote Hide quote
"Joe King" <br25***@aol.co.uk> wrote in message
news:Xns9BB552087F638joekingaolcouk@74.209.136.83...
> "Pegasus \(MVP\)" <I.***@fly.com.oz> wrote in news:edaalvMkJHA.5964
> @TK2MSFTNGP03.phx.gbl:
>
>>
>> "Joe King" <br25***@aol.co.uk> wrote in message
>> news:Xns9BB4D91DB6AF0joekingaolcouk@74.209.136.81...
>>
>>> there's no removal of folders pre 4 backups.
>>> I simulated 7 weeks of running, and nothing was removed.
>>
>> This would be because you ignored my last instruction:
>> "- Remove the word "echo" in line 10 to activate the folder deletion
>> feature."
>>
>>
>
> ummm - I'd like to concur, but I just can't.
>
>
> @echo off
> set Source=d:\test\misc
> set BackupFolder=H:\BU_test
> for %%a in (%date%) do set MyDate=%%a
> set Dest=%BackupFolder%\%MyDate:/=-%
> if not exist "%BackupFolder%" md "%BackupFolder%"
> set MyDate=%date:/=%
> for /F "skip=4 delims=" %%a in ('dir /b /ad /o-d "%Folder%"') do (rd /s /q
> "%BackupFolder%\%%a")
> robocopy "%Source%" "%Dest%" *.* /E /COPYALL
>
>
>
> I'll figger it out
>
> thnax for the assist

To make it easy for you to see where each line starts I numbered each line.
From the script above I am unable to tell if the following is a single long
line, temporarily enclosed by three asterisks:

***for /F "skip=4 delims=" %%a in ('dir /b /ad /o-d "%Folder%"') do (rd /s
/q "%BackupFolder%\%%a")***

or if it is two lines, also temporarily enclosed by asterisks:

*** for /F "skip=4 delims=" %%a in ('dir /b /ad /o-d "%Folder%"') do (rd /s
/q ***
*** "%BackupFolder%\%%a")***

You're in an excellent position to judge! Putting the "echo" word back in
again would give you a superb diagnostic tool.
Author
17 Feb 2009 3:12 PM
Joe King
"Pegasus \(MVP\)" <I.***@fly.com.oz> wrote in news:uhHZm9QkJHA.3380
@TK2MSFTNGP04.phx.gbl:

> for /F "skip=4 delims=" %%a in ('dir /b /ad /o-d "%Folder%"') do (rd /s
> /q "%BackupFolder%\%%a")


I understood the format change and it is one complete line.

I don't understand the first component of the command.
"for /F "skip=4 delims=""

what command does the /F switch modify?

it's not 'set', nor 'dir', nor 'rd'



if I can isolate that, I'm on my way, and can finish this meself

but you can see the 'echo' was removed, right?
Author
17 Feb 2009 3:32 PM
Pegasus (MVP)
Show quote Hide quote
"Joe King" <br25***@aol.co.uk> wrote in message
news:Xns9BB567DF26F50joekingaolcouk@74.209.136.87...
> "Pegasus \(MVP\)" <I.***@fly.com.oz> wrote in news:uhHZm9QkJHA.3380
> @TK2MSFTNGP04.phx.gbl:
>
>> for /F "skip=4 delims=" %%a in ('dir /b /ad /o-d "%Folder%"') do (rd /s
>> /q "%BackupFolder%\%%a")
>
>
> I understood the format change and it is one complete line.
>
> I don't understand the first component of the command.
> "for /F "skip=4 delims=""
>
> what command does the /F switch modify?
>
> it's not 'set', nor 'dir', nor 'rd'
>
> if I can isolate that, I'm on my way, and can finish this meself
>
> but you can see the 'echo' was removed, right?

Yes, I can see that you removed the word "echo", and as I said before: You
should restore it so that you can see with your own eyes which folder(s)
would be deleted. This is the art of debugging: Making things visible that
remain otherwise hidden.

The /F switch allows you to add a number of options to the "for" command.  I
used three of them:
for /F "skip=4 delims=" %%a in ('dir /b /ad /o-d "%Folder%"') . . .
- skip=4: Skip the first four lines that are processed. In your case:
   Skip the four most recent folder names.
- delims=: Treat each line as a single string. Do not break it up
   into space-delimited tokens. In your case: Process each folder
   name as a string, regardless of any embedded spaces.
- ' (single quote): Execute the command between the single quotes and
  assign each line in turn as a string value to the loop variable %%a.

Now put "echo" back again, then run the batch file from a Command Prompt and
make a careful note of the "rd" commands you see on the screen. They are
they key to your problem!
Author
17 Feb 2009 3:48 PM
Joe King
Show quote Hide quote
"Pegasus \(MVP\)" <I.***@fly.com.oz> wrote in
news:ul3$7TRkJHA.5836@TK2MSFTNGP02.phx.gbl:

>
> "Joe King" <br25***@aol.co.uk> wrote in message
> news:Xns9BB567DF26F50joekingaolcouk@74.209.136.87...
>> "Pegasus \(MVP\)" <I.***@fly.com.oz> wrote in news:uhHZm9QkJHA.3380
>> @TK2MSFTNGP04.phx.gbl:
>>
>>> for /F "skip=4 delims=" %%a in ('dir /b /ad /o-d "%Folder%"') do (rd
>>> /s /q "%BackupFolder%\%%a")
>>
>>
>> I understood the format change and it is one complete line.
>>
>> I don't understand the first component of the command.
>> "for /F "skip=4 delims=""
>>
>> what command does the /F switch modify?
>>
>> it's not 'set', nor 'dir', nor 'rd'
>>
>> if I can isolate that, I'm on my way, and can finish this meself
>>
>> but you can see the 'echo' was removed, right?
>
> Yes, I can see that you removed the word "echo", and as I said before:
> You should restore it so that you can see with your own eyes which
> folder(s) would be deleted. This is the art of debugging: Making
> things visible that remain otherwise hidden.
>
> The /F switch allows you to add a number of options to the "for"
> command.  I used three of them:
> for /F "skip=4 delims=" %%a in ('dir /b /ad /o-d "%Folder%"') . . .
> - skip=4: Skip the first four lines that are processed. In your case:
>    Skip the four most recent folder names.
> - delims=: Treat each line as a single string. Do not break it up
>    into space-delimited tokens. In your case: Process each folder
>    name as a string, regardless of any embedded spaces.
> - ' (single quote): Execute the command between the single quotes and
>   assign each line in turn as a string value to the loop variable %%a.
>
> Now put "echo" back again, then run the batch file from a Command
> Prompt and make a careful note of the "rd" commands you see on the
> screen. They are they key to your problem!
>
>
>

aha
after removing the 'echo' prior to the 'rd'

it's trying to delete (captured) these default folders, none of which
have been defined:


rd /s /q "H:\BU\tmp"
rd /s /q "H:\BU\Documents and Settings"
rd /s /q "H:\BU\RECYCLER"
rd /s /q "H:\BU\Intel"
rd /s /q "H:\BU\DELL"
rd /s /q "H:\BU\System Volume Information"
Author
17 Feb 2009 4:09 PM
Pegasus (MVP)
Show quote Hide quote
"Joe King" <br25***@aol.co.uk> wrote in message
news:Xns9BB56DE3CB03Cjoekingaolcouk@74.209.136.84...
>
> aha
> after removing the 'echo' prior to the 'rd'
>
> it's trying to delete (captured) these default folders, none of which
> have been defined:
>
>
> rd /s /q "H:\BU\tmp"
> rd /s /q "H:\BU\Documents and Settings"
> rd /s /q "H:\BU\RECYCLER"
> rd /s /q "H:\BU\Intel"
> rd /s /q "H:\BU\DELL"
> rd /s /q "H:\BU\System Volume Information"

Oh dear! The string
('dir /b /ad /o-d "%Folder%"')
should actually read
('dir /b /ad /o-d "%BackupFolder%"')
because %Folder% is not defined anywhere.

Sorry for my oversight!
Author
17 Feb 2009 4:11 PM
Joe King
Joe King <br25***@aol.co.uk> wrote in
Show quoteHide quote
news:Xns9BB56DE3CB03Cjoekingaolcouk@74.209.136.84:

> "Pegasus \(MVP\)" <I.***@fly.com.oz> wrote in
> news:ul3$7TRkJHA.5836@TK2MSFTNGP02.phx.gbl:
>
>>
>> "Joe King" <br25***@aol.co.uk> wrote in message
>> news:Xns9BB567DF26F50joekingaolcouk@74.209.136.87...
>>> "Pegasus \(MVP\)" <I.***@fly.com.oz> wrote in news:uhHZm9QkJHA.3380
>>> @TK2MSFTNGP04.phx.gbl:
>>>
>>>> for /F "skip=4 delims=" %%a in ('dir /b /ad /o-d "%Folder%"') do (rd
>>>> /s /q "%BackupFolder%\%%a")
>>>
>>>
>>> I understood the format change and it is one complete line.
>>>
>>> I don't understand the first component of the command.
>>> "for /F "skip=4 delims=""
>>>
>>> what command does the /F switch modify?
>>>
>>> it's not 'set', nor 'dir', nor 'rd'
>>>
>>> if I can isolate that, I'm on my way, and can finish this meself
>>>
>>> but you can see the 'echo' was removed, right?
>>
>> Yes, I can see that you removed the word "echo", and as I said before:
>> You should restore it so that you can see with your own eyes which
>> folder(s) would be deleted. This is the art of debugging: Making
>> things visible that remain otherwise hidden.
>>
>> The /F switch allows you to add a number of options to the "for"
>> command.  I used three of them:
>> for /F "skip=4 delims=" %%a in ('dir /b /ad /o-d "%Folder%"') . . .
>> - skip=4: Skip the first four lines that are processed. In your case:
>>    Skip the four most recent folder names.
>> - delims=: Treat each line as a single string. Do not break it up
>>    into space-delimited tokens. In your case: Process each folder
>>    name as a string, regardless of any embedded spaces.
>> - ' (single quote): Execute the command between the single quotes and
>>   assign each line in turn as a string value to the loop variable %%a.
>>
>> Now put "echo" back again, then run the batch file from a Command
>> Prompt and make a careful note of the "rd" commands you see on the
>> screen. They are they key to your problem!
>>
>>
>>
>
> aha
> after removing the 'echo' prior to the 'rd'
>
> it's trying to delete (captured) these default folders, none of which
> have been defined:
>
>
> rd /s /q "H:\BU\tmp"
> rd /s /q "H:\BU\Documents and Settings"
> rd /s /q "H:\BU\RECYCLER"
> rd /s /q "H:\BU\Intel"
> rd /s /q "H:\BU\DELL"
> rd /s /q "H:\BU\System Volume Information"
>
>
>
>
>
>


all done

replace "%Folder%" with "%BackupFolder%"

and bobs yer uncle

thnax for the patience

jk
Author
17 Feb 2009 4:39 PM
Al Dunbar
Show quote Hide quote
"Pegasus (MVP)" <I.***@fly.com.oz> wrote in message
news:ul3$7TRkJHA.5836@TK2MSFTNGP02.phx.gbl...
>
> "Joe King" <br25***@aol.co.uk> wrote in message
> news:Xns9BB567DF26F50joekingaolcouk@74.209.136.87...
>> "Pegasus \(MVP\)" <I.***@fly.com.oz> wrote in news:uhHZm9QkJHA.3380
>> @TK2MSFTNGP04.phx.gbl:
>>
>>> for /F "skip=4 delims=" %%a in ('dir /b /ad /o-d "%Folder%"') do (rd /s
>>> /q "%BackupFolder%\%%a")
>>
>>
>> I understood the format change and it is one complete line.
>>
>> I don't understand the first component of the command.
>> "for /F "skip=4 delims=""
>>
>> what command does the /F switch modify?

/F modifies the FOR command.

/Al

Show quoteHide quote
>> it's not 'set', nor 'dir', nor 'rd'
>>
>> if I can isolate that, I'm on my way, and can finish this meself
>>
>> but you can see the 'echo' was removed, right?
>
> Yes, I can see that you removed the word "echo", and as I said before: You
> should restore it so that you can see with your own eyes which folder(s)
> would be deleted. This is the art of debugging: Making things visible that
> remain otherwise hidden.
>
> The /F switch allows you to add a number of options to the "for" command.
> I used three of them:
> for /F "skip=4 delims=" %%a in ('dir /b /ad /o-d "%Folder%"') . . .
> - skip=4: Skip the first four lines that are processed. In your case:
>   Skip the four most recent folder names.
> - delims=: Treat each line as a single string. Do not break it up
>   into space-delimited tokens. In your case: Process each folder
>   name as a string, regardless of any embedded spaces.
> - ' (single quote): Execute the command between the single quotes and
>  assign each line in turn as a string value to the loop variable %%a.
>
> Now put "echo" back again, then run the batch file from a Command Prompt
> and make a careful note of the "rd" commands you see on the screen. They
> are they key to your problem!
>

Bookmark and Share

Post Thread options