2

in case I accidentally modify/delete important documents, my linux PC makes daily backups with a script that gets executed by cron and contains the following line.

rsync --checksum --recursive ${source} ${dest}/$i --link-dest=${dest}/$((i-1))

(${source} ist the path of the documents folder, ${dest}/n is the path of the n-th backup.)

Using the --link-dest option has the great advantage, that if you backup a 3 GB Folder, change on small file and backup again, both backups combined need 3 GB disk space, instead of 6 GB if I would run rsync without the --link-dest option.

I'm struggling to write a similar script for windows: I could just use the cp -r powershell command (or the xcopy cmd command) but this command does not have an option that is similar to rsync's --link-dest option. Using the linux subsystem for windows for the rsync command works, but scripts in the cron.daily folder inside the linux subsystem for windows do net get executed daily.

TLDR: What is the windows equivalent of rsync -r pathA pathB --link-dest pathC

PS: In case anyone wants the linux version of the script for his own backups, here it is:

#!/bin/bash

source=/home/username/documents
dest=/myBackup

if [ "$1" == "--install" ] ; then
    echo "installing..."
    cp $0 /etc/cron.daily/myBackupScript
    mkdir $dest
    echo "installed"
    exit 0
fi

for i in {0..9999}; do
    if [ ! -e ${dest}/$i ]; then
        echo "Copying to " ${dest}/$i
        if [ -d ${dest}/$((i-1)) ]; then
            rsync --checksum --recursive ${source} ${dest}/$i --link-dest=${dest}/$((i-1))
        else
            rsync --checksum --recursive ${source} ${dest}/$i
        fi
        DATE=`date +%Y-%m-%d__%H:%M:%S`
        touch ${dest}/$i/$DATE
        exit 0
    fi
done
echo "unable to do backup"
exit 4
Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Volker Weißmann
  • 554
  • 1
  • 6
  • 24
  • there are windows versions of rsync – Marcin Orlowski Mar 31 '18 at 16:36
  • [cwrsync](https://www.itefix.net/cwrsync) or [deltacopy](http://www.aboutmyip.com/AboutMyXApp/DeltaCopy.jsp) works pretty well – Didix Mar 31 '18 at 16:38
  • Possible duplicate of [How do I create file hardlink in PowerShell on Windows 10?](https://stackoverflow.com/questions/31863258/how-do-i-create-file-hardlink-in-powershell-on-windows-10) – Tripp Kinetics Mar 31 '18 at 17:02

1 Answers1

0

The current rsync version (3.2.2) from the MSYS2 collection for Windows (install: pacman -S rsync), supports the --link-dest hardlink re-use option correctly on NTFS. It also supports NTFS unicode filenames now. Absolute paths have to be given in MSYS / Cygwin convention - e.g. /C/path/to/source/.

Note: So far (2021-02) the MSYS2 rsync cannot create / replicate symbolic links in the destination using any of the symlink options. It would create content copies instead. Yet it can detect and exclude symlinks in the source.

kxr
  • 4,841
  • 1
  • 49
  • 32