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

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
