Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


RE: Backup Script-copy

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,41914
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> RE: Backup Script-copy
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: <<   < prev  1 2 [3]
Login
Message << Older Topic   Newer Topic >>
 RE: Backup Script-copy - 1/19/2007 3:43:52 AM   
  netman06

 

Posts: 99
Score: 0
Joined: 10/19/2006
Status: offline
use the above code, still receeving the same error message, as far as the archiving, do to space issues, I only want to keep two copies one copy in the source folder and one copy in the target folder.

This way I also have two copies.

Thanks,

Mike

(in reply to ebgreen)
 
 
Post #: 41
 
 RE: Backup Script-copy - 1/19/2007 3:45:13 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
Will there ever be other files in the archive folders?

_____________________________

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

(in reply to netman06)
 
 
Post #: 42
 
 RE: Backup Script-copy - 1/19/2007 4:07:23 AM   
  netman06

 

Posts: 99
Score: 0
Joined: 10/19/2006
Status: offline
no, just the daily bkf files, days of the week only, so mondau, tuesday, wednesday, thursday, friday, saturday, sunday.

Mike

(in reply to ebgreen)
 
 
Post #: 43
 
 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

(in reply to ebgreen)
 
 
Post #: 44
 
 RE: Backup Script-copy - 1/19/2007 5:29:43 AM   
  netman06

 

Posts: 99
Score: 0
Joined: 10/19/2006
Status: offline
a couple of problems.

1) its deletes all bkf, and seems to even if they are old, it even deletes the new files with a date modified 1/18/2007

2) it does not even copy the files into the F:\JDENJ00NASV01Backups

Would it be easier to just set it up to delete files older than 7 days inside the days of the week folders inside the F:\JDENJ00NASV01Backups, then I'll set up NTBackup to overwrite the days of the week files, in g:\new folder, then we all need to worry about the f:\directory for deleting files.

I do not get any errors now, with the new code.

(in reply to ebgreen)
 
 
Post #: 45
 
 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

(in reply to netman06)
 
 
Post #: 46
 
 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




(in reply to ebgreen)
 
 
Post #: 47
 
 RE: Backup Script-copy - 1/19/2007 8:12:50 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
Ok, I think I understand the process better now. I'll see what I can do.

_____________________________

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

(in reply to netman06)
 
 
Post #: 48
 
 RE: Backup Script-copy - 1/19/2007 8:19:54 AM   
  netman06

 

Posts: 99
Score: 0
Joined: 10/19/2006
Status: offline
thanks, I'm online if you have any questions.

Mike

(in reply to ebgreen)
 
 
Post #: 49
 
 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

(in reply to ebgreen)
 
 
Post #: 50
 
 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

(in reply to ebgreen)
 
 
Post #: 51
 
 RE: Backup Script-copy - 1/19/2007 4:03:00 PM   
  netman06

 

Posts: 99
Score: 0
Joined: 10/19/2006
Status: offline
I fixed up this script and it can copy files with no permission problem, the main thing I would like you to look at is the copy line and path strings.

fso.CopyFile strFile, strShare, True

Const PATH = "C:\denbak1\"

strShare = "c:\denbak2\"

This is always where the script is show having a problem:

fso.CopyFile strFile, strShare, True

what does this do different then what you are doing? I seems to me that we are doing the same thing, I just don't understand why we get the permission problem with this fso.copyfile line. now I looked at the differenance between fso.CopyFile and fso.Copy, could this cause any isssues?


      

Thanks,

Miike

< Message edited by netman06 -- 1/20/2007 7:49:54 AM >

(in reply to netman06)
 
 
Post #: 52
 
 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

(in reply to netman06)
 
 
Post #: 53
 
 RE: Backup Script-copy - 1/22/2007 7:57:14 AM   
  netman06

 

Posts: 99
Score: 0
Joined: 10/19/2006
Status: offline
HI, EBGreen

ok, Can you look at your last code post and test it with the Date 1/19/2007 8:27:35 AM post directory information. To see if you are getting any error message.

Thanks,

Mike

(in reply to ebgreen)
 
 
Post #: 54
 
 
Page:  <<   < prev  1 2 [3]
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> RE: Backup Script-copy Page: <<   < prev  1 2 [3]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts