DBIx-FileStore

Perl module that provides tools to insert, delete and manipulate
files stored in a mysql database.

"What!?" you say. "You're not supposed to store files directly
in a database!"

And I say, "Yes, friend, you're right. But sometimes you just
want to anyway." I actually wrote this just to see how well it
would work.

The answer is that it works fine. Modulus the fact that you're
storing large blobs (up to 500K) in a database. (In particular,
it might make your mysql transaction logs large, if you have
them enabled.)

The implementation and design details are explained throughout
the module's documentation; in particular see the
documentation for DBIx::FileStore.

In a nutshell you can copy files into and out of the database
(respectively) using the commands 'fdbput' and 'fdbget'.

'fdbmv' and 'fdbrm' are also provided, along
with a few other utilities in the script/ directory.

The important things to note are:

A) All the filenames in the filestore are in one flat address space.
  That is, a file like '/a/b/c.txt' is called just that, it's not
  in a folder called /a/b/ (although fdbls does offer some support
  for directory-like viewing of files with common prefixes).

B) The filenames in the filestore cannot contain spaces. It's demo
  code after all -- we tried to keep it simple.

For usage details, see the QUICKSTART section of this file (below)
and the documentation for the filestore scripts in the script/
directory.

For technical details, see the documentation for DBIx::FileStore
and the utilities in script/ as well.

There's a video demo showing use of the DBIx::FileStore command
line utilities available at joshr.com/src/DBIx-FileStore/
that is provided in multiple formats.

INSTALLATION

See the next section for use of the DBIx::FileStore system.
To install DBIx::Filestore, follow the normal perl test
and install process:

   perl Makefile.PL  (install any prerequisites it might flag)
   make
   make test
   sudo make install


QUICKSTART

Here we give a quickstart guide. We assume you've installed
DBIx::FileStore as in the previous section. To get the database setup:

 1) Have Mysql installed and running. You'll also DBI and DBD::mysql.

 2) Choose what database, dbuser and dbpasswd you're going to use
    to access mysql.  (DBIx-Filestore uses a table called 'files'
    and another called 'fileblocks' which are created in step 4.
    See table-definitions.sql and the documentation for
    DBIx::FileStore for technical details.)

 3) Copy the file fdb.conf-sample to either /etc/fdb.conf or ~/.fdbrc,
    and edit it to specify your dbname, dbuser and dbpasswd.

 4) Set up the needed tables in mysql via a command like:
        mysql dbname < table-definitions.sql

 5) You now have the DBIx-FileStore system installed.

 6) As a simple test, let's copy a file
    into the filestore:

        % cd /etc/
        % fdbput hosts

    That copies the file '/etc/hosts' into the filestore
    under the name 'hosts'.
    You can see it in the database with fdbls:

        % fdbls
        hosts

    fdbls also has a few interesting options, including -h, -l, and
    -m, which shows the file's size, update time (in the filestore),
    and MD5 checksum:

        % fdbls -h -l -m hosts
        7.44K 20101116 19:28 fp911CO8MLqOLmCGtmx7wA hosts

    You can view its contents via the command fdbcat:

        % fdbcat hosts | head -7
        # /etc/hosts    hardwired addresses.
        # DO NOT EDIT! CHANGES WILL BE OVERWRITTEN ON THE NEXT RUN OF
        # /home/admin/bin/setup/hosts-setup
        #
        127.0.0.1   localhost
        255.255.255.255 broadcasthost
        ::1             localhost

    We can also see some data about the files in the filestore:

        % fdbstat
        fdbstat: DB has 7623 bytes in 1 files stored in 1 blocks.

    Using you can use 'fdbrm' to remove files from the filestore:

        % fdbrm hosts

For more info, see the documentation for the 'fdb*' tools:
fdbcat, fdbget, fdbls, fdbmv, fdbput, fdbrm, fdbstat,
and fdbtidy.

fdbslurp (which is the inverse of fdbcat in
that it slurps from stdin instead of printing
to stdout) is left as an exercise for the reader.

LICENSE AND COPYRIGHT

Copyright (C) 2010 Josh Rabinowitz

This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.