Help me make a script for recursive mass hardlink creation

Brownz

Dabbler
Joined
Sep 5, 2017
Messages
23
I have recently found out my freenas install of sonarr/radarr and qbittorrent was setup incorrectly.
I wanted the sonarr/raddarr app to create hardlinks to the torrent location, but I didnt reliase that it would fail if the download data was on a different dataset. Now the default action is to copy the torrent data and I have been left with alot of duplicated data.

Since I noticed this I have transfered all the data to a download directory on my media dataset.
I just have the monumental task of deleting copies in the media location and instead creating a hardlink to each of the torrent files in the download location.

Can anyone help me create a script that will: Recursively loop through my download directory and for each torrent file: perform a similar hardlink creation to the media directory that sonarr and raddarr does, this includes renaming the file to something human/plex readable and creating series folders if not already there.

Im quite a noob at creating scripts, Im sure this is a simple process for some one, can anyone help?
 
Last edited:

fracai

Guru
Joined
Aug 22, 2012
Messages
1,212
That step of creating something human readable sounds like you'd need to audit every rename action.
Instead, I suggest making a list of the source files (find source/path/ -type f > "source.txt"), copy that (cp "source.txt" "destination.txt"), edit each destination line to what it should be (proper destination path, new file and folder names, etc.), then write a script that reads both files and renames each file in source to the corresponding line in destination.
Alternatively, keep everything in one file. get your source list and then turn each line in to a hardlink command.

If you don't actually need to edit the destination names, rsync includes a mode where you can create hardlinks instead.

Oh! Actually, rdfind is a tool perfect for this. It finds duplicate files and can delete or create sym- or hard links. It's not in the ports collection, but I think I was able to compile it.
 
Top