Login | |
|
 |
RE: Backup Script-copy - 1/19/2007 5:03:15 AM
|
|
 |
|
| |
ebgreen
Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
|
In that case, try this: Option Explicit 'On Error Resume Next Const SOURCEDIR = "G:\new\" 'Note the trailing \ Const TARGETROOTDIR = "F:\JDENJ00NASV01Backups\" 'Right now they are the same but this makes it easy to change Dim oFSO : Set oFSO = CreateObject("Scripting.FileSystemObject") Dim oFile, oFile2 Dim strNewName Dim strDay Dim dicDays : Set dicDays = CreateObject("Scripting.Dictionary") dicDays.Add "MONDAY", TARGETROOTDIR & "MONDAY\" dicDays.Add "TUESDAY", TARGETROOTDIR & "TUESDAY\" dicDays.Add "WEDNESDAY", TARGETROOTDIR & "WEDNESDAY\" dicDays.Add "THURSDAY", TARGETROOTDIR & "THURSDAY\" dicDays.Add "FRIDAY", TARGETROOTDIR & "FRIDAY\" dicDays.Add "SATURDAY", TARGETROOTDIR & "SATURDAY\" dicDays.Add "SUNDAY", TARGETROOTDIR & "SUNDAY\" For Each oFile In oFSO.GetFolder(SOURCEDIR).Files If dicDays.Exists(UCase(oFSO.GetBaseName(oFile.Name))) Then strNewName = dicDays(UCase(oFSO.GetBaseName(oFile.Name))) & oFSO.GetBaseName(oFile.Name) & GetTimeStamp(oFile) & "." & oFSO.GetExtensionName(oFile.Name) oFile.Copy strNewName For Each oFile2 In oFSO.GetFolder(dicDays(UCase(oFSO.GetBaseName(oFile.Name)))).Files If oFSO.GetAbsolutePathName(oFile2.Name) <> oFSO.GetBaseName(strNewName) Then oFile2.Delete True End If Next oFile.Delete True End If Next Function GetTimeStamp(oFile) 'Takes a file and returns a string formatted as YYYYMMDD based on the last modified date of the file GetTimeStamp = Right("0000" & Year(oFile.DateLastModified), 4) _ & Right("00" & Month(oFile.DateLastModified), 2) _ & Right("00" & Day(oFile.DateLastModified), 2) End Function
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Backup Script-copy - 1/19/2007 5:57:47 AM
|
|
 |
|
| |
ebgreen
Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
|
Ok, time for a reset. I'm getting confused about what the end result should be. Here is how I understand the system: INITIAL CONDITIONS: There is a folder (srcDir) that has files in it. These files will be named x.bkf where x is a day of the week PROCESS There is another folder (tgtDir) that has a subfolder for each day of the week. When the script runs, it will copy the .bkf file from srcDir to the subfolder in tgtDir for the day of the week that corresponds to it's name. It will rename the file during the copy to add a timestamp into the name. It will delete the original file from srcDir. It will make sure that there are only 7 days worth of files in the backup dir. END CONDITIONS: No .bkf files in the srcDir folder. 7 files in each of the backup folders (one for each day for the past 7 days) for a total of 49 backup files.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Backup Script-copy - 1/19/2007 7:52:29 AM
|
|
 |
|
| |
netman06
Posts: 99
Score: 0
Joined: 10/19/2006
Status: offline
|
WOW, great explanation, I wish I had your ability for explaining the processes. Yes you are correct, that will work for me. I do have a space problem with 7 days, of full backups, and diff backups. Well, I'm at a lost, with what to do with the target backup files. I main problem is I can not have more then 7 files total, do to space limits on the hard drive. For the source drive it is a TB server with no limits. so can we have the source dir keep the 7 x 49 files 7 files for each day of the week, then delete them, when older then 7 days. now for the target drive, which is my security parachute, only keep 1 file for each of the days of the week. for a total of 7 files 1, full and 6, diffs, I should be able to handle this space. but I have no idea how to only have 1 file for each day. Process is to run. 1) rename backup file to last modified date, which is in the source dir 2) copy file into day of the week folder, which is in the source dir 3) find files older then 7 days I do not know if you have a better idea, but what about this. before we do anything copy the native ntbackup file, say named monday, copy it to the targert drive, in the monday folder, and overwrite any file there. 1) copy monday into the monday folder on the target drive 2) if file already exists there delete it. 3) then copy the monday backup file into the monday folder, which is on the target drive. so put this before we do all of the other scripting. we can use these drives for the script. Source drive: f:\backupfiles Target drive: g:\saved_backupfiles
|
|
| |
|
|
|
 |
RE: Backup Script-copy - 1/19/2007 8:27:35 AM
|
|
 |
|
| |
ebgreen
Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
|
Try this. It is untested so there may be some typos/errors in it: Option Explicit 'On Error Resume Next Const SOURCEDIR = "G:\new\" 'Note the trailing \ Const TARGETROOTDIR = "F:\JDENJ00NASV01Backups\" 'Right now they are the same but this makes it easy to change Dim oFSO : Set oFSO = CreateObject("Scripting.FileSystemObject") Dim oFile Dim strDay Dim dicDays : Set dicDays = CreateObject("Scripting.Dictionary") dicDays.Add "MONDAY", TARGETROOTDIR & "MONDAY\" dicDays.Add "TUESDAY", TARGETROOTDIR & "TUESDAY\" dicDays.Add "WEDNESDAY", TARGETROOTDIR & "WEDNESDAY\" dicDays.Add "THURSDAY", TARGETROOTDIR & "THURSDAY\" dicDays.Add "FRIDAY", TARGETROOTDIR & "FRIDAY\" dicDays.Add "SATURDAY", TARGETROOTDIR & "SATURDAY\" dicDays.Add "SUNDAY", TARGETROOTDIR & "SUNDAY\" For Each oFile In oFSO.GetFolder(SOURCEDIR).Files If dicDays.Exists(UCase(oFSO.GetBaseName(oFile.Name))) Then strDay = UCase(oFSO.GetBaseName(oFile.Name)) 'Rename the backup file to the last modified Date oFile.Name = oFSO.GetBaseName(oFile.Name) & GetTimeStamp(oFile) & "." & oFSO.GetExtensionName(oFile.Name) 'remove any files from the day of week folders that are over 7 days old CleanUpOldFiles oFSO.GetFolder(SOURCEDIR & strDay), 7 'copy the file into the day of the week folder in source oFile.Copy SOURCEDIR + strDay 'remove the current file from the day of week folder in the target dir oFSO.DeleteFile TARGETROOTDIR & strDay & "\*.*" 'copy the file to the day of week folder in the target folder oFile.Copy TARGETROOTDIR & strDay 'delete the file from the source dir so that it does not get backed up again oFile.Delete True End If Next Sub CleanUpOldFiles(oFolder, nDays) Dim oFile For Each oFile In oFolder.Files If DateDiff("d", oFile.DateLastModified, Now()) > nDays Then oFile.Delete True End If Next End Sub Function GetTimeStamp(oFile) 'Takes a file and returns a string formatted as YYYYMMDD based on the last modified date of the file GetTimeStamp = Right("0000" & Year(oFile.DateLastModified), 4) _ & Right("00" & Month(oFile.DateLastModified), 2) _ & Right("00" & Day(oFile.DateLastModified), 2) End Function
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Backup Script-copy - 1/19/2007 3:42:51 PM
|
|
 |
|
| |
netman06
Posts: 99
Score: 0
Joined: 10/19/2006
Status: offline
|
Hello, EBGreen I tried the script, an still getting an error message: Line 26,Char 2 - Microsoft VBScript runtime error: Permission denied I have tried alot of things to get it to work with no luck, I even search google for error message and fso.copy information, and have no idea why I'm getting this error, can you please check the on your computer to see if you too get it. Here is how I have the folder structure setup. Sourcedir: c:\denbak1 monday tuesday wednesday thursday friday saturday sunday Targetdir: c:\denbak2 monday tuesday wednesday thursday friday saturday sunday I even tried it with putting the say monday file, in the root of the sourcedir, but that did not work. All that is happening right now is the say monday.bkf is being renamed monday20070119.bkf I know we are very close but is seems to be with the path statements. if it is a permission issue, I do not know what to check, because I'm an administrator on this windows 2000 pro workstation. if you can get it to work, say with a monday.bkf file, I just rename any file to monday.bkf I echo these. Sourcedir and strday: C:\Denbak1\ MONDAY this looks good to me. Thanks, Mike
|
|
| |
|
|
|
 |
RE: Backup Script-copy - 1/22/2007 2:18:17 AM
|
|
 |
|
| |
ebgreen
Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
|
Well, when you do this oFSO.CopyFile, you are using the FileSystemObject to do the copy. When you do oFile.Copy, you are using the file object to do the copy. I am not aware of any differences but apparently there are.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
|
|