Results 1 to 13 of 13
  1. #1

    Please tell me if 2 hard drives with the same application can use single DB

    Hello

    I have a server with 2 hard drives. One is almost full so I need to use the newly added Hard drive to continue putting the media. If I made an identical copy of the application, altered the paths and used the same DB would that actually work? If not, how could I get the application to recognise media on the 2 drives?

    Regards
    We move to improve

  2. #2
    Join Date
    Apr 2000
    Location
    California
    Posts
    3,051
    I think more details are needed about it/how it works, but yes, different applications/scripts can use the same database without issue. As for it recognizing the other media/disk, I don't see why not, but I can't say for sure without knowing more about the service/application in question.

  3. #3
    Join Date
    Apr 2002
    Location
    Hollywood, CA
    Posts
    3,046
    symlink using the 'ln' command assuming this is a *nix box. You wont have to alter anything...

  4. #4
    Join Date
    Apr 2002
    Location
    Hollywood, CA
    Posts
    3,046
    To elaborate a little further:

    Your first path:
    /usr/media

    Your second path(drive)
    /mnt/HD2/media/<file name>
    Code:
    ln -s /mnt/HD2/media/<file_name1> /usr/media/<file_name2>
    This will link the file on the 2nd drive to your first harddrive. When you do a directory listing the files on your second harddrive will be listed on your first harddrive. It's like creating a shortcut with a little more power!

    ls -al /usr/media will result in the following:

    ... <file_name2> -> /mnt/HD2/media/<file_name1>

    ls will result in the following:

    <file_name2>

    making it appear as if <file_name2> is located on your first harddrive when in reality it lives on your second harddrive.
    Last edited by case; 02-24-2008 at 03:48 PM.

  5. #5
    Wow, nice, but 2 questions:
    1 - where would I put this command and
    2 - I have over 2000 videos, so you saying I would need to do this for each and every one?
    We move to improve

  6. #6
    Join Date
    Apr 2000
    Location
    California
    Posts
    3,051
    You probably don't want to link each one separately, and the idea is better to create a link for a directory. However, if it's for a specific directory, you may as well just mount the other drive with a partition path that you want to use and just use it naturally. Symbolic links don't hurt, but it could be a hassle trying to symlink that many files.

  7. #7
    Join Date
    Apr 2002
    Location
    Hollywood, CA
    Posts
    3,046
    The best way to employ this command would be through a shell script and or perl script that automates the entire process. I would probably cron this script as well that way you don't have to worry about actually running any commands after you've uploaded your new media files and makes adding new files hassle free in the future. The cron would run based on a time increment you find acceptable and add the symlink for you.

    Code:
    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    my @files = </mnt/hd2/media/*>;
    
    foreach my $file (@files) {
        if ( -e "/usr/media/$file" ) {
            next;
        }
        else {
            system(`ln -s /mnt/hd2/media/$file /usr/media/$file`);
        }
    }
    This perl script is pretty simple. It reads the directory and puts the file names into an array. It then loops through the array checking to see if the file name exists in the media directory. If so, it does nothing, if not it creates the symlink.

    This script is just something I threw together in a minute. You would probably want to modify it or add some error checking before deploying to production. If you need help let me know!

  8. #8
    Join Date
    Apr 2002
    Location
    Hollywood, CA
    Posts
    3,046
    Here is a finalized/tested example. There isn't much to change. You'll need to redefine the $hd1_media and $hd2_media variables to reflect the proper paths.

    You can change $FILE_PATTERN for example to equal a certain type of file like '*.mov' for quicktime. Right now it will pull all files names in $hd2_media dir using the '*' wild card.

    Pretty simple.. let me know if you have any questions.

    Code:
    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    # define hard drive media directories
    my $hd1_media = "/home/hd1";
    my $hd2_media = "/home/hd2";
    
    # change working dir
    chdir( $hd2_media );
    
    # list files in dir, put file handles in array
    my $FILE_PATTERN = '*';
    my @files = glob( $FILE_PATTERN );
    
    # Build new symlinks, ignore existing symlinks
    foreach my $file ( @files ) {
        if ( -e "$hd1_media/$file" ) {
            next;
        }
        else {
            symlink( "$hd2_media/$file", "$hd1_media/$file" )
              or die "Unable to create symlink for $file";
        }
    }

  9. #9
    Join Date
    Apr 2000
    Location
    California
    Posts
    3,051
    I would recommend using another method to read the files more efficiently than glob or some <wild card *> when you're going to be dealing with thousands of files. You would be reading a lot of data into that array which will consume some resources. I'd also recommend just changing the path in the scripts or adding a secondary path to fall back to or use instead, retaining the other existing path, and just mount the other partition on the secondary drive and save all the hassle with a crontab to run a script to locate new files to create symbolic links.

    If you insist on using a solution like that or just want to for fun (it can be), rather than reading it all into an array and then processing it, use 'while' with something like the following to just step through in one shot:

    Code:
    #!/usr/bin/perl
    use warnings;
    use strict;
    
    while ( </directory/path/here/*.{avi,mov,etc}> )
         symlink($file, $target) if !-l $target;
    }
    
    # With the appropriate checks.
    Last edited by Tim Greer; 02-25-2008 at 02:29 AM.

  10. #10
    Join Date
    Apr 2002
    Location
    Hollywood, CA
    Posts
    3,046
    Quote Originally Posted by Tim Greer View Post
    I would recommend using another method to read the files more efficiently than glob or some <wild card *> when you're going to be dealing with thousands of files. You would be reading a lot of data into that array which will consume some resources. I'd also recommend just changing the path in the scripts or adding a secondary path to fall back to or use instead, retaining the other existing path, and just mount the other partition on the secondary drive and save all the hassle with a crontab to run a script to locate new files to create symbolic links.

    If you insist on using a solution like that or just want to for fun (it can be), rather than reading it all into an array and then processing it, use 'while' with something like the following to just step through in one shot:
    The poster is talking about 2k files. Either method will process 10k files/symlinks in under .5 seconds even on a somewhat older machine. You however are correct. Using a while loop is the quicker, better suited method. The purpose of the array, and variables was to make the script easy to understand/change for a non-programmer. Either way this script should have no negative effects on the machine unless we start talking hundreds of thousands of files.

    Opposed to mounting a new dir, creating symlinks enables the poster to maintain his current media directory which I'm under the impression is not organized by directories but is more of a drop off point for miscellaneous media files which are then maintained by a secondary database backed application which is only capable of reading from one directory.

    If the application is capable of walking the dir structure then of course mounting the second HD in this folder would eliminate any need for a script.

    Code:
    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    # define hard drive media directories
    my $hd1_media = "/home/hd1";
    my $hd2_media = "/home/hd2";
    
    # Build new symlinks, ignore existing symlinks
    opendir DIR, $hd2_media
        or die "Cannot opendir $!";
    
    while ( my $file = readdir( DIR ) ) {
        if ( -e "$hd1_media/$file" ) {
            next;
        }
        else {
            symlink( "$hd2_media/$file", "$hd1_media/$file" )
              or die "Unable to create symlink for $file";
        }
    }

  11. #11
    Join Date
    Apr 2000
    Location
    California
    Posts
    3,051
    Pardon, I've had a fever of 103 and didn't finish my thought last night in my example. Anyway, I thought they meant 2k files a day, and I obviously misread it, but I'm always a stickler for the most efficient method (I'm not suggesting your ideas of code weren't fine). I just got a different impression of what they wanted and why which is why I suggested just using a different solution, but I just don't think there's enough information to really know either way unless the OP provides more information.

    If they want to traverse directories, they can use use File::KGlob, a more efficient Schwartzian Transform, etc., but for just listing only movie files, I'd suggest a while on the <glob> just so it doesn't read in all of the irrelevant files that might exist, and not have to grep for the specific file files after they've been read in. But, again, your solution is fine, too. I obviously mistakenly thought they'd be dealing with more files. Anyway, they have several options that will work fine, so unless they give more detail, that should do it.

  12. #12
    :-)

    Wow, I actually did end up mounting the other hard drive in the videos folder and it WORKS A CHARM - THANK YOU ALL!!!
    We move to improve

  13. #13
    Join Date
    Apr 2000
    Location
    California
    Posts
    3,051
    Glad to hear it!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •