How to truncate backup paths in rsnapshot
Solution 1
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
.
Solution 2
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.
Solution 3
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.
Related videos on Youtube
andreas-h
Updated on September 18, 2022Comments
-
andreas-h almost 2 years
I'm not sure if the heading is really coorect. I have a line in my rsnapshot.conf
backup [email protected]:/mnt/rsnapshot/ srv01/
So rsnapshot creates a directors
RSNAPSHOT_ROOT/daily.0/srv01/mnt/rsnapshot
and puts the backed-up files there. For me, the/mnt/rsnapshot
part is unnecessary; I'd rather have my backed-up files directly inRSNAPSHOT_ROOT/daily.0/srv01/
. Is there any way to achieve this? -
andreas-h over 11 yearsin theory, and according to the manpage, this should work, but it doesn't -- I still have the
/mnt/rsnapshot
in my backups. Any idea what could be wrong? -
Steven Monday over 11 yearsPerhaps
rsnapshot
"sanitizes" the source pathname before passing it torsync
, stripping off the extra./
. Check the log file/var/log/rsnapshot.log
, it should show you exactly whatrsync
commands it is issuing. -
andreas-h over 11 yearsrsnapshot seems to cut off the trailing
/
, so that it rsync with the path[email protected]:/mnt/rsnapshot/.
Is there anything I can do without disabling--relative
? -
Steven Monday over 11 years@andreas-h: Check out the EDIT. I hope this solves it for you.
-
Sridhar Sarnobat almost 3 yearsyou still need ` +rsync_long_args=--no-relative` don't you?