These are some reference notes I put together for mounting WebDAV volumes via the command-line.
About six months ago I switched from Wordpress to Jekyll to maintain this blog. Consequently, I saved a couple of bucks by cancelling my full-featured web hosting service and switching to the simple file publishing offered by my Fastmail.fm account.
Fastmail doesn’t offer ssh access, so files must be transferred by FTP or WebDAV. I wanted fully scripted deploys for my Jekyll site, and started off using FTP with the NcFTP client.
The problem with FTP was that my entire site was uploaded every time, even if most of it was unchanged. This wasn’t that big of a deal because I don’t have too many files, but it bothered me knowing that a better solution was available if I could just mount my Fastmail directory via WebDAV and then rsync everything over.
One thing worth noting is that rsync normally looks at both the modification time and the size of each file in the set to determine whether or not it needs to be copied to the destination directory. Because Jekyll always regenerates every file, the modification times are always updated. This causes rsync to copy your entire site over to the destination and subverts one of the best features of rsync - the speedup you get from only syncing diffs.
The way to get around this is to use the
--size-only flag. This causes rsync to ignore timestamps. Most of the time this shouldn’t be a problem, unless you make minor edits to a file that doesn’t cause a change in file size.
rsync -rvz --size-only --delete "~/mysite_src/" "/mnt/webdav/mysite_dest"
I use Ubuntu and OS X. There’s a different solution for each. Here are my notes.
sudo apt-get install davfs2
To mount as a non-root user:
Note: Must run
dpkg-reconfigure davfs2 according to /usr/share/doc/davfs2/README.Debian to get around “/sbin/mount.davfs: program is not setuid root” issue when trying to mount as non-root user.
ignore_home kernoops to /etc/davfs2/davfs2.conf to get around the “/sbin/mount.davfs: / is the home directory of user kernoops” error.
Add an entry in fstab:
http://example.org/dav /media/dav davfs noauto,user 0 0
Add your user to the davfs group:
sudo adduser <user> davfs
Make sure WebDAV connection credentials are in ~/.davfs2/secrets with restrictive permissions (
/media/dav webdav-username password
mount /media/dav umount /media/dav
mount_webdav exists but is unreliable. Could not get workarounds to work for password-protected WebDAV resource.
The best thing to do is first mount the WebDAV volume manually. In the Finder, hit Command+K to connect to the server. When prompted for credentials, allow them to be saved in the keychain.
Then, launch Automator and create a workflow that simply consists of the action “Connect to Servers”. Save the workflow to disk.
The Automator workflow can be run from the command-line via:
automator -i "https://webdav.example.com" <workflow> > /dev/null 2>&1
The -i parameter specifies input to the workflow. See
automator command-line utility printed a bunch of warnings about certain additions that couldn’t be loaded. That’s why the output is directed to
Note: The workflow is itself a folder. The folder can be given as the argument to automator. Within the main workflow folder, there is a subfolder called
Contents with a file called
document.wflow. This file can be passed directly to the
automator command-line program, and the containing folders can be ditched.