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