Deutsche Sprache auswählen Select english language

HardlinkBackup - Kompakte DatensicherungCompact data backup

ÜbersichtOverview

Zur regelmäßigen Sicherung eines Datenbestandes, bei dem sich nicht viele Dateien ändern reicht es aus, nur geänderte Dateien zu sichern. Soll ein Verzeichnis mit dem Stand eines bestimmten Tages wieder hergestellt werden tritt bei den üblichen inkrementellen oder differenziellen Verfahren häufig das Problem auf, dass der vollständige Inhalt aus mehreren Sicherungszeitpunkten gesammelt werden muss. For the regular backup of a data stock with not so many changes it is suffcient to save only modified files. When restoring a complete directory with the status of a certain day the usual incremental or differential methods have the disadvantage that the complete content must be collected from several backup sets.

Es wäre ideal, bei jedem Sicherungslauf nur die geänderten Dateien zu sichern, aber trotzdem ALLE Dateien der Quelle in jedem Sicherungssatz zur Verfügung zu haben. Dieses Ziel kann mit Hilfe sogenannter Hardlinks umgesetzt werden. Dazu wird die Fähigkeit des NTFS-Dateisystems genutzt, mehrere Namen für einen einzelnen Dateiinhalt zu verwalten. It would be ideal to backup only the changed files during each backup run, but still have ALL files of the source available in each backup set. With the help of so-called hard links this goal can be achieved. For this the ability of the NTFS file system is used to manage multiple names for a single file content.

BeschreibungDescription

AblaufProcess

Das PowerShell-Skript HardlinkBackup erstellt vollständige Sicherungen eines Verzeichnisbaumes in einem Zielverzeichnis. Diese Sicherungssätze werden in Tages-, Wochen-, Monats- und Jahresverzeichnissen verwaltet und in ihrer Anzahl begrenzt. Das Prinzip ist wie folgt: The PowerShell script HardlinkBackup creates full backups of a directory tree in a target directory. These backup sets are managed in daily, weekly, monthly and annual directories and are limited in number. The principle is as follows:

Jede (Tages-)Sicherung enthält die komplette Ablagestruktur. Physikalisch kopiert werden jedoch nur die gegenüber der letzten Sicherung geänderten Dateien. Die unveränderten Dateien existieren lediglich als Hardlink im Dateisystem und verweisen auf den Inhalt aus der letzten Sicherung. Eine Datei wird als geändert angesehen, wenn sich entweder die Dateigröße, das Datum der letzten Änderung oder die Attribute vom Original unterscheiden. Each (daily) backup contains the complete directory structure. However, only those files are physically copied which have been modified since the last backup. The unchanged files exist only as a hardlink and point to the content of the last backup. A file is considered modified when either the size, the date of last modification or the attributes differ from the original file.

Die eigentliche Arbeit erledigt das ProgrammThe program LN.EXE von Hermann Schinagl (Stichwort 'Delorean Copy'). Das PowerShell-Skript definiert die Ablagestruktur (Tages-, Wochen-, Monats- und Jahresbereiche), sorgt für das "Wandern" der Tagessicherung in die jeweiligen Bereiche und beschränkt dort deren Anzahl. Das folgende Bild mag das verdeutlichen: of Hermann Schinagl (keyword 'Delorean Copy') does the actual work. The PowerShell script defines the directory structure (daily, weekly, monthly and yearly area), ensures the "linking" of the current backup set into the respective areas and limits the number of sets. The following image may illustrate this:

Für jedes der Quellverzeichnisse (AERA, DBSDATA, DIOS, Praxis) existieren im Sicherungspfad die Bereichsverzeichnisse Tag, Woche, Monat und Jahr. Liegt die letzte Sicherung nicht in der aktuellen Kalenderwoche, so wird dieses Verzeichnis in den Bereich Woche übertragen - die Verzeichnisstruktur wird kopiert, die Dateien als Hardlink eingetragen. Stammt die letzte Sicherung nicht aus dem aktuellen Monat, erfolgt ein Übertrag in den Bereich Monat; entsprechend wird beim Jahr verfahren.
Die tägliche Sicherung landet immer im Topf Tag in einem eigenen Verzeichnis mit einem Zeitstempel als Name.
For each of the source directories (AERA, DBSDATA, DIOS, Praxis) the directories for the areas Day, Week, Month and Year do exist in the backup path. If the last backup is not in the current calendar week, a hardlink clone of this directory will be created in the week area - the directory structure is copied, the files are hardlinked. The same logic is applied to month and year.
The daily backup is always created in the day area with a timestamped directory name.

Die Anzahl der Sicherungsverzeichnisse in den Bereichen ist begrenzt (Tage: 15, Woche: 10, Monat: 9, Jahr: 5). Auf diese Weise kann man mit abnehmender Granularität auf 6 Jahre zurückgreifen. Diese Werte sind konfigurierbar und letztlich nur von der Plattenkapazität begrenzt. The number of backup directories in the areas is limited (days: 15, week: 10, month: 9, year: 5). In this way, with decreasing granularity, it is possible to go back up to 6 years. These values are configurable and ultimately depend only on the disk capacity.

SpeicherplatzSpace requirements

Verzeichnis DIOS enthält Patientendaten, DBSData Röntgenbilder und Praxis normale Dokumente. Nachfolgend die Auswertung des tatsächlichen Platzbedarfes: The DIOS folder contains patient data, DBSData x-rays and Praxis normal documents. In the following the evaluation of the actual space requirement:

    F:\Ablagen>ln --truesize Praxis
                       Items               Bytes
        File:        300.085     323.614.587.101
    Hardlink:        296.088     233.145.295.457
       Total:              -      90.469.291.644

    F:\Ablagen>ln --truesize DIOS
                      Items               Bytes
        File:        544.650     163.469.841.253
    Hardlink:        529.509     130.954.740.279
       Total:              -      32.515.100.974

       F:\Ablagen>ln --truesize DBSData
                      Items               Bytes
        File:      1.462.534     322.540.406.007
    Hardlink:      1.447.845     311.117.293.273
       Total:              -      11.423.112.734
      

Hier haben sich 1-2% der Dateien geändert; der Platzbedarf beträgt nur 17%. Trotzdem stehen in jedem Sicherungsverzeichnis alle Dateien zur Verfügung. 1-2% of the files have been modified and the space requirement is only 17%. Nevertheless all files are available in each backup directory.

NutzungUsage

Installation

Zur Nutzung muss das Archiv in ein beliebiges Verzeichnis entpackt werden. In den sprachspezifischen Konfigurationsdateien (.\DE\Configuration.psd1 bzw. .\EN\Configuration.psd1) können die Voreinstellungen (Auszuschließende Pfade und Dateien, Anzahl der aufzuhebenden Sicherungen, ...) angepasst werden.
Das Programm LN.EXE wird im Skriptpfad und den sonstigen Systempfaden (Umgebungsvariable PATH) gesucht. Im Archiv ist die statisch gelinkte 32-Bit-Version enthalten, die keine installierten Laufzeitbibliotheksversionen voraussetzt.
Aufrufparameter werden wie bei PowerShell-Skripts üblich mittels

HELP .\HardLinkBackup.ps1
angezeigt. Nachfolgend die Ausgabe der detaillierten Hilfe: To use it, extract the archive into any directory. Settings such as paths and files to exclude, number of savesets to keep can be adjusted as needed in the language specific configuration files (.\DE\Configuration.psd1 or .\EN\Configuration.psd1).
The program LN.EXE is searched in the script path and the other system paths (environment variable PATH). The archive contains the statically linked 32-bit version which does not depend on a certain version of installed runtime libraries.
Invocation help can be requested in the usual way for PowerShell scripts with
HELP .\HardLinkBackup.ps1
Below is the output of the detailed help:

AufrufInvocation

  ÜBERSICHTSYNOPSIS
    Backup directory tree using hardlinks to previous backup set on unaltered files.

  SYNTAX
    .\HardlinkBackup.ps1 [-SourceDirectory] <String> [-BackupDirectory] <String>
                         [-Name <String>] [-ExcludePaths <String[]>] [-ExcludeFiles <String[]>]
                         [-Purge] [-Keep <String[]>] [-WhatIf] [<CommonParameters>]

  BESCHREIBUNGDESCRIPTION
    Perform a backup from <SourceDir> to <BackupDir> using last backup set for
    hardlink references when a file is unchanged. Four period directories
    are used: 'Day', 'Week', 'Month' and 'Year'. A new backup set is always
    created in a timestamped directory below 'Day'. On every invocation a check
    is performed wether the last backup belongs to the current periods. If not,
    a hardlink entry will be created under the appropriate directory.
    The maximum number of backup sets in each period directory can be adjusted
    automatically.
    Exclusions for directory or file names can be specified. A predefined set
    is already built in but can be modified via a culture dependent configuration
    file.

  PARAMETERS
    -SourceDirectory <DirectoryInfo>
      alias SRC - top directory of the tree to backup

   -BackupDirectory <DirectoryInfo>
     alias BCK - base of backup directory - must exist!

   -Name <String>
     optional name appended to base of backup directory - default is name part of source path

   -ExcludePaths <String[]>
     alias XP - list of wildcard expressions to exclude paths
     an item starting with ':' is directly interpreted as a regular expression

   -ExcludeFiles <String[]>
     alias XF - list of wildcard expressions to exclude files

   -Keep <String[]>
      define maximum number of backup sets to keep within period directories
      (D=day, W=week, M=month, Y=year): format D=n,W=n,M=n,Y=n - equal sign is optional

    -Purge [<SwitchParameter>]
      restrict number of backup sets kept in the period directories

    -WhatIf [<SwitchParameter>]
      show what would be done but do not perform operation

    -------------------------- BeispielExample 1 --------------------------
    PS C:\>HardLinkBackup D:\Data S:\Backup
    Copy D:\Data to S:\Backup\Data\Day\yyyy-mm-dd_hhmm
    where yyyy-mm-dd_hhmm represents current date and time

    -------------------------- BeispielExample 2 --------------------------
    PS C:\>HardLinkBackup D:\Documents\Personal S:\Backup -name MyDocs
    Copy D:\Documents\Personal to S:\Backup\MyDocs\Day\yyyy-mm-dd_hhmm

    -------------------------- BeispielExample 3 --------------------------
    PS C:\>HardLinkBackup D:\ S:\Backup -xp *cache,temp
    exclude paths containing a directory name which ends with 'cache'
    or is equal to 'temp'.
    Matching across directories is possible: Firefox\Cache*

    -------------------------- BeispielExample 4 --------------------------
    PS C:\>HardLinkBackup D:\ S:\Backup -purge -whatif -verbose
    show predefined exclusions and period restrictions

    -------------------------- BeispielExample 5 --------------------------
    PS C:\>HardLinkBackup D:\ S:\Backup -purge
    Restrict number of backup sets to the defined maximum count.
      

RückgabewerteReturn codes

Im Sicherungsverzeichnis wird eine Logdatei erzeugt mit den Ausgaben von LN.EXE. Das Skript selbst liefert folgende Rückgabewerte: A log file with the output of LN.EXE is created in the backup directory. The script itself defines the following return codes:

HistorieHistory

22.10.202310/22/2023, V1.1.0
  • Optionen für LN-Befehle in Konfigurationsdatei ermöglicht options of LN commands possible via configuration file
  • Überprüfung der regulären Ausdrücke bei Pfadausschluss verification of regular expressions used for path exclusion
29.05.202205/29/2022, V1.0.6
  • Pfadausschluss intern auf reguläre Ausdrücke umgestellt path exclusion implemented internally using regular expressions
  • Angabe von regulären Ausdrücken möglich mittels ":"-Präfix specification of regular expressions using ":" prefix

Fragen / KommentareQuestions / Comments