Forum OpenACS Development: Extract files from the database

Collapse
Posted by Malte Sussdorff on
I have an old .LRN site which currently stores the files in the database. I would like to get them out of the database and store them in the filesystem. I heard that SLOAN did this already, so I wondered if someone could point me to a script that does this. If not, what is the best way to do it (taking into account that part of the exercise is to actually delete the content from the database). This is PG7.4, but I might need to run it on Oracle 8.1 as well (hopefully).
Collapse
Posted by Rocael Hernández Rizzardini on
#
# @author Rocael Hernandez (mailto:roc@viaro.net)
# @creation-date 2004-09-02
# @arch-tag: ec90a7aa-1355-47a4-a3f1-36876faed57d
# @cvs-id $Id: move.tcl,v 1.1 2004/09/15 04:03:48 roc Exp $


db_foreach get_items {select item_id, revision_id from cr_revisions where item_id in (select item_id from cr_items where content_type = 'file_storage_object' and storage_type = 'lob')} {

    set file [ns_mktemp /tmp/fs-${revision_id}-XXXXXX]

    db_blob_get_file write_lob_content {
        select lob as content
        from cr_revisions
        where revision_id = :revision_id
    } -file $file


    db_transaction {
        set filename [cr_create_content_file $item_id $revision_id "$file"]
        db_dml set_file_content {
            update cr_revisions
            set content = :filename
            where revision_id = :revision_id
        }

        db_dml update_cr_item {
            update cr_items set storage_type = 'file' where item_id = :item_id
        }

        # now lets delete the lob file from the DB!
        db_dml update_cr_lob {
            update cr_revisions set lob = NULL where revision_id = :revision_id
        }
    }

ns_log notice "
--------------------------------------------------------------------------------
ROC debugging 
fiel = $file
revision_id = '${revision_id}'
filename = '${filename}'
item_id = '${item_id}' 
--------------------------------------------------------------------------------"


}