Forum OpenACS Development: Relocating blob-stored data to files

Hi there, has anyone created a script to relocate filestorage data from blobs to the file-system. i forgot to set StoreFilesInDatabaseP to 0 and created some filestorage instances that save their data to blobs. now i want to correct that and relocate the data to the file-system. if anyone has created a script to accomplish that i would be glad to get some help.

TIA, peter

Collapse
Posted by Rocael Hernández Rizzardini on
This worked for Galileo (PG):

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
file = $file
revision_id = '${revision_id}'
filename = '${filename}'
item_id = '${item_id}'
--------------------------------------------------------------------------------"

}

Collapse
Posted by Peter Alberer on
thanks a lot Rocael!