HOWTO: Mount your Database as File System via WebDAV under Linux

No, no this isn’t another DBFS post but a more simple and direct way of achieving the same

;-)

Just had a funny discussion with Roel Hartman regarding how to trick the Tomcat APEX 4 setup in believing that the virtual XFILES directory in the database was actually available on disk of the local server. This is probably not the way to solve this but should be realized via Tomcat / APEX 4. The OTN Development virtualbox environment with APEX 4 gets his “/i/” images via Tomcat from the directory.

[oracle@localhost i]$ pwd
/home/oracle/apache-tomcat-6.0.20/webapps/ROOT/i

The easiest solution would have been to copy the XFILES images and files in a directory called XFILES under the ROOT directory.

[oracle@localhost i]$ pwd
/home/oracle/apache-tomcat-6.0.20/webapps/ROOT/XFILES

Investigating the APEX 3 and 4 OTN Development virtualbox environments, I discovered the following way to solve it as well, which in this case was implemented by Mark Drake.

What you could do in this situation, while keeping it “as is”, so XFILES files and images in the database are still in the XDB Repository, is to “trick” the Tomcat server so the virtual directory could be accessed via WebDAV as if it were a file system mount. There is an open source project out there called “davfs”, which is nowadays a GNU Project, and can be found here for download (“davfs2″) which could achieve this for us.

As it is said there:


Web Distributed Authoring and Versioning (WebDAV), an extension to the HTTP-protocol, allows authoring of resources on a remote web server. davfs2 provides the ability to access such resources like a typical filesystem, allowing for use by standard applications with no built-in support for WebDAV.

  • davfs2 is designed to fully integrate into the filesystem semantics of Unix-like systems (mount, umount, etc.). davfs2 makes mounting by unprivileged users as easy and secure as possible.
  • davfs2 does extensive caching to make the file system responsive, to avoid unnecessary network traffic and to prevent data loss, and to cope for slow or unreliable connections.
  • davfs2 will work with most WebDAV servers needing little or no configuration.
  • davfs2 is developed and tested on GNU/Linux but porting to other free operating systems should not be too cumbersome.

After downloading and installing the davfs2 packages, the manual pages via entering “man davfs2.conf” on the prompt will show you, among others,

NAME
davfs2.conf – Configuration file for mount.davfs

DESCRIPTION
There is a system wide configuration file /usr/local/etc/davfs2/davfs2.conf and user configuration files ~/.davfs2/davfs2.conf. When mount.davfs is invoked by root, only the system wide configuration file is read. When invoked by an ordinary user, the user configuration file is read in addition. Settings from the user configuration file will take precedence over the system wide configuration.

The configuration file consists of lines where each line contains a keyword value pair. Keyword and value are separated by spaces and/or tabs.

The file may contain sections that are for one specific mount point only. Such a section starts with a line, that contains the full path of the mount point enclosed in square brackets. The section ends at the start of the next section or the end of file. Options that shall apply to all mounted file system must come before the first sections. Options given in a mount specific section will have precedence.

…other man manuals can be found under ” mount.davfs(8)” and “umount.davfs(8)”.

OTN Development Virtualbox “davfs” Set-up

The current OTN Development Virtualbox environment will show the following content for the server config file

[oracle@localhost i]$ cat /usr/LOCAL/etc/davfs2/davfs2.conf
# davfs2 configuration file 2009-04-12
# version 9
# ------------------------------------
 
# Copyright (C) 2006, 2007, 2008, 2009 Werner Baumann
 
# Copying AND distribution OF this file, WITH OR WITHOUT modification, are
# permitted IN any medium WITHOUT royalty provided the copyright notice
# AND this notice are preserved.
 
# Please READ the davfs2.conf (5) man page FOR a description OF the
# configuration options AND syntax rules.
 
# Available options AND DEFAULT VALUES
# ====================================
 
# General Options
# ---------------
 
# dav_user        davfs2            # system wide config file ONLY
# dav_group       davfs2            # system wide config file ONLY
# ignore_home                       # system wide config file ONLY
# kernel_fs       fuse
# buf_size        16                 # KiByte
 
# WebDAV Related Options
# ----------------------
 
# use_proxy       1                 # system wide config file ONLY
# proxy                             # system wide config file ONLY
# servercert
# clientcert
# secrets         ~/.davfs2/secrets # USER config file ONLY
# ask_auth        1
# use_locks       1
# lock_owner      <USER -name>
# lock_timeout    1800              # seconds
# lock_refresh    60                # seconds
# use_expect100   0
# if_match_bug    0
# drop_weak_etags 0
# allow_cookie    0
# precheck        1
# ignore_dav_header 0
# server_charset
# connect_timeout 10                # seconds
# read_timeout    30                # seconds
# retry           30                # seconds
# max_retry       300               # seconds
# add_header
 
# Cache Related Options
# ---------------------
 
# backup_dir      lost+found
# cache_dir       /var/cache/davfs2 # system wide cache
#                 ~/.davfs2/cache   # per USER cache
# cache_size      50                # MiByte
# table_size      1024
# dir_refresh     60                # seconds
# file_refresh    1                 # SECOND
# delay_upload    10
# gui_optimize    0
 
# Debugging Options
# -----------------
 
# debug           # possible VALUES: config, kernel, cache, http, xml,
                  #      httpauth, locks, ssl, httpbody, secrets, most
</user>

So in short nothing is additionally configured on server level. The Oracle user config in /home/oracle/.davfs2 doesn’t show also no extra configuration

[oracle@localhost .davfs2]$ pwd
/home/oracle/.davfs2
 
[oracle@localhost .davfs2]$ ls *
davfs2.conf  secrets
 
cache:
localhost+home-oracle-dav+oracle
 
certs:
private
 
[oracle@localhost .davfs2]$ ls -ltra
total 28
-rw-------  1 oracle oracle 2648 Sep 13 08:34 secrets
-rw-r--r--  1 oracle oracle 2169 Sep 13 08:34 davfs2.conf
drwxr-xr-x  3 oracle oracle 4096 Sep 13 08:34 certs
drwx------ 39 oracle oracle 4096 Sep 13 08:34 ..
drwxr-xr-x  4 oracle oracle 4096 Sep 13 08:34 .
drwx------  3 oracle oracle 4096 Sep 13 08:34 cache
 
[oracle@localhost .davfs2]$ cat davfs2.conf
# davfs2 configuration file 2009-04-12
# version 9
# ------------------------------------
 
# Copyright (C) 2006, 2007, 2008, 2009 Werner Baumann
 
# Copying AND distribution OF this file, WITH OR WITHOUT modification, are
# permitted IN any medium WITHOUT royalty provided the copyright notice
# AND this notice are preserved.
 
 
# Please READ the davfs2.conf (5) man page FOR a description OF the
# configuration options AND syntax rules.
 
 
# Available options AND DEFAULT VALUES
# ====================================
 
# General Options
# ---------------
 
# dav_user        davfs2            # system wide config file ONLY
# dav_group       davfs2            # system wide config file ONLY
# ignore_home                       # system wide config file ONLY
# kernel_fs       fuse
# buf_size        16                 # KiByte
 
# WebDAV Related Options
# ----------------------
 
# use_proxy       1                 # system wide config file ONLY
# proxy                             # system wide config file ONLY
# servercert
# clientcert
# secrets         ~/.davfs2/secrets # USER config file ONLY
# ask_auth        1
# use_locks       1
# lock_owner      <USER -name>
# lock_timeout    1800              # seconds
# lock_refresh    60                # seconds
# use_expect100   0
# if_match_bug    0
# drop_weak_etags 0
# allow_cookie    0
# precheck        1
# ignore_dav_header 0
# server_charset
# connect_timeout 10                # seconds
# read_timeout    30                # seconds
# retry           30                # seconds
# max_retry       300               # seconds
# add_header
 
# Cache Related Options
# ---------------------
 
# backup_dir      lost+found
# cache_dir       /var/cache/davfs2 # system wide cache
#                 ~/.davfs2/cache   # per USER cache
# cache_size      50                # MiByte
# table_size      1024
# dir_refresh     60                # seconds
# file_refresh    1                 # SECOND
# delay_upload    10
# gui_optimize    0
 
# Debugging Options
# -----------------
 
# debug           # possible VALUES: config, kernel, cache, http, xml,
                  #      httpauth, locks, ssl, httpbody, secrets, most
 
[oracle@localhost .davfs2]$ cat secrets
# davfs2 secrets file  2009-10-18
# version 4
# -------------------------------
 
# Copyright (C) 2006, 2007, 2008, 2009 Werner Baumann
 
# Copying AND distribution OF this file, WITH OR WITHOUT modification, are
# permitted IN any medium WITHOUT royalty provided the copyright notice
# AND this notice are preserved.
 
 
# # This file must be readable AND writeable BY the owner ONLY (mode 0600).
 
# This file contains user-name AND password FOR the proxy, the
# WebDAV resources AND decryption passwords FOR client certificates.
 
# Comments are indicated BY a '#' CHARACTER AND the rest OF the line
# IS ignored. Empty LINES are ignored too.
 
# Each line consists OF two OR three items separated BY spaces OR tabs.
# IF an item contains one OF the characters SPACE, tab, #, \ OR ", this
# character must be escaped by a preceding \. Alternatively, the item
# may be enclosed in double quotes. (see also the davfs2.conf (5) man page)
 
 
# Proxy Line
# ----------
# A proxy line consists of the fully qualified domain name of the proxy,
# the user-name and the password. The proxy name must not contain a scheme
# or path segment, but a port number should be added, separated by a colon.
# The password my be omitted.
# Instead of the name of the proxy, the keyword "proxy" may be used.
 
# Examples
# foo.bar:3245                  otto          my\ secret
# foo.bar                       otto          "my secret"
# proxy                         otto          "my secret"
 
 
# Credential Line
# ---------------
# A credential line consists of the mount-point, the user-name and
# the password. The mount-point must be an absolute path, starting
# with /. The password may be omitted.
# For compatibility with older versions, instead of the mount-point
# the URL may be given. The URL must contain scheme, fully qualified
# domain name and path. If the path segment is missing, / is assumed.
 
# Examples
# /home/otto/foo                otto          g3H\"x\ 7z\\
# /media/dav/bar                otto          geheim
# Old style
# "http://foo.bar/my documents" otto          "geh # heim"
# https://foo.bar:333/dav       otto          geh\ \#\ heim
 
 
# Password for Client Certificate
# -------------------------------
# It must contain the name of the certificate file and the encryption
# password. The name must be either absolute (starting with /) or the
# file-name only. If it is not absolute, it is assumed to be in the
# standard directory for client certificates.
 
# Examples
# /home/otto/.davfs2/certs/private/otto.crt  geheim
# otto_private.crt              "this IS extraordinary secret"
# "otto private.crt"            this\ is\ secret,\ too.
</user>

Mount your database as a file system via WebDAV under Linux

So although you have the option to configure a lot, for the OTN Development Virtualbox environment nothing specific has been configured. To mount your database as a file system the XDB Protocol adapter must be enabled. For example via the following

SQL> -- enable HTTP XDB protocol port
SQL> EXECUTE DBMS_XDB.SetHTTPPort(80)
 
SQL> -- to disable HTTP XDB protocol port
SQL> EXECUTE DBMS_XDB.SetHTTPPort(0)

After you have enabled the protocol listener you are now able to mount a (hopefully empty, in this case “/home/oracle/dav”) directory created for this purpose via an /etc/fstab entry like (check the last entry):

[oracle@localhost .davfs2]$ cat /etc/fstab
LABEL=/                 /                       ext3    defaults        1 1
LABEL=/home             /home                   ext3    defaults        1 2
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
LABEL=SWAP-hda2         swap                    swap    defaults        0 0
http://localhost:80     /home/oracle/dav        davfs   noauto,users    0 0

and then mount or u(n)mount the database XDB Repository via

 
[oracle@localhost .davfs2]$ mount /home/oracle/dav
Please enter the username TO authenticate WITH server
http://localhost:80 OR hit enter FOR NONE.
  Username: system
Please enter the password TO authenticate USER system WITH server
http://localhost:80 OR hit enter FOR NONE.
  Password:
 
[oracle@localhost .davfs2]$ umount /home/oracle/dav
/sbin/umount.davfs: waiting while mount.davfs (pid 4308) synchronizes the cache .. OK

After mounting the XDB database Repository this will show a directory structure, via a linux/unix on the prompt, for instance like the following:

[oracle@localhost .davfs2]$  mount /home/oracle/dav
Please enter the username TO authenticate WITH server
http://localhost:80 OR hit enter FOR NONE.
  Username: system
Please enter the password TO authenticate USER system WITH server
http://localhost:80 OR hit enter FOR NONE.
  Password:
[oracle@localhost .davfs2]$ cd /home/oracle/dav
 
[oracle@localhost dav]$ ls
home  images  lost+found  olap_data_security  OLAP_XDS  
public  publishedContent  sys  xdbconfig.xml  xds  XFILES
 
[oracle@localhost dav]$ ls -l
total 0
drwxr-xr-x  5 oracle oracle 0 Jul 19 10:46 home
drwxr-xr-x 23 oracle oracle 0 Aug 13  2009 images
drwx------  2 oracle oracle 0 Sep 13 08:34 lost+found
drwxr-xr-x  3 oracle oracle 0 Aug 13  2009 olap_data_security
drwxr-xr-x  2 oracle oracle 0 Aug 13  2009 OLAP_XDS
drwxr-xr-x  2 oracle oracle 0 Jul 25 12:44 public
drwxr-xr-x  3 oracle oracle 0 Jul 19 10:46 publishedContent
drwxr-xr-x 13 oracle oracle 0 Jul 19 10:45 sys
-rw-r--r--  1 oracle oracle 0 Jul 19 13:32 xdbconfig.xml
drwxr-xr-x  3 oracle oracle 0 Aug 13  2009 xds
drwxr-xr-x 11 oracle oracle 0 Jul 19 14:01 XFILES

An alternative would be to do it manual. Mounting file systems is only allowed via root or having the proper *nix privileges. Being root you could mount the wanted XFILES virtual database directory so the Tomcat APEX 4 installation would be able to access it via:

[oracle@localhost bin]$ su -
Password:
 
[root@localhost ~]# umount /home/oracle/dav
/sbin/umount.davfs: waiting while mount.davfs (pid 4699) synchronizes the cache .. OK
 
[root@localhost ~]# mkdir /home/oracle/apache-tomcat-6.0.20/webapps/ROOT/XFILES
[root@localhost ~]# chmod 777 /home/oracle/apache-tomcat-6.0.20/webapps/ROOT/XFILES
[root@localhost ~]# chown oracle:oinstall /home/oracle/apache-tomcat-6.0.20/webapps/ROOT/XFILES
 
[root@localhost ~]#  mount -t  davfs  http://localhost:80/XFILES /home/oracle/apache-tomcat-6.0.20/webapps/ROOT/XFILES
Please enter the username TO authenticate WITH server
http://localhost:80/XFILES OR hit enter FOR NONE.
  Username: XFILES
Please enter the password TO authenticate USER XFILES WITH server
http://localhost:80/XFILES OR hit enter FOR NONE.
  Password:
 
[root@localhost ~]# exit
 
[oracle@localhost ~]$ cd
[oracle@localhost ~]$ cd apache-tomcat-6.0.20/
[oracle@localhost apache-tomcat-6.0.20]$ cd webapps/
[oracle@localhost webapps]$ cd ROOT/
 
[oracle@localhost ROOT]$ cd XFILES/
 
[oracle@localhost XFILES]$ ls
authenticationStatus.xml  common  KML  lib  lite  loading.gif  
logo.png  lost+found  resConfig  unauthenticated.xml  WebDemo  
WebServices  whoami.xml  Xinha  XMLSearch
 
[oracle@localhost XFILES]$ ls -l
total 23
-rw-r--r--  1 root root    17 Jul 19 10:50 authenticationStatus.xml
drwxr-xr-x  4 root root     0 Jul 19 10:49 common
drwxr-xr-x  7 root root     0 Jul 19 10:50 KML
drwxr-xr-x  4 root root     0 Jul 19 10:50 lib
drwxr-xr-x  5 root root     0 Jul 19 10:49 lite
-rw-r--r--  1 root root 10819 Jul 19 10:49 loading.gif
-rw-r--r--  1 root root 10220 Jul 19 10:49 logo.png
drwx------  2 root root     0 Sep 13 10:24 lost+found
drwxr-xr-x  2 root root     0 Jul 19 10:49 resConfig
-rw-r--r--  1 root root    19 Jul 19 10:50 unauthenticated.xml
-rw-r--r--  1 root root     0 Jul 19 14:01 vaartserijnstraat_utrecht.xml
drwxr-xr-x  4 root root     0 Jul 19 10:50 WebDemo
drwxr-xr-x  4 root root     0 Jul 19 10:50 WebServices
-rw-r--r--  1 root root    15 Jul 19 10:50 whoami.xml
drwxr-xr-x 13 root root     0 Jul 19 12:41 Xinha
drwxr-xr-x  6 root root     0 Jul 19 10:50 XMLSearch

Have fun with your mounted database as a file server set-up.