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