[Linux] Symlink script - Unifies Hard Drive Contents

Come up with a useful post-processing script? Share it here!
Post Reply
prochobo
Newbie
Newbie
Posts: 4
Joined: May 24th, 2009, 4:29 pm

[Linux] Symlink script - Unifies Hard Drive Contents

Post by prochobo »

Let me first explain what problem this addresses:

I have a server with (2) 1.5TB drives.  I want to store all my sabnzbd downloads to these drives and view all the downloads in one volume, not two. 

For example, I have /mnt/sda/Movies and /mnt/sdb/Movies.  My sdb has completely filled up, so I must redirect all downloads to sda.  Well, it's such a pain in the ass going back and forth between the same folder (Movies) on two different drives.  Instead, I'd like to open one Movies folder and see the contents from both the Movies folders in sda and sdb.

So basically, this script looks at two partitions, compares the differences, and makes symlinks to the differences.  By no means am I a programmer, so the code I've produced is a little rough, but it works :)  Also, I never saw a way to do this, so I thought I'd share.  Someone out there has got to have the same problem as me. 

Code: Select all

#!/bin/bash

# find out what sda has that sdb doesn't have, store in tosync var
tosync=`sudo diff -r /mnt/sda /mnt/sdb | grep  /mnt/sda | sed 's/Only in //' | sed 's/: /\//'`

#create array from findings above, stores each file path in an element using newline as a separator
old_IFS=$IFS
IFS=$'\n'
lines=($tosync) # array
IFS=$old_IFS
length=${lines[@]}

# loop through the array
for ((i=0; i<${#lines[*]}; i++))
do
        src=${lines[$i]} #store source file path
        dest=`echo $src | sed 's/^\/mnt\/sda/\/mnt\/sdb/'` #store destination file path - changes "/mnt/sda" from source file path to "/mnt/sdb"
        ln -s "$src" "$dest" #create the symbolic link
done
You'll have to modify this script to match up to your partitions, but this should give you a good start :)
doubledrat
Release Testers
Release Testers
Posts: 180
Joined: February 20th, 2008, 3:16 pm

Re: [Linux] Symlink script - Unifies Hard Drive Contents

Post by doubledrat »

wouldn't it be easier to just link the downloaded directory as it's a parameter to the postproc job?

e.g.

Code: Select all

ln -s "$1" "/mnt/sdb/$3"
I'm cheating a bit as I'm using the name of the download ($3) for the linked name, but it should do what you want
prochobo
Newbie
Newbie
Posts: 4
Joined: May 24th, 2009, 4:29 pm

Re: [Linux] Symlink script - Unifies Hard Drive Contents

Post by prochobo »

doubledrat wrote: wouldn't it be easier to just link the downloaded directory as it's a parameter to the postproc job?

e.g.

Code: Select all

ln -s "$1" "/mnt/sdb/$3"
I'm cheating a bit as I'm using the name of the download ($3) for the linked name, but it should do what you want
Yes, in fact, I thought of going about it that way.  Only thing is, I had already partially filled my /mnt/sda volume, so I needed to link the current files as well.
Post Reply