Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old December 28th, 2004, 01:21 PM
samcneal samcneal is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 75 samcneal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 26 m 2 sec
Reputation Power: 4
DTS - SQL Server

I am having a problem with my DTS package. I want to move old backup files that are 10 days old. However, it is not passing the file name. Prior to adding the date as a condition, it moved all the bak files within the folder to the other folder. Any suggestions/

' Move File
Option Explicit
Function Main()
Dim oFSO
Dim sSourceFile
Dim sDestinationFile
Dim oFile
Set oFSO = CreateObject("Scripting.FileSystemObject")
sSourceFile = "C:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\Data\*.bak"
sDestinationFile = "C:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\Oldbakfiles\"

Set oFile = oFSO.GetFile(sSourceFile)
If oFile.DateCreated < Date Then
oFSO.MoveFile sSourceFile, sDestinationFile
Else
Main = DTSTaskExecResult_Failure
End If

' Clean Up
Set oFSO = Nothing
Set oFile = Nothing

Main = DTSTaskExecResult_Success
End Function

Reply With Quote
  #2  
Old December 28th, 2004, 03:31 PM
lewy's Avatar
lewy lewy is offline
Alter Ego Wizard
ASP Free Specialist (4000 - 4499 posts)
 
Join Date: Jun 2004
Location: Edinburg Tx
Posts: 4,381 lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 1009 Folding Title: Novice Folder
Time spent in forums: 1 Month 1 Week 1 Day 23 h 7 m 43 sec
Reputation Power: 1488
I've never tried to Move files this way.
You may want to try and first grab all the files in the directory and then test for the date modified on a one by one basis then if the file meets the criteria, move it.
This is how I would do it:
Code:
 
	 Dim testdate
	 testdate = Date() 
	 path = Server.MapPath("/your back up path file/") 'rememer to replace this with the folder path to your backups
	 set fs = CreateObject("Scripting.FileSystemObject")
	 set folder = fs.GetFolder(path)
 
	 for each item in folder.Files
		 If item.DateLastModified < testdate
			response.write "<br>" & item.name & " Date Modified = " & item.DateLastModified
			'Move the file to its new directory
		 End if
	 next

This will give you the files in your directory that were last modified before today.
Moving the file should be straight forward from this point on.

Reply With Quote
  #3  
Old December 28th, 2004, 03:42 PM
samcneal samcneal is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 75 samcneal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 26 m 2 sec
Reputation Power: 4
DTS Package

Thanks for the feedback. I am getting an error in the server path. This is what I have:

Function Main()
Dim testdate
testdate = Date()
'sSourceFile = "C:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\Data\*.bak"
sDestinationFile = "C:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\Oldbakfiles\"
path = Server.MapPath("\\local\C:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\Data\*.bak") 'rememer to replace this with the folder path to your backups
set fs = CreateObject("Scripting.FileSystemObject")
set folder = fs.GetFolder(path)

for each item in folder.Files
If item.DateLastModified < testdate Then
response.write "<br>" & item.name & " Date Modified = " & item.DateLastModified
fs.MoveFile folder, sDestinationFile 'Move the file to its new directory
End if
next
Main = DTSTaskExecResult_Success
End Function

Reply With Quote
  #4  
Old December 28th, 2004, 03:50 PM
samcneal samcneal is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 75 samcneal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 26 m 2 sec
Reputation Power: 4
I actually modified the path to reflect what I should have. Now I am getting a response error. What exactly does that line suppose to do?

Quote:
Originally Posted by samcneal
I am having a problem with my DTS package. I want to move old backup files that are 10 days old. However, it is not passing the file name. Prior to adding the date as a condition, it moved all the bak files within the folder to the other folder. Any suggestions/

' Move File
Option Explicit
Function Main()
Dim oFSO
Dim sSourceFile
Dim sDestinationFile
Dim oFile
Set oFSO = CreateObject("Scripting.FileSystemObject")
sSourceFile = "C:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\Data\*.bak"
sDestinationFile = "C:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\Oldbakfiles\"

Set oFile = oFSO.GetFile(sSourceFile)
If oFile.DateCreated < Date Then
oFSO.MoveFile sSourceFile, sDestinationFile
Else
Main = DTSTaskExecResult_Failure
End If

' Clean Up
Set oFSO = Nothing
Set oFile = Nothing

Main = DTSTaskExecResult_Success
End Function

Reply With Quote
  #5  
Old December 28th, 2004, 04:03 PM
lewy's Avatar
lewy lewy is offline
Alter Ego Wizard
ASP Free Specialist (4000 - 4499 posts)
 
Join Date: Jun 2004
Location: Edinburg Tx
Posts: 4,381 lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 1009 Folding Title: Novice Folder
Time spent in forums: 1 Month 1 Week 1 Day 23 h 7 m 43 sec
Reputation Power: 1488
Server.MapPath only works, if you have your files residing in the wwwroot folder, when I tested this I used the wwwroot folder. Change this to something like "c:\test\your folderpath\"
This line response.write "<br>" & item.name & " Date Modified = " & item.DateLastModified simply writes out to the browser file names that match your criteria.

Test the code without it

And try it without a function call
Instead use:
Code:
 
Dim testdate
testdate = Date() 
 
sDestinationFile = "C:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\Oldbakfiles\"
path = "C:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\Data\") 
 
set fs = CreateObject("Scripting.FileSystemObject")
set folder = fs.GetFolder(path)
 
for each item in folder.Files
  If item.DateLastModified < testdate Then
	fs.MoveFile folder, sDestinationFile 'Move the file to its new directory
  End if
next

Reply With Quote
  #6  
Old December 28th, 2004, 04:46 PM
samcneal samcneal is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 75 samcneal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 26 m 2 sec
Reputation Power: 4
DTS script problem

This is what I was trying, with both codes, I'm either getting file does not exist or file already exists.

' Move File
Option Explicit
Function Main()
Dim Fso
Dim Folder
Dim F
Dim Destinationfile
Dim Date

Date = Now()
Destinationfile = "C:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\Oldbakfiles"
Set Fso = Createobject("Scripting.Filesystemobject")
Set Folder = Fso.Getfolder("C:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\DATA")
For Each F In Folder.Files
If F.Datecreated < Date Then
Fso.Movefile F, Destinationfile
End If
Next
Set Fso = Nothing
Set Folder = Nothing
Set F = Nothing

Main = Dtstaskexecresult_Success

End Function

Reply With Quote
  #7  
Old December 28th, 2004, 04:59 PM
lewy's Avatar
lewy lewy is offline
Alter Ego Wizard
ASP Free Specialist (4000 - 4499 posts)
 
Join Date: Jun 2004
Location: Edinburg Tx
Posts: 4,381 lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 1009 Folding Title: Novice Folder
Time spent in forums: 1 Month 1 Week 1 Day 23 h 7 m 43 sec
Reputation Power: 1488
Use this code, it should work.

Code:
<%@language=Vbscript %>
  
<% 
   
	  '*************************************************  ********************************
	  '******************** This portion of the asp script moves files in ****************************
	  '******************** older than today's date to a new directory   ***************************
	  '*************************************************  ********************************
	  Dim test
	  test = date()
	  path = "C:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\DATA"
	  sDestinationFile = "C:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\Oldbakfiles"
	  
	  set fs = CreateObject("Scripting.FileSystemObject")
	  set folder = fs.GetFolder(path)
	  
	  for each item in folder.Files
		 if item.DateLastModified < test Then			
			fs.MoveFile folder&"\"&item.Name, sDestinationFile&"\" 
		 End If
	 next
   
	
%>

Reply With Quote
  #8  
Old December 28th, 2004, 05:08 PM
samcneal samcneal is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 75 samcneal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 26 m 2 sec
Reputation Power: 4
Thanks that work. Would it be difficult to have it check if it is 10 days old than the date()? Should I add n days to the If stmt?

Reply With Quote
  #9  
Old December 28th, 2004, 05:18 PM
lewy's Avatar
lewy lewy is offline
Alter Ego Wizard
ASP Free Specialist (4000 - 4499 posts)
 
Join Date: Jun 2004
Location: Edinburg Tx
Posts: 4,381 lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 1009 Folding Title: Novice Folder
Time spent in forums: 1 Month 1 Week 1 Day 23 h 7 m 43 sec
Reputation Power: 1488
Just change the if then statement to
if (item.DateLastModified) > test-10 AND item.DateLastModified < test Then ....

This statement will give you what you are looking for.

Reply With Quote
  #10  
Old December 28th, 2004, 05:39 PM
samcneal samcneal is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 75 samcneal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 26 m 2 sec
Reputation Power: 4
Thanks. I truly appreciate your help. I have files dated back to 12/16 and the most current file was created 12/21. It moved the most current and left the older files. Andy ideas?

Reply With Quote
  #11  
Old December 28th, 2004, 05:42 PM
samcneal samcneal is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 75 samcneal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 26 m 2 sec
Reputation Power: 4
I think it should be datecreated instead of datelastmodified. I tried this to see if it made a difference and there was no change.

Reply With Quote
  #12  
Old December 28th, 2004, 07:26 PM
lewy's Avatar
lewy lewy is offline
Alter Ego Wizard
ASP Free Specialist (4000 - 4499 posts)
 
Join Date: Jun 2004
Location: Edinburg Tx
Posts: 4,381 lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 1009 Folding Title: Novice Folder
Time spent in forums: 1 Month 1 Week 1 Day 23 h 7 m 43 sec
Reputation Power: 1488
My bad, the if then statement should be
if (item.DateLastModified) < test-10 then ....
This should move files that are older than 12/18/2004

Reply With Quote
  #13  
Old December 29th, 2004, 10:33 AM
samcneal samcneal is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 75 samcneal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 26 m 2 sec
Reputation Power: 4
Thanks!!!! That was exactly what I needed. Can you suggest a good ActiveX book for beginners?

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > DTS - SQL Server


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread: