VBS/NTBACKUP + ローテーション
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
#navi(../)
'#######################################################...
'未テスト
'
'
'#######################################################...
Option Explicit
'実運用時はコメントアウトのこと
On Error Resume Next
Dim WshNetwork
Dim strDate, strBackup, strPath, strOldestFile
Dim strYear, strMonth, strDay, strTargetDate
Dim index, FileList
Dim objShell, objFile, objWMIService
Dim dtmDate
Set objShell = Wscript.CreateObject("WScript.Shell")
Set WshNetwork = Wscript.CreateObject("WScript.Network")
'Z:ドライブが使用されていれば切断
RemoveNetworkDrive()
'ネットワークドライブの接続
WshNetwork.MapNetworkDrive "Z:", "file://127.0.0.1/work"...
'バックアップ実行コマンドの作成
strBackup = "C:\WINDOWS\system32\ntbackup.exe backup ""@...
'本日の日付でファイル名を作成
dtmDate = Date
GetDate (dtmDate)
'最後の"を取り除き、日付_full.bkfというファイル名を指定
index = Len(strBackup) - 1
strPath = Left(strBackup, index) & strTargetDate & "_ful...
'コマンドの実行
objShell.Run (strPath)
'???????????????????????
'古いファイルの削除
'???????????????????????
'本日から何日以前のファイルを対象にするか指定
dtmDate = Date - 13
'指定条件でファイル名を生成
GetDate (dtmDate)
'
Set objWMIService = GetObject("winmgmts:\\" & "127.0.0.1...
Set FileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='C:\work\Upload...
& "ResultClass = CIM_DataFile")
For Each objFile In FileList
strDate = Left(objFile.LastModified,
Wscript.echo strDate
If strDate < strTargetDate Then
'If objFile.Extension = “_full.bkf” Then
'objFile.Delete
'End If
End If
Next
'ネットワークドライブの切断
RemoveNetworkDrive()
'終了処理
Set WshNetwork = Nothing
Set objShell = Nothing
'ここまで
'???????????????????????
'ネットワークドライブの切断
Private Function RemoveNetworkDrive()
On Error Resume Next
WshNetwork.RemoveNetworkDrive "Z:", False, True
End Function
'???????????????????????
'ファイル名、Date整形
Function GetDate(dtmDate)
strDay = Day(dtmDate)
If Len(strDay) < 2 Then
strDay = "0″ & strDay"
End If
strMonth = Month(dtmDate)
If Len(strMonth) < 2 Then
strMonth = "0″ & strMonth"
End If
strYear = Year(dtmDate)
strTargetDate = strYear & strMonth & strDay
End Function
'???????????????????????
#navi(../)
終了行:
#navi(../)
'#######################################################...
'未テスト
'
'
'#######################################################...
Option Explicit
'実運用時はコメントアウトのこと
On Error Resume Next
Dim WshNetwork
Dim strDate, strBackup, strPath, strOldestFile
Dim strYear, strMonth, strDay, strTargetDate
Dim index, FileList
Dim objShell, objFile, objWMIService
Dim dtmDate
Set objShell = Wscript.CreateObject("WScript.Shell")
Set WshNetwork = Wscript.CreateObject("WScript.Network")
'Z:ドライブが使用されていれば切断
RemoveNetworkDrive()
'ネットワークドライブの接続
WshNetwork.MapNetworkDrive "Z:", "file://127.0.0.1/work"...
'バックアップ実行コマンドの作成
strBackup = "C:\WINDOWS\system32\ntbackup.exe backup ""@...
'本日の日付でファイル名を作成
dtmDate = Date
GetDate (dtmDate)
'最後の"を取り除き、日付_full.bkfというファイル名を指定
index = Len(strBackup) - 1
strPath = Left(strBackup, index) & strTargetDate & "_ful...
'コマンドの実行
objShell.Run (strPath)
'???????????????????????
'古いファイルの削除
'???????????????????????
'本日から何日以前のファイルを対象にするか指定
dtmDate = Date - 13
'指定条件でファイル名を生成
GetDate (dtmDate)
'
Set objWMIService = GetObject("winmgmts:\\" & "127.0.0.1...
Set FileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='C:\work\Upload...
& "ResultClass = CIM_DataFile")
For Each objFile In FileList
strDate = Left(objFile.LastModified,
Wscript.echo strDate
If strDate < strTargetDate Then
'If objFile.Extension = “_full.bkf” Then
'objFile.Delete
'End If
End If
Next
'ネットワークドライブの切断
RemoveNetworkDrive()
'終了処理
Set WshNetwork = Nothing
Set objShell = Nothing
'ここまで
'???????????????????????
'ネットワークドライブの切断
Private Function RemoveNetworkDrive()
On Error Resume Next
WshNetwork.RemoveNetworkDrive "Z:", False, True
End Function
'???????????????????????
'ファイル名、Date整形
Function GetDate(dtmDate)
strDay = Day(dtmDate)
If Len(strDay) < 2 Then
strDay = "0″ & strDay"
End If
strMonth = Month(dtmDate)
If Len(strMonth) < 2 Then
strMonth = "0″ & strMonth"
End If
strYear = Year(dtmDate)
strTargetDate = strYear & strMonth & strDay
End Function
'???????????????????????
#navi(../)
ページ名: