rsync is a versatile command line tool that allows efficient data transfers and synchronization between systems. A symbolic link (symlink) is a file that points to another file or directory. To preserve symbolic links during rsync operations, you use the -l or —links option. However, it is important to note that this will only keep the symbolic links, not what they are pointing to.
Here’s an example: Suppose you have a symlink “/home/user/docs” which points to “/mnt/docs”. When you use rsync -l, it will duplicate the symlink to the destination, but will not copy “/mnt/docs” to the destination.
```
rsync -avz -l /source/directory/ /destination/directory/
```
In case you want the symbolic link and the data it is pointing to both to be synced, use the -L or —copy-links option. This means that if the source system has symbolic links, rsync treats them as the files or folders they point to. Be cautious as this might lead to duplicating large amounts of data if those links point to large folders .
Here’s an example of using the -L option:
```
rsync -avz -L /source/directory/ /destination/directory/
```
Documentation for rsync’s symbolic link options can be found in the manpages (‘man rsync’). Below are excerpts from the version of the manpage included with rsync 3.2.3:
```
-l, —links copy symlinks as symlinks
-L, —copy-links transform symlink into referent file/dir
—copy-unsafe-links only “unsafe” symlinks are transformed
—safe-links ignore symlinks that point outside the source tree
```
These options provide a flexible set of controls on how symbolic links are handled.
In addition to preserving symbolic links, there are many more options you may want to consider when creating backups. Some of these include preserving file permissions (-p), owner (-o), group (-g), and timestamps (-t). The -a option (‘archive mode’) is often useful as it enables many of these options at once.
Using rsync effectively involves understanding the types of data you’re working with, and the constraints of your storage and network environment. Although rsync is highly flexible and efficient, make sure you understand each option well before using them in your data backup or transfer operations.
Sources:
1. rsync(1) – Linux man page. (n.d.). Retrieved March 24, 2021, from https://linux.die.net/man/1/rsync
2. Millan, R. (2011). Preserve symbolic links, file permissions and ownership in tar and rsync. Retrieved March 24, 2021, from https://major.io/2011/05/24/preserve-symbolic-links-file-permissions-and-ownership-in-tar-and-rsync/
3. Arch Linux. (n.d.). Rsync. Retrieved March 24, 2021, from https://wiki.archlinux.org/index.php/rsync\_NPC