Access vba에서 고정 디렉터리로 이동하여 해당 디렉터리 (및 하위 디렉터리)의 모든 파일을 압축하고 zip 보관 파일을 (일반적으로) 새로운 아카이브 저장 용 디렉토리. 내 액세스 프런트 엔드 및 관련 파일의 백업 루틴입니다. 내 개인 자격 증명을 사용하여 매일 내 클라이언트 컴퓨터에서 실행했습니다. 이제는 더 강력하고 책임이 있기 때문에 작은 SQL Server 컴퓨터에서 실행하고 싶습니다. 나는 T-SQL에서 액세스 루틴을 "호출"하는 대신 모든 것을 수행하기를 원합니다.SQL Server 에이전트 작업에서 보관할 Zip 파일
나는 약간의 연구를했지만, 이것으로 나를 도울 결정적인 것을 찾을 수 없다. 누군가 나를 도와 줄 수 있습니까? 여기에 액세스 VBA 코드 :이 때문에 쉘에서
Function Zip_All_Files_in_Folder()
Dim FileNameZip, FolderName
Dim strDate As String, TargetPath As String
Dim oApp As Object
TargetPath = "H:\xxx\secure\Construction\Access\All Database Backup\" & Format(Date, "YYYY-MMM") & "_Backup\"
If Len(Dir(TargetPath)) = 0 Then
MkDir (TargetPath)
End If
FolderName = "H:\xxx\secure\Construction\Access\CPAS\"
strDate = Format(Date, "YY-MM-DD")
FileNameZip = TargetPath & strDate & ".zip"
'Create empty Zip File
NewZip (FileNameZip)
'Copy the files to the compressed folder
Set oApp = CreateObject("Shell.Application")
oApp.Namespace(FileNameZip).CopyHere oApp.Namespace(FolderName).items
'Keep script waiting until Compressing is done
On Error Resume Next
Dim time As Integer
Do Until (oApp.Namespace(FileNameZip).items.Count = _
oApp.Namespace(FolderName).items.Count) Or time > 180
Sleep (1000)
time = time + 1
Loop
On Error GoTo 0
'Send a message about the way the script ended
If time < 180 Then
SendEmail "[email protected]", "Looks like the zip backup worked." & vbCrLf & TargetPath
Else
SendEmail "[email protected]", "Better double check the Zip backup: " & time & " seconds" & vbCrLf & TargetPath
End If
DoCmd.Quit
End Function
Sub NewZip(sPath)
'Create empty Zip File
'Changed by keepITcool Dec-12-2005
If Len(Dir(sPath)) > 0 Then Kill sPath
Open sPath For Output As #1
Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0)
Close #1
End Sub
SS2k5 전체, Office2007, MSServer2k8 –
그렇다면 SQL Server에서 예약 된 작업을 만들어 스크립트를 실행할 수 있으며 유지 관리 계획도 확인할 수 있습니다. 그러나 가장 간단한 솔루션은 여전히 독립형 스크립트입니다. – Pondlife