How to exclude symbolic link in rsync/rsnapshot

5,546

Unless you set rsync_short_args or rsync_long_args in the configuration file for rsnapshot, you'll use rsync -a to perform the copy.

The default action for rsync -a is to copy a symlink as a symlink, and to ignore the target of the symlink. (Obviously, if the target of the symlink is within your source file tree it will get copied, but that's because of its position not because it's the target of an included symlink.)

If you want to exclude the symlink itself, you just need to reference it in an exclude line:

exclude /foo/bar

I've not included the leading /home because that's the root of your source tree and filters are always based on the root of the source.

Share:
5,546

Related videos on Youtube

zar
Author by

zar

I teach mathematics in a high school in Italy.

Updated on September 18, 2022

Comments

  • zar
    zar almost 2 years

    I am using rsnapshot to manage my backups. The file /home/foo/bar is a symbolic link to a folder, and I want to exclude it. The --exclude option does not work, because if the pattern ends with a / then it will only match a directory, not a symlink.

    How could I do this?

    The rsync man page says:

    if the pattern ends with a / then it will only match a directory, not a regular file, symlink, or device.

    So what I'm asking is: how can I exclude from rsnapshot a symbolic link to a folder?

    If the link is /home/foo/bar, which of the following config lines is the right one?

    exclude /home/foo/bar/
    
    exclude /home/foo/bar
    
    exclude /home/foo/bar**
    
    exclude /home/foo/bar***
    

    This is the config file that I'm using now:

    config_version  1.2
    snapshot_root   /media/satellite/rsnapshot/
    
    cmd_cp      /bin/cp
    cmd_rm      /bin/rm
    cmd_rsync   /usr/bin/rsync
    cmd_logger  /usr/bin/logger
    
    retain      hourly  6
    retain      daily   7
    retain      weekly  4
    
    verbose     2
    loglevel    3
    
    lockfile    /var/run/rsnapshot.pid
    
    exclude /home/roberto/media/
    exclude /home/roberto/media
    exclude /home/roberto/media**
    exclude /home/roberto/media***
    
    backup  /home/      localhost/
    backup  /etc/       localhost/
    backup  /usr/local/ localhost/
    backup  /var/www/   localhost/
    

    Where /home/roberto/media is a symlink to /media, which is a directory

    • Gilles 'SO- stop being evil'
      Gilles 'SO- stop being evil' about 7 years
      I don't understand the problem. Why would the pattern end with a slash? What's wrong with --exclude=/bar (assuming that your source is /home/foo)?
    • zar
      zar about 7 years
      Well, neither --exclude /home/foo/bar nor --exclude /home/foo/bar/ are working
    • Gilles 'SO- stop being evil'
      Gilles 'SO- stop being evil' about 7 years
      What command line are you using, and if applicable what configuration file? Copy-paste them into your question.
    • zar
      zar about 7 years
      Ok, now I have in my configuration file the following lines: exclude /home/roberto/media/ exclude /home/roberto/media exclude /home/roberto/media** exclude /home/roberto/media*** --- One of them is the right one, the directory is not copied anymore
    • Gilles 'SO- stop being evil'
      Gilles 'SO- stop being evil' about 7 years
      Copy-paste the complete configuration file into your question. We can't help you if you hide crucial information.