How to permanently mount a Nextcloud Webdavfolder using the terminal

I was looking for a way to achieve this for several Virtual Machines: VirtualPrivateServer and local VirtualBox, in order to replace Dropbox and Rsync. These servers run backups creating tar.gz files from directories, sqldatabase dumps, and copy configuration and installation files, triggered by crontab. Space is limited so these files do not change name, they are overwritten and just their size and/or timestamp are changed. I used to manage versions on a local machine running BackInTime. Nextcloud has it’s own version controle, so BackInTime is no longer required either.

With a NextCloudPi folder mounted permanently, I address all of the requirement in a single solution. Here is how I did it.

Install davfs2

sudo apt-get install davfs2

Add a line to fstab using

sudo nano /etc/fstab
https://nextcloudpi.mydomain.org:xx43/remote.php/webdav/MYbackups/ /media/backups davfs defaults,uid=username,gid=groupname,_netdev,auto 0 0

Add your user to the correct group:

sudo usermod -a -G davfs2

Create mountpoint

sudo mkdir /media/backups

Add mountpoint, user and password to davfs2 configuration file

sudo echo “/media/backups/ username password” >> /etc/dav2fs/secrets

Mount the webdav folder

sudo mount /media/backups

Check if mounted

df -h

NextCloudPi WebDav folder mounted

I now have an additional 80GB of space available to my virtual machine, so I can backup to my hearts content. I can also revert to any version by restoring it to a an earlier version from Nextcloud file manager.

NCP-VersionControl

:wink: