none
Fazer Backup e enviar automaticamente por Backup é possível? RRS feed

  • Pergunta

  • Pessoal sou novo em fazer Scripts Windows...

    Já consegui alguns materiais na net sobre isso e quero começar a estudar, mas um recurso que para mim é muito importante, e preciso ter a certeza que é possível fazer é o seguinte:

    é possível por script fazer um backup do meu servidor windows server 2003 R2 SP2, e depois de o backup pronto ele enviar para um servidor de FTP colocando Login e Senha e fazendo o Upload do mesmo? é complicado?


    quarta-feira, 11 de julho de 2007 11:32

Respostas

  • A parte de  fazer e monitorar o backup vc acha pronto aki no forum.
    Com este vc conegue,l porem pelo que li ele precisa de um activeX
    http://www.chilkatsoft.com/download/FtpActiveX.msi
    veja saite:
    http://www.robvanderwoude.com/vbstech_internet_ftp.html



    Option Explicit

    ' Upload the file "test.txt" from the current (local) directory to
    ' "ftp.myServer.myTld/www/testdir/test.txt"; create the directory
    ' "testdir" if it doesn't exist; login as "myid" with password "secret".
    WScript.Echo FTPUpload( "test.txt", "/www/testdir", _
    "ftp.myServer.myTld", _
    "myid", "secret", True )


    Function FTPUpload( locFile, targetDir, host, user, password, blnMkDir )
    ' This function uses the free ChilkatFTP ActiveX component
    ' to upload a single file.
    ' The remote directory can be specified, but the remote
    ' file name will be the same as the local file name.
    ' The function is based on Chilkat's own sample for the ChilkatFTP2 component
    ' (which is not free): http://www.example-code.com/vbscript/ftpPutFile.asp
    '
    ' Arguments:
    ' locFile [string] the (path and) file name of the file to be uploaded
    ' targetDir [string] the (relative) path of the remote target directory;
    ' if empty, the current remote directory will be used
    ' host [string] the remote host name (e.g. "ftp.mydomain.org")
    ' user [string] the login name for the remote host
    ' password [string] the password for the login account
    ' blnMkDir [boolean] if True, the remote directory will be created if it
    ' doesn't exist, otherwise the function will fail if
    ' the remote directory doesn't exist
    '
    ' The ChilkatFTP ActiveX component can be downloaded from:
    ' http://www.chilkatsoft.com/download/FtpActiveX.msi
    ' Documentation can be found at:
    ' http://www.chilkatsoft.com/refdoc/xChilkatFtpRef.html
    '
    ' Written by Rob van der Woude
    ' http://www.robvanderwoude.com

    ' Standard housekeeping
    Dim objFSO, objFTP, ok, strRemFile

    ' Extract the local file name and extension only from its path
    Set objFSO = CreateObject( "Scripting.FileSystemObject" )
    With objFSO
    strRemFile = .BuildPath( targetDir, .GetFileName( locFile ) )
    End With
    Set objFSO = Nothing

    ' Create a ChilkatFTP object
    Set objFTP = CreateObject( "ChilkatFTP.ChilkatFTP.1" )

    ' pass the connection properties to the object
    objFTP.Username = user
    objFTP.Password = password
    objFTP.Hostname = host

    ' Connect, abort and return error message on failure
    ok = objFTP.Connect( )
    If ( ok <> 1 ) Then
    FTPUpload = objFTP.LastErrorText
    Set objFTP = Nothing
    Exit Function
    End If

    If targeDir <> "" Then
    ' If specified, create target directory
    If blnMkDir = True Then
    objFTP.CreateRemoteDir targetDir
    End If
    ' Change directory remotely, abort and return error message on failure
    ok = objFTP.ChangeRemoteDir( targetDir )
    If ( ok <> 1 ) Then
    FTPUpload = objFTP.LastErrorText
    objFTP.Disconnect()
    Set objFTP = Nothing
    Exit Function
    End If
    End If

    ' Upload the file, abort and return error message on failure
    ok = objFTP.PutFile( locFile, strRemFile )
    If ( ok <> 1 ) Then
    FTPUpload = objFTP.LastErrorText
    End If

    ' Disconnect,and release the object
    objFTP.Disconnect( )
    Set objFTP = Nothing

    ' Return result
    FTPUpload = "Upload succeeded"
    End Function
    quarta-feira, 11 de julho de 2007 22:17
  • Mais um
    A parte de  fazer e monitorar o backup vc acha pronto aki no forum.
    Basta ler as instruções no próprio script.

    Option Explicit : Dim BaseDir, FTPaddr, UserName, Password, arASCII, ShowSuccess

    'vbsFTP.vbs - FTP upload tool using DOS FTP (DOS window suppressed).
    '© Bill James - bill@billsway.com - rev 20 Oct 2000

    'Requirements:
    ' Windows Script Host 2.0 or higher.
    ' FTP.exe in the local path (should already be present).
    ' Local folder structure must match the directory structure of your web site.

    'Implementation:
    ' 1) Edit the User Variables section below for your specific criteria.
    ' 2) Place a shortcut to this script in the SendTo folder.

    'Usage:
    ' Right click a file or files in your local web directory, click SendTo,
    ' then select the vbsFTP shortcut. Optional: Drag-and-Drop to script.

    ' * * * * * * * * * * * * * * User Variables * * * * * * * * * * * * * *
    ' FTP address for the root of your web site:
    ' Example: "ftp.myISP.com" (check ISP help page for details) *
    FTPaddr = "ftp.foo.com"
    ' Local folder that equates to the root of your web site: *
    BaseDir = "C:\inetpub\wwwroot"
    ' FTP username for your site: *
    UserName = "username"
    ' FTP password for your site: *
    Password = "password"
    ' ---ADVANCED Setup Options--- *
    ' (If you don't know what ascii upload means, leave this alone!)
    ' Files to be uploaded in ASCII format: *
    arASCII = Array("txt", "cgi", "pl", "htm", "html", "asp", "js", "vbs")
    ' Suppress Popup if upload succeeded (True or False, no quotes): *
    ShowSuccess = False
    ' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

    Dim Title, args, fso, f, ck, ws, InFile, ftp, OutFile
    Dim arOutLines, IconType, MsgTimer, Sent, errFTP

    Title = "vbsFTP © Bill James"
    Set args = WScript.Arguments
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ws = CreateObject("WScript.Shell")
    InFile = fso.GetSpecialFolder(2) & "\" & fso.GetTempName
    Set ftp = fso.OpenTextFile(InFile, 2, True)
    OutFile = fso.GetSpecialFolder(2) & "\" & fso.GetTempName
    arOutlines = Array()

    SanityCheck() 'Check input parameters OK

    WriteScript() 'Write the FTP script

    'Upload the files
    ws.Run "%comspec% /c ftp -i -s:" & InFile & " >" & OutFile, 0, True

    GetResults() ' Results of transfer

    ' Report failure or success
    If ShowSuccess Then
    ws.Popup Join(arOutLines, vbcrlf), MsgTimer, Title, IconType
    Else
    If errFTP Then
    ws.Popup Join(arOutLines, vbcrlf), MsgTimer, Title, IconType
    End If
    End If

    Cleanup() 'Release objects and exit

    '---------Subs----------

    Sub SanityCheck()
    'Script can not run if called directly with no parameters
    If args.Count < 1 Then
    ws.Popup "Use Drag-and-Drop or SendTo only.", , Title, 48
    Cleanup()
    End If

    'Check that file argument is in the local base directory
    If Left(args(0), Len(BaseDir)) <> BaseDir Then
    ws.Popup "Files to upload must be in " & BaseDir & " folder or sub folder.", , Title, 48
    Cleanup()
    End If

    'Check if a folder was sent to script
    On Error Resume Next
    Err.Clear
    For f = 0 To args.Count -1
    Set ck = fso.GetFile(args(f))
    If Err Then
    ws.Popup "Folders can not be uploaded.", , Title, 48
    Cleanup()
    End If
    Next
    On Error GoTo 0
    End Sub

    Sub WriteScript()
    Dim RelPath, i, Trans
    'Create variable to enable changing to the same Web directory
    RelPath = fso.GetParentFolderName(args(0))
    If RelPath <> BaseDir Then
    RelPath = Right(RelPath, Len(RelPath) - Len(BaseDir) - 1)
    Else
    RelPath = ""
    End If
    With ftp
    .WriteLine "open " & FTPaddr
    .WriteLine UserName
    .WriteLine Password
    .WriteLine "bell"
    If RelPath <> "" Then .WriteLine "cd " & chr(34) & RelPath & chr(34)
    For f = 0 To args.Count -1
    Sent = False
    'Determine if ascii or binary transmission to be used
    For Each i in arASCII
    If LCase(i) = LCase(fso.GetExtensionName(args(f))) Then
    If Trans <> "ascii" Then
    Trans = "ascii"
    .WriteLine Trans
    End If
    Sent = True
    End If
    Next
    If Not Sent Then
    If Trans <> "binary" Then
    Trans = "binary"
    .WriteLine Trans
    End If
    End If
    .WriteLine "put " & chr(34) & args(f) & chr(34)
    Next
    .WriteLine "close"
    .WriteLine "bye"
    .Close
    End With
    End Sub

    Sub GetResults()
    Dim i, OutPut, ThisLine
    errFTP = False
    IconType = 64
    MsgTimer = 3
    ReDim Preserve arOutLines(0)
    arOutLines(0) = Title & vbcrlf & vbcrlf & "ERROR DURING UPLOAD: " & vbcrlf
    i = 0
    Set OutPut = fso.OpenTextFile(OutFile, 1)
    Do While Not OutPut.AtEndOfStream
    ThisLine = OutPut.ReadLine
    'FTP error codes are 4xx or 5xx
    If CStr(Left(ThisLine, 1)) = CStr(4) Or CStr(Left(ThisLine, 1)) = CStr(5) Then
    i = i + 1
    ReDim Preserve arOutLines(i)
    arOutLines(i) = ThisLine
    errFTP = True
    IconType = 48 + 4096
    MsgTimer = 0
    End If
    Loop
    OutPut.Close
    If errFTP Then
    i = i + 1
    ReDim Preserve arOutLines(i)
    arOutLines(i) = "File(s) not uploaded:" & vbcrlf
    Else
    ReDim Preserve arOutLines(0)
    arOutLines(0) = Title & vbcrlf & vbcrlf & _
    "File(s) uploaded successfully:" & vbcrlf
    End If
    For f = 0 To args.Count -1
    i = i + 1
    ReDim Preserve arOutLines(i)
    arOutLines(i) = args(f) & Space(15)
    Next
    End Sub

    Sub Cleanup()
    On Error Resume Next
    fso.DeleteFile InFile, True
    fso.DeleteFile OutFile, True
    Set args = Nothing
    Set fso = Nothing
    Set ws = Nothing
    Set ftp = Nothing
    Erase arOutlines
    Erase arASCII
    WScript.Quit
    End Sub

    quarta-feira, 11 de julho de 2007 22:27

Todas as Respostas

  • A parte de  fazer e monitorar o backup vc acha pronto aki no forum.
    Com este vc conegue,l porem pelo que li ele precisa de um activeX
    http://www.chilkatsoft.com/download/FtpActiveX.msi
    veja saite:
    http://www.robvanderwoude.com/vbstech_internet_ftp.html



    Option Explicit

    ' Upload the file "test.txt" from the current (local) directory to
    ' "ftp.myServer.myTld/www/testdir/test.txt"; create the directory
    ' "testdir" if it doesn't exist; login as "myid" with password "secret".
    WScript.Echo FTPUpload( "test.txt", "/www/testdir", _
    "ftp.myServer.myTld", _
    "myid", "secret", True )


    Function FTPUpload( locFile, targetDir, host, user, password, blnMkDir )
    ' This function uses the free ChilkatFTP ActiveX component
    ' to upload a single file.
    ' The remote directory can be specified, but the remote
    ' file name will be the same as the local file name.
    ' The function is based on Chilkat's own sample for the ChilkatFTP2 component
    ' (which is not free): http://www.example-code.com/vbscript/ftpPutFile.asp
    '
    ' Arguments:
    ' locFile [string] the (path and) file name of the file to be uploaded
    ' targetDir [string] the (relative) path of the remote target directory;
    ' if empty, the current remote directory will be used
    ' host [string] the remote host name (e.g. "ftp.mydomain.org")
    ' user [string] the login name for the remote host
    ' password [string] the password for the login account
    ' blnMkDir [boolean] if True, the remote directory will be created if it
    ' doesn't exist, otherwise the function will fail if
    ' the remote directory doesn't exist
    '
    ' The ChilkatFTP ActiveX component can be downloaded from:
    ' http://www.chilkatsoft.com/download/FtpActiveX.msi
    ' Documentation can be found at:
    ' http://www.chilkatsoft.com/refdoc/xChilkatFtpRef.html
    '
    ' Written by Rob van der Woude
    ' http://www.robvanderwoude.com

    ' Standard housekeeping
    Dim objFSO, objFTP, ok, strRemFile

    ' Extract the local file name and extension only from its path
    Set objFSO = CreateObject( "Scripting.FileSystemObject" )
    With objFSO
    strRemFile = .BuildPath( targetDir, .GetFileName( locFile ) )
    End With
    Set objFSO = Nothing

    ' Create a ChilkatFTP object
    Set objFTP = CreateObject( "ChilkatFTP.ChilkatFTP.1" )

    ' pass the connection properties to the object
    objFTP.Username = user
    objFTP.Password = password
    objFTP.Hostname = host

    ' Connect, abort and return error message on failure
    ok = objFTP.Connect( )
    If ( ok <> 1 ) Then
    FTPUpload = objFTP.LastErrorText
    Set objFTP = Nothing
    Exit Function
    End If

    If targeDir <> "" Then
    ' If specified, create target directory
    If blnMkDir = True Then
    objFTP.CreateRemoteDir targetDir
    End If
    ' Change directory remotely, abort and return error message on failure
    ok = objFTP.ChangeRemoteDir( targetDir )
    If ( ok <> 1 ) Then
    FTPUpload = objFTP.LastErrorText
    objFTP.Disconnect()
    Set objFTP = Nothing
    Exit Function
    End If
    End If

    ' Upload the file, abort and return error message on failure
    ok = objFTP.PutFile( locFile, strRemFile )
    If ( ok <> 1 ) Then
    FTPUpload = objFTP.LastErrorText
    End If

    ' Disconnect,and release the object
    objFTP.Disconnect( )
    Set objFTP = Nothing

    ' Return result
    FTPUpload = "Upload succeeded"
    End Function
    quarta-feira, 11 de julho de 2007 22:17
  • Mais um
    A parte de  fazer e monitorar o backup vc acha pronto aki no forum.
    Basta ler as instruções no próprio script.

    Option Explicit : Dim BaseDir, FTPaddr, UserName, Password, arASCII, ShowSuccess

    'vbsFTP.vbs - FTP upload tool using DOS FTP (DOS window suppressed).
    '© Bill James - bill@billsway.com - rev 20 Oct 2000

    'Requirements:
    ' Windows Script Host 2.0 or higher.
    ' FTP.exe in the local path (should already be present).
    ' Local folder structure must match the directory structure of your web site.

    'Implementation:
    ' 1) Edit the User Variables section below for your specific criteria.
    ' 2) Place a shortcut to this script in the SendTo folder.

    'Usage:
    ' Right click a file or files in your local web directory, click SendTo,
    ' then select the vbsFTP shortcut. Optional: Drag-and-Drop to script.

    ' * * * * * * * * * * * * * * User Variables * * * * * * * * * * * * * *
    ' FTP address for the root of your web site:
    ' Example: "ftp.myISP.com" (check ISP help page for details) *
    FTPaddr = "ftp.foo.com"
    ' Local folder that equates to the root of your web site: *
    BaseDir = "C:\inetpub\wwwroot"
    ' FTP username for your site: *
    UserName = "username"
    ' FTP password for your site: *
    Password = "password"
    ' ---ADVANCED Setup Options--- *
    ' (If you don't know what ascii upload means, leave this alone!)
    ' Files to be uploaded in ASCII format: *
    arASCII = Array("txt", "cgi", "pl", "htm", "html", "asp", "js", "vbs")
    ' Suppress Popup if upload succeeded (True or False, no quotes): *
    ShowSuccess = False
    ' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

    Dim Title, args, fso, f, ck, ws, InFile, ftp, OutFile
    Dim arOutLines, IconType, MsgTimer, Sent, errFTP

    Title = "vbsFTP © Bill James"
    Set args = WScript.Arguments
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ws = CreateObject("WScript.Shell")
    InFile = fso.GetSpecialFolder(2) & "\" & fso.GetTempName
    Set ftp = fso.OpenTextFile(InFile, 2, True)
    OutFile = fso.GetSpecialFolder(2) & "\" & fso.GetTempName
    arOutlines = Array()

    SanityCheck() 'Check input parameters OK

    WriteScript() 'Write the FTP script

    'Upload the files
    ws.Run "%comspec% /c ftp -i -s:" & InFile & " >" & OutFile, 0, True

    GetResults() ' Results of transfer

    ' Report failure or success
    If ShowSuccess Then
    ws.Popup Join(arOutLines, vbcrlf), MsgTimer, Title, IconType
    Else
    If errFTP Then
    ws.Popup Join(arOutLines, vbcrlf), MsgTimer, Title, IconType
    End If
    End If

    Cleanup() 'Release objects and exit

    '---------Subs----------

    Sub SanityCheck()
    'Script can not run if called directly with no parameters
    If args.Count < 1 Then
    ws.Popup "Use Drag-and-Drop or SendTo only.", , Title, 48
    Cleanup()
    End If

    'Check that file argument is in the local base directory
    If Left(args(0), Len(BaseDir)) <> BaseDir Then
    ws.Popup "Files to upload must be in " & BaseDir & " folder or sub folder.", , Title, 48
    Cleanup()
    End If

    'Check if a folder was sent to script
    On Error Resume Next
    Err.Clear
    For f = 0 To args.Count -1
    Set ck = fso.GetFile(args(f))
    If Err Then
    ws.Popup "Folders can not be uploaded.", , Title, 48
    Cleanup()
    End If
    Next
    On Error GoTo 0
    End Sub

    Sub WriteScript()
    Dim RelPath, i, Trans
    'Create variable to enable changing to the same Web directory
    RelPath = fso.GetParentFolderName(args(0))
    If RelPath <> BaseDir Then
    RelPath = Right(RelPath, Len(RelPath) - Len(BaseDir) - 1)
    Else
    RelPath = ""
    End If
    With ftp
    .WriteLine "open " & FTPaddr
    .WriteLine UserName
    .WriteLine Password
    .WriteLine "bell"
    If RelPath <> "" Then .WriteLine "cd " & chr(34) & RelPath & chr(34)
    For f = 0 To args.Count -1
    Sent = False
    'Determine if ascii or binary transmission to be used
    For Each i in arASCII
    If LCase(i) = LCase(fso.GetExtensionName(args(f))) Then
    If Trans <> "ascii" Then
    Trans = "ascii"
    .WriteLine Trans
    End If
    Sent = True
    End If
    Next
    If Not Sent Then
    If Trans <> "binary" Then
    Trans = "binary"
    .WriteLine Trans
    End If
    End If
    .WriteLine "put " & chr(34) & args(f) & chr(34)
    Next
    .WriteLine "close"
    .WriteLine "bye"
    .Close
    End With
    End Sub

    Sub GetResults()
    Dim i, OutPut, ThisLine
    errFTP = False
    IconType = 64
    MsgTimer = 3
    ReDim Preserve arOutLines(0)
    arOutLines(0) = Title & vbcrlf & vbcrlf & "ERROR DURING UPLOAD: " & vbcrlf
    i = 0
    Set OutPut = fso.OpenTextFile(OutFile, 1)
    Do While Not OutPut.AtEndOfStream
    ThisLine = OutPut.ReadLine
    'FTP error codes are 4xx or 5xx
    If CStr(Left(ThisLine, 1)) = CStr(4) Or CStr(Left(ThisLine, 1)) = CStr(5) Then
    i = i + 1
    ReDim Preserve arOutLines(i)
    arOutLines(i) = ThisLine
    errFTP = True
    IconType = 48 + 4096
    MsgTimer = 0
    End If
    Loop
    OutPut.Close
    If errFTP Then
    i = i + 1
    ReDim Preserve arOutLines(i)
    arOutLines(i) = "File(s) not uploaded:" & vbcrlf
    Else
    ReDim Preserve arOutLines(0)
    arOutLines(0) = Title & vbcrlf & vbcrlf & _
    "File(s) uploaded successfully:" & vbcrlf
    End If
    For f = 0 To args.Count -1
    i = i + 1
    ReDim Preserve arOutLines(i)
    arOutLines(i) = args(f) & Space(15)
    Next
    End Sub

    Sub Cleanup()
    On Error Resume Next
    fso.DeleteFile InFile, True
    fso.DeleteFile OutFile, True
    Set args = Nothing
    Set fso = Nothing
    Set ws = Nothing
    Set ftp = Nothing
    Erase arOutlines
    Erase arASCII
    WScript.Quit
    End Sub

    quarta-feira, 11 de julho de 2007 22:27
  • Opa Valeu Romeu!!!

    Eu até tinha procurado antes no fórum, mas acredito que tenha procurado com as palavras erradas, pois, realmente não tinha encontrado esses scripts...

    Post Marcado como resposta : )
    os dois.... rs

    Mais uma vez obrigado pela ajuda
    quinta-feira, 12 de julho de 2007 11:11
  • esquenta não cara...quando dá para ajudar a gente ajuda.
    quinta-feira, 12 de julho de 2007 19:12