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
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
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.
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
- 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
- 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.
- 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
- sudo mv /var/www/owncloud/data /mnt/owncloud/
data directory relocated, we will update ownCloud so that it’s aware of this change.
ownCloud stores its configurations in a single file, which we will edit with the new path to the
Open the file with the
- sudo nano /var/www/owncloud/config/config.php
datadirectory variable and update its value with the new location.
. . . 'datadirectory' => '/mnt/owncloud/data', . . .
data directory moved and the configuration file updated, we are ready to confirm that our files are accessible from the new storage location.
Now, we can start Apache using the
systemctl command and regain access to ownCloud:
- sudo systemctl start apache2
Finally, navigate to the ownCloud web interface:
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.
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.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
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 now
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!
What about database entries? https://help.nextcloud.com/t/is-there-a-safe-and-reliable-way-to-move-data-directory-out-of-web-root/3642
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’,
‘datadirectory’ => ‘/media/family/data6GB/owncloud/data1’,
‘datadirectory’ => ‘/mnt/082e0dbc-3463-43a8-b267-dcecd879abe0/owncloud/data1’,
Original on the boot SSD, I needed more space so I wanted to move the data dir to new HD
The mount point of my second HHD in Ubuntu - I worked 48hrs to get this to work with no success
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?