Bkp save: backup destination inside source causes rdiff-backup recursion warning

Hi,

I found what appears to be a small bug in the bkp utility from elive-tools.

Environment

bkp is provided by elive-tools:

$ type -a bkp
bkp is /usr/bin/bkp
bkp is /bin/bkp

$ file /usr/bin/bkp
/usr/bin/bkp: Bourne-Again shell script, ASCII text executable

$ dpkg -S /usr/bin/bkp
elive-tools: /usr/bin/bkp

Problem

When running bkp save from the user's home directory:

$ cd ~
$ bkp save
Saving...WARNING: The target directory '/home/patrick/.cache/bkp/backups/%home%patrick.rdiff' may be contained in the source directory '/home/patrick'. This could cause an infinite recursion. You may need to use the --exclude option (which you might already have done).

The reason appears to be that bkp stores its backups under:

bkpdir_main="${HOME}/.cache/${tool}"
bkpdir_backups="${bkpdir_main}/backups"

Therefore, when the directory being backed up is $HOME, the backup repository itself is located inside the source directory.

The do_save() function currently invokes rdiff-backup without excluding the bkp storage directory:

if ((is_old_rdiff)) ; then
    do_sudo rdiff-backup "${src}" "${dst}"
else
    do_sudo rdiff-backup $rdiff_opts backup "${src}" "${dst}"
fi

Suggested fix

Exclude ${bkpdir_main} from the source:

if ((is_old_rdiff)) ; then
    do_sudo rdiff-backup --exclude "${bkpdir_main}" "${src}" "${dst}"
else
    do_sudo rdiff-backup $rdiff_opts backup --exclude "${bkpdir_main}" "${src}" "${dst}"
fi

This is preferable to excluding the entire ~/.cache directory because it changes only what is necessary to prevent bkp from backing up its own repository.

After applying this change locally, bkp save can safely back up $HOME without rdiff-backup considering the destination to be part of the source tree.

Reproduction

cd ~
bkp save

Expected behaviour:

bkp backs up the home directory while automatically excluding its own ~/.cache/bkp working/backup directory.

Current behaviour:

rdiff-backup detects that the backup repository is contained within the directory being backed up and warns about possible infinite recursion.

Thanks!

1 Like