Backup einer Partition

gigalogisch

Mitglied
Hallo Leute,

ich muss ehrlich gestehen, dass ich "eigentlich" von VBScript keine Ahnung hab. Ich komme von PHP :) - darum kann ich ein paar Dinge nachvollziehen.
Ich bin also am "zusammenkopieren" verschiedener Codeschnippsel. Und im Endeffekt möchte ich erreichen, dass mir das VB-Script meine komplette Partition D auf eine externe Festplatte, Laufwerkbuchstabe M kopiert. Vorher soll der Backup-Ordner gelöscht werden, damit eine z. B. umbenannte Datei 2x auftaucht.

So wie ich das bis jetzt habe, kann ich leider nur einzelne Ordner kopieren. Natürlich könnte ich jetzt für jeden einzelnen Ordner ein einzelnes Script schreiben, aber was mach ich wenn ein neuer dazukommt. Ich denke, ihr wisst was ich meine :rolleyes:

Code:
Set DateiSystem = CreateObject("Scripting.FileSystemObject")
backup_ziel = "M:\Daten (D)"
backup_quelle = "D:\Word"
set fs = createObject("Scripting.filesystemobject")
fs.deletefolder backup_ziel
If Not DateiSystem.FolderExists(backup_ziel) Then
DateiSystem.CreateFolder backup_ziel
End If
Set Ordner = DateiSystem.GetFolder(backup_quelle)
Ordner.Copy backup_ziel, true
MsgBox "Das Backup wurde erfolgreich durchgeführt!",,"Backup Erfolg"

Ich hab für die Variable backup_quelle auch schon "D", "D:" und "D:\" probiert, funktioniert aber leider nicht.

Vielen Dank

Willi
 
Probier mal CopyFolder
Code:
Recursively copies a folder from one location to another.

object.CopyFolder ( source, destination[, overwrite] );
Arguments
object 
Required. Always the name of a FileSystemObject. 
source 
Required. Character string folder specification, which can include wildcard characters, for one or more folders to be copied. 
destination 
Required. Character string destination where the folder and subfolders from source are to be copied. Wildcard characters are not allowed. 
overwrite 
Optional. Boolean value that indicates if existing folders are to be overwritten. If true, files are overwritten; if false, they are not. The default is true. 
Remarks
Wildcard characters can only be used in the last path component of the source argument. For example, you can use: 

[JScript]
fso = new ActiveXObject("Scripting.FileSystemObject");
fso.CopyFolder ("c:\\mydocuments\\letters\\*", "c:\\tempfolder\\")
[VBScript]
FileSystemObject.CopyFolder "c:\mydocuments\letters\*", "c:\tempfolder\"
But you cannot use: 

[JScript]
fso = new ActiveXObject("Scripting.FileSystemObject");
fso.CopyFolder ("c:\\mydocuments\\*\\*", "c:\\tempfolder\\")
[VBScript]
FileSystemObject.CopyFolder "c:\mydocuments\*\*", "c:\tempfolder\"
If source contains wildcard characters or destination ends with a path separator (\), it is assumed that destination is an existing folder in which to copy matching folders and subfolders. Otherwise, destination is assumed to be the name of a folder to create. In either case, four things can happen when an individual folder is copied. 

If destination does not exist, the source folder and all its contents gets copied. This is the usual case. 
If destination is an existing file, an error occurs. 
If destination is a directory, an attempt is made to copy the folder and all its contents. If a file contained in source already exists in destination, an error occurs if overwrite is false. Otherwise, it will attempt to copy the file over the existing file. 
If destination is a read-only directory, an error occurs if an attempt is made to copy an existing read-only file into that directory and overwrite is false. 
An error also occurs if a source using wildcard characters doesn't match any folders.

The CopyFolder method stops on the first error it encounters. No attempt is made to roll back any changes made before an error occurs.
 
Hallo Magge,

danke für die Antwort, ich weiß aber leider nicht, wie ich das jetzt einbinden soll.
Vielleicht so?

Code:
Set DateiSystem = CreateObject("Scripting.FileSystemObject")
backup_ziel = "M:\Daten (D)"
backup_quelle = "D:\Word"
set fs = createObject("Scripting.filesystemobject")
fs.deletefolder backup_ziel
If Not DateiSystem.FolderExists(backup_ziel) Then
DateiSystem.CreateFolder backup_ziel
End If
Set Ordner = DateiSystem.GetFolder(backup_quelle)
FileSystemObject.CopyFolder backup_quelle, backup_ziel
MsgBox "Das Backup wurde erfolgreich durchgeführt!",,"Backup Erfolg"

Funkt nur leider nicht :rolleyes:
Er sagt: Object erforderlich: FileSystemObject in Zeile 10

Hast du - oder auch andere - noch eine Idee, oder mache ich etwas falsch?

Danke

Willi
 
Die Fehlermeldung besagt das ein Objekt von Typ "FileSystemObject" benötigt wird.
Das hast du mit deiner Variable fs schon instanziiert.

Der Aufruf sollte dann also fs.CopyFolder .. lauten
 
Hallo,

danke - aber leider kann ich mit dieser Funktion auch nicht alle Ordner einer Partition kopieren :(
Hab es auch diesmal wieder mit "D", "D:" und "D:\" probiert, was aber nicht zum Erfolg führte.
Oder kann es sein, dass es gar nicht geht?

Code:
Set DateiSystem = CreateObject("Scripting.FileSystemObject")
backup_ziel = "M:\Daten (D)"
backup_quelle = "D:\"
set fs = createObject("Scripting.filesystemobject")
fs.deletefolder backup_ziel
If Not DateiSystem.FolderExists(backup_ziel) Then
DateiSystem.CreateFolder backup_ziel
End If
Set Ordner = DateiSystem.GetFolder(backup_quelle)
fs.CopyFolder backup_quelle, backup_ziel
MsgBox "Das Backup wurde erfolgreich durchgeführt!",,"Backup Erfolg"

Danke noch mal

Willi
 
Was kommt denn für ein Fehler? Eventuel must du die Pfadangabe in Anführungszeichen übergeben:
Code:
backup_ziel = """M:\Daten (D)"""
 
Laufzeitfehler in Zeile 10, Zeichen 1
Ungültiger Prozeduraufruf oder ungültiges Argument.

Wenn ich natürlich z. B. "D:\Word" angebe, alles einwandfrei... Er will mir nur nicht die gesamte Partition also "D:\" annehmen.

Danke
 
Also bei mir funktioniert es mit "D:\*" einwandfrei. Hab es aber in VB und nicht in VBS ausprobiert.
 
Zurück