Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > modify incremental_backup

Reply
Thread Tools Display Modes

modify incremental_backup

 
 
Joe King
Guest
Posts: n/a

 
      02-16-2009
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
 
Reply With Quote
 
 
 
 
Pegasus \(MVP\)
Guest
Posts: n/a

 
      02-16-2009

"Joe King" <> 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%


 
Reply With Quote
 
Joe King
Guest
Posts: n/a

 
      02-16-2009
"Pegasus \(MVP\)" <> wrote in
news::

>
> "Joe King" <> 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



 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a

 
      02-16-2009

"Joe King" <> wrote in message
news:Xns9BB4B694858EAjoekingaolcouk@74.209.136.81. ..
> "Pegasus \(MVP\)" <> wrote in
> news::
>
>>
>> "Joe King" <> 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.


 
Reply With Quote
 
Joe King
Guest
Posts: n/a

 
      02-16-2009
"Pegasus \(MVP\)" <> wrote in
news:e8cYE$:

>
> 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?

 
Reply With Quote
 
Joe King
Guest
Posts: n/a

 
      02-17-2009
"Pegasus \(MVP\)" <> wrote in
news:e8cYE$:

>
> "Joe King" <> wrote in message
> news:Xns9BB4B694858EAjoekingaolcouk@74.209.136.81. ..
>> "Pegasus \(MVP\)" <> wrote in
>> news::
>>
>>>
>>> "Joe King" <> 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.
 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a

 
      02-17-2009

"Joe King" <> 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."


 
Reply With Quote
 
Joe King
Guest
Posts: n/a

 
      02-17-2009
"Pegasus \(MVP\)" <> wrote in news:edaalvMkJHA.5964
@TK2MSFTNGP03.phx.gbl:

>
> "Joe King" <> 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
 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a

 
      02-17-2009

"Joe King" <> wrote in message
news:Xns9BB552087F638joekingaolcouk@74.209.136.83. ..
> "Pegasus \(MVP\)" <> wrote in news:edaalvMkJHA.5964
> @TK2MSFTNGP03.phx.gbl:
>
>>
>> "Joe King" <> 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.


 
Reply With Quote
 
Joe King
Guest
Posts: n/a

 
      02-17-2009
"Pegasus \(MVP\)" <> 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?
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Modify Uses John McC Active Directory 4 01-16-2009 01:37 AM
WSS - Modify Sal Candela Windows Small Business Server 7 12-04-2006 01:34 AM
Last to Modify Will Schneider Active Directory 5 03-05-2005 03:16 PM
Add/Modify PTR RR using DNS API in C/C++ RD DNS Server 5 10-11-2004 03:19 AM
Modify rights but cannot modify David Gower Active Directory 2 01-14-2004 02:39 AM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59