Wie verarbeitet Robocopy Dateisystemlinks (symbolische Links, Hardlinks und Junctions)?

Wie verarbeitet Robocopy Dateisystemlinks (symbolische Links, Hardlinks und Junctions)?

Ist es sicher, ein Robocopy-Backup zu löschen? Ich habe gelesen, dass einige Leute versehentlich Dateien außerhalb des Backups gelöscht haben, weil diese Links/Verbindungen enthielten. Kann ich das verhindern?

Antwort1

DerRobocopy-Dokumentelistet Optionen auf, die das Verhalten von Robocopy in Bezug auf Dateisystemlinks steuern:

/sl Symbolischen Links nicht folgen, sondern eine Kopie des Links erstellen.
/xj Schließt Verknüpfungspunkte aus, die normalerweise standardmäßig eingeschlossen werden.
/xjd Schließt Verknüpfungspunkte für Verzeichnisse aus.
/xjf Schließt Verknüpfungspunkte für Dateien aus.

Ich habe ein Batch-Skript erstellt, um herauszufinden, wie Robocopy mit und ohne diese Optionen funktioniert. Es verwendetmlinkMit mlinkkönnen Sie Folgendes erstellen:

  • Symbolische Links zu Dateien und Verzeichnissen.
  • Harte Links zu Dateien. Der Versuch, einen harten Link zu einem Verzeichnis zu erstellen, führt zu einem Fehler.
  • Junctions, also Links zu Verzeichnissen. Der Versuch, eine Junction zu einer Datei zu erstellen, ist zwar erfolgreich, aber die Junction wird unterbrochen.

Symbolische Links können relativ oder absolut sein, je nachdem, wie Sie den Zielparameter übergeben. Hardlinks und Junctions sind immer absolut, auch wenn Sie ein relatives Ziel übergeben.

@echo off
set home=C:\my-directory
cd %home%
mkdir robocopy-source
cd robocopy-source
mkdir a
mkdir b
copy NUL b\foo.txt
cd a
mklink /j junction-dir-absolute %home%\robocopy-source\b\
mklink /d symlink-dir-absolute %home%\robocopy-source\b\
mklink /d symlink-dir-relative ..\b\
mklink /h hardlink-file-absolute %home%\robocopy-source\b\foo.txt
mklink symlink-file-absolute %home%\robocopy-source\b\foo.txt
mklink symlink-file-relative ..\b\foo.txt
cd %home%
robocopy robocopy-source robocopy-target /mir /dcopy:dat
robocopy robocopy-source robocopy-target-sl /mir /dcopy:dat /sl
robocopy robocopy-source robocopy-target-xj /mir /dcopy:dat /xj
robocopy robocopy-source robocopy-target-xjd /mir /dcopy:dat /xjd
robocopy robocopy-source robocopy-target-xjf /mir /dcopy:dat /xjf

Verwendung derLink Shell-Erweiterungkönnen wir jetzt sehen, was passiert ist:

Weg Die Info
robocopy-source\a\junction-dir-absolute Links zu %home%\robocopy-source\b\
robocopy-source\a\symlink-dir-absolute Links zu %home%\robocopy-source\b\
robocopy-source\a\symlink-dir-relative Links zu ..\b\
robocopy-source\a\hardlink-file-absolute Links zu %home%\robocopy-source\b\foo.txt (und sich selbst)
robocopy-source\a\symlink-file-absolute Links zu C:\Benutzer\Marco\Desktop\Linktest\robocopy-source\b\foo.txt
robocopy-source\a\symlink-datei-relativ Links zu ..\b\foo.txt
robocopy-target\a\junction-dir-absolute Verzeichnis mit kopiertem Inhalt von %home%\robocopy-source\b\
robocopy-target\a\symlink-dir-absolute Verzeichnis mit kopiertem Inhalt von %home%\robocopy-source\b\
robocopy-target\a\symlink-dir-relative Verzeichnis mit kopiertem Inhalt von %home%\robocopy-source\b\
robocopy-target\a\hardlink-file-absolute Leere Akte
robocopy-target\a\symlink-file-absolute Leere Akte
robocopy-target\a\symlink-datei-relativ Leere Akte
robocopy-target-sl\a\junction-dir-absolute Verzeichnis mit kopiertem Inhalt von %home%\robocopy-source\b\
robocopy-target-sl\a\symlink-dir-absolute Links zu %home%\robocopy-source\b\
robocopy-target-sl\a\symlink-dir-relative Link zu ..\b\
robocopy-target-sl\a\hardlink-file-absolute Leere Akte
robocopy-target-sl\a\symlink-file-absolute Links zu %home%\robocopy-source\b\foo.txt
robocopy-target-sl\a\symlink-datei-relativ Links zu ..\b\foo.txt
robocopy-target-xj\a\junction-dir-absolute Ist nicht vorhanden
robocopy-target-xj\a\symlink-dir-absolute Ist nicht vorhanden
robocopy-target-xj\a\symlink-dir-relative Ist nicht vorhanden
robocopy-target-xj\a\hardlink-file-absolute Leere Akte
robocopy-target-xj\a\symlink-file-absolute Ist nicht vorhanden
robocopy-target-xj\a\symlink-datei-relativ Ist nicht vorhanden
robocopy-target-xjd\a\junction-dir-absolute Ist nicht vorhanden
robocopy-target-xjd\a\symlink-dir-absolute Ist nicht vorhanden
robocopy-target-xjd\a\symlink-dir-relative Ist nicht vorhanden
robocopy-target-xjd\a\hardlink-file-absolute Leere Akte
robocopy-target-xjd\a\symlink-file-absolute Leere Akte
robocopy-target-xjd\a\symlink-datei-relativ Leere Akte
robocopy-target-xjf\a\junction-dir-absolute Verzeichnis mit kopiertem Inhalt von %home%\robocopy-source\b\
robocopy-target-xjf\a\symlink-dir-absolute Verzeichnis mit kopiertem Inhalt von %home%\robocopy-source\b\
robocopy-target-xjf\a\symlink-dir-relative Verzeichnis mit kopiertem Inhalt von %home%\robocopy-source\b\
robocopy-target-xjf\a\hardlink-file-absolute Leere Akte
robocopy-target-xjf\a\symlink-file-absolute Ist nicht vorhanden
robocopy-target-xjf\a\symlink-datei-relativ Ist nicht vorhanden

Ich komme zu dem Schluss, dass /sldas Löschen eines mit Robocopy erstellten Backups sicher sein sollte, sofern Sie die Option nicht verwendet haben. Wenn Sie die /slOption jedoch verwendet haben, könnten absolute symbolische Links zu Problemen führen, z. B.bei Verwendung des delBefehls.

Weitere Beobachtungen:

  • Ein Hardlink ergibt immer eine leere Datei.
  • Option /xjdüberspringt Links zu Verzeichnissen. Anders als in der Dokumentation angegeben, werden nicht nur Junctions, sondern auch symbolische Links übersprungen!
  • Option /xjfüberspringt Links zu Dateien. Anders als in der Dokumentation angegeben, werden keine Verknüpfungen für Dateien übersprungen (die es sowieso nicht gibt), aber symbolische Links!
  • Option /xjkombiniert /xjdund /xjf.

Ich habe gemeldet,Problem mit den Dokumenten.

Bonusinformationen zu Verknüpfungen (.lnk-Dateien)

Verknüpfungen werden von Robocopy wie normale Dateien behandelt, sieWillezeigen im Allgemeinen außerhalb Ihres Sicherungsverzeichnisses. Sie werden jedoch normalerweise auch von anderen Befehlszeilenprogrammen wie normale Dateien behandelt. Ich habe dies für del /s /qund rmdir /s /qin der Eingabeaufforderung und rm -rfin der MINGW64-Shell überprüft. Alle diese Programme folgen den Verknüpfungen nicht und führen daher nicht zu unbeabsichtigten Löschungen.

verwandte Informationen