This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Recursively recreate hierarchy with NTFS hardlinks by Cygwin


On 2017-08-02, Oleksandr Gavenko wrote:

> Experiments shown that my goal can be archived in single command:
>
>   mkdir orig
>   echo 1 >>orig/my.txt
>
>   mkdir backup
>   rsync -a orig/ backup/1
>   rsync -a --link-dest=../1 orig/ backup/2
>
>   echo 2 >>backup/2/my.txt
>   cmp backup/1/my.txt backup/2/my.txt && echo ok
>   cmp orig/my.txt backup/2/my.txt || echo ok

``fsutil`` is built-in Windows utility:

  bash# fsutil hardlink list backup/2/my.txt
  \home\tmp\backup\1\my.txt
  \home\tmp\backup\2\my.txt

  bash# mv backup/1 backup/3

  bash# fsutil hardlink list backup/2/my.txt
  \home\tmp\backup\3\my.txt
  \home\tmp\backup\2\my.txt

That is additional proof of work.

My bash backup script looks like:

  LOG=/cygdrive/c/home/backup/backup-job.log
  DST=/cygdrive/d/backup

  DATE=`date +%F`

  COMMON_RSYNC_OPT=( -a --delete )

  log() {
    echo `date +'%F %T'` "$@" >>$LOG
  }

  backup_simple() {
    local SRC=$1
    local BASE=${SRC##*/}

    if [ ! -d $SRC ]; then
        log "$SRC does not exist, leave"
        return
    fi
    if [ -d $DST/$BASE/$DATE ]; then
        log "$SRC is already backuped to $DST/$BASE/$DATE"
        return
    fi
    if [ ! -d $DST/$BASE ]; then
        mkdir -p $DST/$BASE
    fi
    local LAST=`cd $DST/$BASE; find . -maxdepth 1 -type d | grep '[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}' | sort -r | head`
    local RSYNC_OPT=( "${COMMON_RSYNC_OPT[@]}" )
    if [ -n "$LAST" ]; then
        RSYNC_OPT+=( --link-dest=../$LAST )
    fi
    rsync "${RSYNC_OPT[@]}" $SRC/ $DST/$BASE/$DATE/
    log "$BASE is backuped"
  }

  backup_simple /cygdrive/c/home/devel/soapui
  backup_simple /cygdrive/c/home/devel/postman

================================================================

What options is recommended for using Cygwin's rsync?

Backuped files don't need to preserve permission, ACL, etc. The goal is to
preserve hierarchy and content and make backuping lightweight (with
timestamps/size checks and hardlinks).

I collected list of:

  -t --no-p --no-l --no-acls --no-o --no-g --no-D -O -J -m --no-partial --delete

to ignore most of file meta-information and make time/size bases checks.

================================================================

What is the better way to schedule backup task?

I've got familiar with Windows Task Scheduler, it has interesting options:

* run task as soon as possible after scheduler start is missed
* stop task if it runs longer then
* wake the computer to run this task

Do I need to bother with Cygwin CRON?

-- 
http://defun.work/


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]