0

I'm using a Time Machine like backup script, that creates a partial backup to an external drive using hard links:

#!/bin/bash

date=`date "+%Y-%m-%dT%H-%M-%S"`
backup=/mnt/backup
targets="/ /data/seafile /boot /boot/efi"

mkdir -p $backup/logs 

rsync -a \
    --stats \
    --partial \
    -h \
    -H \
    -A \
    -X \
    -x \
    --log-file=$backup/logs/$date.log \
    --exclude='/media/**' --exclude='/mnt/**' --exclude='/proc/**' --exclude='/sys/**' --exclude='/tmp/**' --exclude='/run/**' --exclude='/dev/**' \
    $targets \
    --link-dest=$backup/latest \
    $backup/incomplete_$date \
    && mv $backup/incomplete_$date $backup/$date \
    && rm -f $backup/latest \
    && ln -s $backup/$date $backup/latest

Result:

/mnt/backup/
├── 2016-05-24T16-33-08
...
├── 2016-12-01T22-04-25
├── 2016-12-05T20-29-52
├── latest -> /mnt/backup/2016-12-05T20-29-52
├── logs
└── lost+found

This worked fine so far, until I started to use LVM and split up my data to different mount points. Now the contents of these backups look like this:

/mnt/backup/latest
├── bin
├── boot
├── data
...
├── efi
...
├── seafile
...

What I actually intented is that rsync copies every item of the list / /data/seafile /boot /boot/efi to the proper location in the hierarchy, so for e.g. the folders should end up like this:

/mnt/backup/latest
├── boot
│   ├── efi
...
├── data
│   └── seafile

The reason why I have to specify every target is the -x option. This stops rsync from crossing a file system border during the recursion. A "simple" solution would be to:

  • remove the -x flag
  • specify only / as target

But this gives me some additional disadvantages. For example I would have to exclude any unwanted mount point with an additional --exclude='/.../**' tag. For now these aren't too much, but I'd rather like to have an opt-in instead of an opt-out solution.

2

You should be able to get the effect you want with the -R (or --relative) flag. The reproduces the full path of the source in the destination, eg rsync -aR /a/b/c /dest will create a directory /dest/a/b/c.

Your --link-dest should still work but only once you have done a first new copy, so you may prefer to move the directories around in your last backup to match the new hierarchy or not all the hard links will be made.

1
  • Ok.. that was too easy..
    – dersimn
    Dec 7 '16 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.