Steinar
Steinar

Reputation: 5950

Is it possible to backup with rsync, follow root symlink, but preserve the rest of the symlinks?

I'm setting up a backup using rsync. I'd like to specify the root source directory using a symlink that points to it, but for the rest of the archived tree, I'd like to preserve the symlinks.

Further, I'd like to preserve the symlink name as the root in the backup archive.

The reason for this setup (which may, or may not, be very smart) is that the source is a versioned app, where the version numbers will increase over time. I only want to backup the latest version and I want rsync to remove older files from the backup archive.

Example source:

source_symlink -> source-1.2.3
source-1.2.3/
  file1.txt
  dirA/
    fileA.txt
  symlink_fileA -> dirA/fileA.txt

If I attempt to backup this with

rsync -av --delete source_symlink destination_dir

I simply get a copy of the symlink inside my destination; like this:

destination_dir/
  source_symlink -> source-1.2.3

I.e. a symlink pointing to a non-existing directory.

If I resolve the symlink myself, e.g. like this:

rsync -av --delete $(readlink -f source_symlink) destination_dir

I get the following:

destination_dir/
  source-1.2.3/
    file1.txt
    dirA/
      fileA.txt
    symlink_fileA -> dirA/fileA.txt

This is ok until I change the symlink to, for example the next version; e.g. source_symlink -> source-2.0.0. In that case, I end up with duplicates in the archive:

destination_dir/
  source-1.2.3/
  source-2.0.0/

What I'd like is that the root symlink is followed, but the rest of the symlinks are preserved. Further, I'd like to have the symlink name in destination directory. Like this:

destination_dir/
  source/
    file1.txt
    dirA/
      fileA.txt
    symlink_fileA -> dirA/fileA.txt

Is this possible to achieve?

Upvotes: 3

Views: 1750

Answers (1)

SweetChuck
SweetChuck

Reputation: 11

You might want to try exploding the -a option and omitting the "l".

So instead of -av you would have -rptgoDv.

From the documentation:

-l, --links                 copy symlinks as symlinks

Upvotes: 1

Related Questions