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.