Ubuntu Upgrade and Box.com Sync

A mounted Box.com drive and duply are a good combination for backup data to a remote location. Duply allows for encrypted backups, and the encryption also helps to prevent bit rot. A remote drive is useful for keeping cloud-based servers free of extraneous data, which is especially useful when paying per GB per month for storage.

My problem started after I upgraded Ubuntu. Apparently, I used a the default configuration for davfs2 instead of my custom configuration, which caused a few errors. But I also learned a few things:

To use Box.com, you must have an appropriately sized cache and disable file locking in the davfs2 config.

To set this up, edit the config: sudo nano /etc/davfs2/davfs2.conf

Add these two lines anywhere (preferably under the commented out section or at the bottom):

use_locks 0
cache_size 100
  • File locking should be disabled for Box, as it is not compatible. Files can be written to on the server while they are being uploaded to Box, and vice versa, but your timed sync/backup strategy should prevent this.
  • Box.com is limited to files of around 50 MB, and duply defaults to 25 MB, so a cache of 100 MB is certainly safely over the limits.
If a mounted drive cannot be written to, the davfs2 cache will grow (very large).

In my case, it was up to around 9 GB. Check to see what’s going on with journal ctl: sudo journalctl -b | grep mount or something like journalctl -u davfs2 --since today. You might see a message like open files exceed max cache size. Then check the configuration of davfs2 to increase the cache size and see if locking is enabled, as detailed above.

The davfs2 cache can be deleted safely if a drive is unmounted.

Unmount using umount /LOCATION/NAME

If a drive is busy, it can’t be unmounted. You can force an unmount (with chance of data corruption) using umount -f or umount -l, but it’s better to identify and kill the processes using the drive:

  1. lsof | grep '/dev/sda1' (change /dev/sda1 to the mounted drive name)
  2. pkill target_process (kills busy proc. by name | kill PID | killall target_process)
  3. umount /dev/sda1

How do you set up a duply and Box.com backup? I think I wrote about it before, but if not, here are some links: 1, 2
Other resources: 1, 2 , 3, 4, 5

 

 

Someone apparently made a script that can be used to set up a Box.com mount, too, although it mounts to a location under the /home/USER folder:

#!/bin/bash
## davfs2 installation and Box.com account configuration script for Linux
## Tested on Ubuntu, Fedora and OpenSuse
## Update 1.032615

## This script must be run as root
if [ ! $UID = 0 ]; then
    echo "This script needs super user privileges to run"
    echo "run it againg using sudo or login as root"
    exit 1
fi


TTY=$(tty | sed -e 's:/dev/::')

## get current user:
auser=$(w | grep $TTY | awk {'print $1'})
uhome=/home/$auser

## Remove option:
if [ "$1" = '-r' ]; then
  echo "Removing credentials.."
  echo > "$uhome/.davfs2/secrets"
  echo "Removing mount point.."
  sed -i "/$auser@box/d" /etc/fstab
  echo "Removing symlink.."
  unlink /home/$auser/Box
  echo "Done. Exiting.."
  exit 0
elif [ -z "$1" ]; then
  :
else
  echo "Usage:"
  echo "box-linux     |  Configure a Box account"
  echo "box-linux -r  |  Remove Box configuration"
  exit 1  
fi


## determine OS type and install davfs2:
os_type() {
  if [ -f /usr/bin/yum ]; then  ## RH based distros
    yum -y install fuse-davfs2 davfs2
    ## Double check if davfs2 was installed (for some RH based systems):
    if [ ! -d /etc/davfs2 ]; then
     echo "ERROR: davfs2 was not found." 
     echo "Exiting without making any changes."
     exit 1
    fi
  elif [ -f /usr/bin/dpkg ]; then  ## Debian based distros
    apt-get -y install davfs2
    dpkg-reconfigure davfs2
  elif [ -f /usr/bin/zypper ]; then  ## openSuse
    zypper ar -G http://download.opensuse.org/repositories/filesystems/openSUSE_Factory /openSUSE_Factory-filesystems
    zypper -n install davfs2
  fi
}

echo "==========================================================="
echo "           This script will install davfs2"
echo "           and create a local mount point  "
echo "              for your Box.com account."
echo "    **Choose Yes if asked to allow users to mount WebDAV**   "
echo "==========================================================="
echo ""
echo -n "Proceed with the installation? [Y/n]: "
read -p "$1" STARTINSTALL

if [ ! "$STARTINSTALL" == "Y" ]; then
  echo "Installation aborted."
  exit 1
else
  :
fi

## user input:
echo "Please enter your Email address: "
read -p "$1" EMAIL
echo -n "Please enter your Box password: "
read -s PASSWORD
echo ""
echo "==========================================================="

## check if davfs2 is installed:
if [ -d /etc/davfs2 ]; then 
  :
else
  os_type
fi

## check if Box dir exists in users' Home:
if [ -d /home/$auser/Box ]; then
  echo -n "Box already exists, would you like to update your login details? [Y\n]: "
  read ANSWER
  if [ ! "$ANSWER" == "Y" ]; then
    echo  "Nothing to do. Exiting.."
    exit 1
  else
    echo  "https://dav.box.com/dav $EMAIL $PASSWORD" > $uhome/.davfs2/secrets
    echo "Done. Exiting.."
    exit 0
  fi
else 
  ## add user the davfs2 group:
  echo "Adding $auser to davfs2 group.."
  usermod -a -G davfs2 $auser
  ## create folders:
  su - $auser -c "mkdir $uhome/.davfs2"
  mkdir /media/$auser@box
  ## write conf files:
  echo "writing configuration.."
  echo "dav_group   davfs2" > /etc/davfs2/davfs2.conf
  echo "use_locks   0" >> /etc/davfs2/davfs2.conf
  if [ -f /etc/lsb-release ]; then
    if grep --quiet Ubuntu /etc/lsb-release ; then
      echo "#ignore_home    kernoops" >> /etc/davfs2/davfs2.conf
    fi
  fi
  echo  "https://dav.box.com/dav $EMAIL $PASSWORD" > $uhome/.davfs2/secrets
  chown $auser:$auser $uhome/.davfs2/secrets
  chmod 600 $uhome/.davfs2/secrets
  ## write mount point to fstab:
  if grep --quiet /media/$auser@box /etc/fstab ; then
    :
  else
    echo "## Box" >> /etc/fstab
    echo "https://dav.box.com/dav /media/$auser@box davfs _netdev,defaults,rw,users,noauto 0 0" >> /etc/fstab
  fi
fi

## create rsync script
if [ -f $uhome/.boxsync ]; then
  :
else
   echo "#!/bin/bash" > $uhome/.boxsync
   echo "if grep --quiet box /etc/mtab ; then" >> $uhome/.boxsync
   echo "  :" >> $uhome/.boxsync
   echo "else" >> $uhome/.boxsync
   echo "  mount /media/$auser@box" >> $uhome/.boxsync
   echo "fi" >> $uhome/.boxsync
   echo "rsync -au /source /media/$auser@box" >> $uhome/.boxsync
fi

chown $auser:$auser $uhome/.boxsync
chmod +x $uhome/.boxsync

## Create a symlink
ln -s /media/$auser@box $uhome/Box
chown $auser:$auser $uhome/Box

##
echo "Done."
echo "==========================================================="
echo "       Re-login to apply the changes: su - $auser          " 
echo "         Then Mount your Box folder by accessing           "
echo "       /media/$auser@box from your file manager.           "
echo "       a shortcut was created at /home/$auser/Box          "
echo "==========================================================="
echo "       a pre-configured script for rsync is at             "
echo "       $uhome/.boxsync              "
echo "       edit the source/destination path to suit your needs "
echo "==========================================================="


exit 0