2007-02-26, 04:07 PM | #1 |
注册日期: 2003-10-22
帖子: 11,053
积分:6
精华:24
现金:14348金币
资产:29325305金币
|
[vbs脚本]排除目录备份,并且上传到远程服务器!
代码:
const bak_dir = "e:\test_bak" const file_dir = "E:\test_rar" 'ftp login info const ftp_add = "ip" const ftp_user = "user" const ftp_pw = "password" const ftp_dir = "ftpdir" 'define del before days const del_before_days = "1" 'get format date my_day = day(now) my_month = Month(Now) my_year = year(now) my_date = my_year & "-" & my_month & "-" & my_day 'define bak file name bak_filename = my_date & "_" & "web_bak.rar" 'del old bak file Set FSO = CreateObject("Scripting.FileSystemObject") Set Folder = FSO.GetFolder(bak_dir) Set Files = Folder.Files If Files.Count <> 0 Then For Each File In Files If File.DateLastModified < Now - del_before_days Then '判断是否超过n天 'Wscript.Echo file FSO.DeleteFile file,true End If Next End If ' set exclude dir Set d = CreateObject("Scripting.Dictionary") d.Add "0", "E:\test_rar\新建文件夹 (2)\新建文件夹 (2)" '把目录路径添加到d这个数组中,0,1是数组的索引(index) d.add "1", "E:\test_rar\新建文件夹 (2)\rar" d.add "2", "e:\test_rar\set_exclude.vbs" For Each i in d exclude_dir = exclude_dir & " " & "-x" & chr(34) & d.Item(i) & chr(34) next 'wscript.echo "c:\program files\winrar\rar" & chr(34) & " a -r -o+ -m0 " & _ ' exclude_dir & " " & _ ' bak_dir & bak_filename & " " & file_dir 'exec bak action Set objShell = CreateObject("Wscript.Shell") objShell.Run chr(34) & "c:\program files\winrar\rar" & chr(34) & " a -r -o+ -m3 " & _ exclude_dir & " " & _ bak_dir & "\" & bak_filename & " " & file_dir, 0, True 'create ftp cmd file Set objFSO = CreateObject("Scripting.FileSystemObject") objName = objFSO.GetTempName objTempFile = objName Set objTextFile = objFSO.OpenTextFile(objTempFile, 2, 1) ' create ftp cmd file objTextFile.WriteLine "open " & ftp_add objTextFile.WriteLine "user " & ftp_user & " " & ftp_pw objTextFile.WriteLine "bin" objTextFile.WriteLine "cd " & ftp_dir objTextFile.WriteLine "lcd " & bak_dir objTextFile.WriteLine "put " & bak_filename objTextFile.WriteLine "bye" objTextFile.Close wscript.echo objTempFile ' exec ftp command objShell.Run "ftp -n -i -s:" & objTempFile , 0, True ' del temp ftp cmd file objFSO.DeleteFile(objTempFile) |
|