How to use davfs to bulk copy files to Nextcloud

If you want to transfer many gigs of data to a Nextcloud server, you probably want to use the command line instead of a browser. This quick HOWTO is an overview of using davfs2 to get the job done.

(Condensed and enhanced from here https://docs.nextcloud.com/server/latest/user_manual/en/files/access_webdav.html)

Steps:

Install the software

yum install davfs

Create mount directory

mkdir ~/nextcloud

Create a credentials directory

mkdir ~/.davfs2

Copy the default secrets file

cp /etc/davfs2/secrets ~/.davfs2

chmod 600 ~/.davfs2/secrets

Edit secrets file

Add information about the local mount point and the remote Nextcloud username and password that’s you’ll be logging into:

mc -e ~/.davfs2/secrets

/home/user/nextcloud    username    password

Note: I wasn’t very successful with this, every time I tried to mount I *still* had to type the username and password.

Fix locks

When you start bulk copying, you might see it copy directories but fail on every single file. In the install document they refer to Resource temporarily available and this worked for me:

mc -e /etc/davfs2/davfs2.conf

use_locks 0

Add your Linux user to the davfs2 group

usermod -aG davfs2 root

You’ll get 404 errors if you don’t.

Mount the disk

sudo mount -t davfs https://cloud.example.com/remote.php/dav/files/username/ ~/nextcloud

umount the disk

umount ~/nextcloud

This didn’t work for me, in spite of the /etc/fstab entry as stated below:

mount ~/nextcloud

/etc/fstab had this:

# Nextcloud mount
https://cloud.example.com/nextcloud/remote.php/dav/files/username/ /home/username/nextcloud davfs user,rw,auto 0 0

Troubleshooting

Certificate issues

I kept on getting certificate warning when trying to mount. It turns out I was using a really old CentOS 6 or 7 box and root certificates weren’t up to date. Make sure your root certificates are up to date:

yum install ca-certificates

You should see “update” somewhere when you run this.

Certificate issue two

I also had a problem that it didn’t understand the Let’s Encrypt and kept on thinking it had expired. I found a great solution on Stack that allow you to grab a remote cert and store it locally:

openssl s_client -connect cloud.bs-inc.co.za:443 -showcerts </dev/null 2>/dev/null | openssl x509 -outform PEM > certificate.pem

mv certificate.pem /etc/davfs2/certs/certificate.pem

Job Status

If you’re doing this work from another Linux server to your Nextcloud instance, you probably want to run the job in the background.

The command is probably something like cp -ru * /mnt/usb/backup /home/username/nextcloud &

If you have to see the job, do this:

jobs

If you want to bring the job to the foreground, do this:

fg %# e.g. fg %1

 

Share this article

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top