Fixing broken symbolic links in Urbackup backups

When I changed hardware for my Urbackup server, I found that it had only corrected the backup directory path for new backups. As a result, all symbolic links prior to migration are broken.

Here are the commands used to move data from one server (nfs1) to another (pbs14200) :

rsync /media/vol1/urbackup/ --archive --compress --delete --hard-links root@pbs14200.inframshe.univ-fcomte.fr:/mnt/datastore/datastore0/urbackup

rsync /var/urbackup/ --archive --compress --delete --hard-links root@pbs14200.inframshe.univ-fcomte.fr:/var/urbackup

As you can see, the paths to the backup directory differ from one server to another: the first uses a Dell MD1000 ext4/RAID6 array mounted on /media/vol1/urbackup, while the second uses ZFS storage on an HPE Apollo 4200 mounted on /mnt/datastore/datastore0.

In this thread, I propose a script that allowed me to solve the problem.

First, here’s the command to find broken symbolic links:

find /mnt/datastore/datastore0/urbackup -xtype l -exec ls -l {} +

Before writing a script, let’s take a look at how the problem arises and how it can be corrected for a given broken symbolic link.

The following link is broken and is displayed in red in the Bash terminal.

ls -l /mnt/datastore/datastore0/urbackup/pgisdata-mshe.univ-fcomte.fr/231109-1933/.hashes/etc/cron.daily
lrwxrwxrwx 1 urbackup urbackup 99 Nov  9 19:33 /mnt/datastore/datastore0/urbackup/pgisdata-mshe.univ-fcomte.fr/231109-1933/.hashes/etc/cron.daily -> /media/vol1/urbackup/pgisdata-mshe.univ-fcomte.fr/.directory_pool/JE/JEIllloCKt16925479922169876288

/media/vol1/urbackup/pgisdata-mshe.univ-fcomte.fr/.directory_pool/JE/JEIllloCKt16925479922169876288 no longer exists as it has been moved to /mnt/datastore/datastore0.

Here is the bash command to correct broken symbolic link:

ln -sf /mnt/datastore/datastore0/urbackup/pgisdata-mshe.univ-fcomte.fr/.directory_pool/JE/JEIllloCKt16925479922169876288 /mnt/datastore/datastore0/urbackup/pgisdata-mshe.univ-fcomte.fr/231109-1933/.hashes/etc/cron.daily

Let’s implement this in a correction script. I can’t take much credit for this, as I admit I used ChatGPT to help me with this task. :innocent:

#!/bin/bash

# Fixing broken symbolic links in Urbackup backups
# Define the path of the old and new directories
old_path="/media/vol1/urbackup"
new_path="/mnt/datastore/datastore0/urbackup"

# Directory path to traverse
directory_path="/mnt/datastore/datastore0/urbackup"

# Find all symbolic links containing the old path and correct them
find "$directory_path" -type l | while read -r link; do
    # Check if the symbolic link contains the old path
    if [ "$(readlink "$link" | grep "$old_path")" ]; then
        # Extract the part of the path after the old directory
        old_part=$(readlink "$link" | sed "s|$old_path||g")

        # Create the new link by replacing the old path with the new one
        new_link="$new_path$old_part"
        ln -sf "$new_link" "$link"

        echo "The link $link has been corrected to $new_link"
    fi
done

Don’t be in a hurry… Running this script takes time (several days), especially if the server manages other types of backup in the same backup location (Borgbackup and Proxmox Backup Server, in my case).

I hope this feedback will be useful…

Ernest.

urbackupsrv remove-unknown is already able to fix symlinks.

And I did it with success after migrating the backup storage.

1 Like

Excellent answer, the solution proposed by the publisher is necessarily better than the ones we’re tinkering with here and there! I didn’t know this command existed.

Thank you so much!

Ernest.

1 Like