How to truncate backup paths in rsnapshot

rsnapshot uses the --relative flag of rsync to preserve pathname information. In most cases, you probably do want to keep (at least some of) that information, especially when backing up local directories. However, in your case, you really don't need to keep the leading path prefix.

With reasonably recent versions of rsync (v.2.6.7+), you can explicitly control the portion of the pathname prefix that --relative saves by inserting a ./ at the desired cut-point. The ./ does not effectively change the pathname, but it does tell rsync that you want --relative to only keep the part of the pathname that follows the ./. Since you want to cut off the entire pathname, you simply append the ./ onto the end of the source path, like this:

backup  [email protected]:/mnt/rsnapshot/./  srv01/

EDIT

Okay, so it looks like the ./ trick won't work in this case, since rsnapshot strips off the trailing /. Instead, you should be able to disable the --relative option on a per-backup-point basis, by adding a fourth column to your backup line, like this:

backup  [email protected]:/mnt/rsnapshot/  srv01/  +rsync_long_args=--no-relative

The +rsync_long_args tells rsnapshot to append to its existing rsync_long_args option, for the current backup-point only. By appending --no-relative to rsync_long_args, you achieve the desired effect of turning off --relative.


Steven's first suggestion to use ./ does actually work with rsnapshot, you just have to put it twice:

backup  [email protected]:/mnt/rsnapshot/././  srv01/

Rsnapshot will strip the last slash of, but the first dot works for rsync.


This behaviour is actually controlled by rsync's --relative flag. Quoting the rsync manual:

-R, --relative

Use relative paths. This means that the full path names specified on the command line are sent to the server rather than just the last parts of the filenames. This is particularly useful when you want to send several different directories at the same time. For example, if you used this command:

rsync -av /foo/bar/baz.c remote:/tmp/

... this would create a file named baz.c in /tmp/ on the remote machine. If instead you used

rsync -avR /foo/bar/baz.c remote:/tmp/

then a file named /tmp/foo/bar/baz.c would be created on the remote machine, preserving its full path. These extra path elements are called "implied directories" (i.e. the "foo" and the "foo/bar" directories in the above example). [...]

So, in your rsnapshot.conf find the line that starts with rsync_long_args. By default, --delete --numeric-ids --relative --delete-excluded should be present. Removing the --relative option, should lead to the desired results.

Tags:

Rsnapshot