// Tutorial //

How To Move the Data Directory for ownCloud on Ubuntu 16.04

Published on August 29, 2016 · Updated on October 19, 2016
Default avatar
By Michael Lenardson
Developer and author at DigitalOcean.
How To Move the Data Directory for ownCloud on Ubuntu 16.04

Introduction

ownCloud is a capable solution for storing your digital life on a private server. By default, data is saved on the same partition as the operating system, which may lead to a lack of free disk space. For instance, with high-resolution pictures and high-definition videos continuously being backed up, it is easy to run out of space. As your storage needs grow, it may become necessary to move ownCloud’s data directory. Whether you are adding more space or just looking to change the default storage location, this tutorial will guide you through relocating ownCloud’s data directory.

Prerequisites

Before you begin using this guide, an ownCloud server needs to be installed and configured. You can set one up by following this guide. If our installation guide was used, then the data directory is in ownCloud’s web root, which by default is located at /var/www/owncloud.

In this example, we are moving ownCloud’s data directory to an attached additional storage volume that is mounted at /mnt/owncloud. If you are using DigitalOcean, you can mount a block storage volume to fulfill that role by following our How To Use Block Storage on DigitalOcean guide.

Regardless of the underlying storage being used, this guide can help you move the data directory for ownCloud to a new location.

Step 1 – Moving the ownCloud Data Directory

When ownCloud is in use and backend changes are being made, there is the possibility that data may become corrupt or damaged. To prevent that from happening, we will stop Apache with the systemctl utility:

  1. sudo systemctl stop apache2

Some of the service management commands do not display an output. To verify that Apache is no longer running, use the systemctl utility with the status command:

  1. sudo systemctl status apache2

The last line of the output should state that it’s stopped.

Output
. . . Stopped LSB: Apache2 web server.

Warning: It is highly recommended that you backup your data prior to making any changes.

Copy the contents of the data directory to a new directory using the rsync command. Using the -a flag preserves the permissions and other directory properties, while the -v flag provides verbose output so you can monitor the progress. In the example below, we back up our content into a new directory, owncloud-data-bak, within our user’s home directory.

  1. sudo rsync -av /var/www/owncloud/data/ ~/owncloud-data-bak/

  With Apache stopped, we will move the data directory to the new location using the mv command:

  1. sudo mv /var/www/owncloud/data /mnt/owncloud/

With the data directory relocated, we will update ownCloud so that it’s aware of this change.

Step 2 – Pointing ownCloud to the New Data Location

ownCloud stores its configurations in a single file, which we will edit with the new path to the data directory.

Open the file with the nano editor:

  1. sudo nano /var/www/owncloud/config/config.php

Find the datadirectory variable and update its value with the new location.

/var/www/owncloud/config/config.php
. . .
  'datadirectory' => '/mnt/owncloud/data',
. . .

With the data directory moved and the configuration file updated, we are ready to confirm that our files are accessible from the new storage location.

Step 3 – Starting Apache

Now, we can start Apache using the systemctl command and regain access to ownCloud:

  1. sudo systemctl start apache2

Finally, navigate to the ownCloud web interface:

https://server_domain_or_IP/owncloud

ownCloud is a web application and does not have a way to verify the integrity of its configuration. Therefore, access to the web interface means the operation was successful.

Conclusion

In this tutorial, we expanded the amount of disk space available to ownCloud. We accomplished this by moving its data directory to an additional storage volume. Although we were using a block storage device, the instructions here should be applicable for relocating the data directory regardless of the technology being used.


Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in our Questions & Answers section, find tutorials and tools that will help you grow as a developer and scale your project or business, and subscribe to topics of interest.

Sign up
About the authors
Default avatar
Developer and author at DigitalOcean.

Still looking for an answer?

Was this helpful?
7 Comments

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Do NOT use this instruction, you will get an error

“Your Data directory is invalid Please check that the data directory contains a file “.ocdata” in its root.”

Use this https://doc.owncloud.org/server/10.0/admin_manual/maintenance/manually-moving-data-folders.html

FIXED, but WHY? It has been a big frustration to move Owncloud /data directory to a second hard drive…

my owncloud/config/config.php file now has these entries.

1 ) ‘datadirectory’ => ‘/var/www/html/owncloud/data’,

  1. ‘datadirectory’ => ‘/media/family/data6GB/owncloud/data1’,

  2. ‘datadirectory’ => ‘/mnt/082e0dbc-3463-43a8-b267-dcecd879abe0/owncloud/data1’,

  3. Original on the boot SSD, I needed more space so I wanted to move the data dir to new HD

  4. The mount point of my second HHD in Ubuntu - I worked 48hrs to get this to work with no success

  5. This is the information I found in Ubuntu gui file browser, right click on datat1 dir > properties > “Location:”. I just thought to give it a shot and insert this in the config file and it worked!

Can anyone explain what is going on? I’m new to linux and the only reason I go through all this trouble is to set up my own NAS with OneCloud.

I have set up my partitions using the gui tool Disks. The ext4 partition is set to mount on startup

Step 1 – Moving the ownCloud Data Directory

The correct command is:

mv /var/www/owncloud/data /mnt/owncloud/data

Great tutorial. Is there any reason why you didn’t do a ‘cp’ instead of a ‘mv’ + ‘rysnc’ in Step 1, and then once confirmed that the copied data directory was functioning properly, then deleted the original directory? This is the approach I took (mostly because I didn’t have enough space in my droplet to do the data duplication!) and can report that it’s functioning correctly, The only change I had to make was to chgrp/chown to the permissions per the original as they copied over as root.

This comment has been deleted

nice. Does this also work for Nextcloud?