Manually Move the Data Directory

Introduction

Use these instructions if you intend to move your ownCloud’s data directory from its current location to another without using a symbolic link.

As ownCloud is deployed via Docker, it is easy to move any data for a Dockerised deployment, as this simply involves relocating the contents of the mount point. Additional steps need to be taken into account when upgrading from a standard installation to Docker because the database needs to be updated.

This guide assumes that:

  • The current Docker volume folder is: <mount-point>/oc

  • The new Docker volume folder is: <mount-point>/oc-new

  • ownCloud’s database name is owncloud

  • For a standard installation, the data directory is var/www/owncloud/data

  • The internal "data folder of a Dockerized installation is /mnt/data/files

Please change the paths above to reflect your environment.

Summary

The following steps are necessary to move the data directory.

  1. Stop the web proxy server

  2. Enable maintenance mode

  3. Sync your Data directory

  4. Adjust ownCloud’s configuration

  5. Check permissions

  6. Disable maintenance mode

  7. Start the web proxy server

Look at each section below for a detailed description.

Stop the Web Proxy Server

To ensure there are no active user connections to your ownCloud instance, stop access to it from the web proxy server. Follow the web proxy server description to find out how to do this.

Enable Maintenance Mode

It is necessary to enable maintenance mode to avoid running cron jobs. To enable maintenance mode, run the following command.

docker compose exec owncloud occ maintenance:mode --on

Sync your Data Directory

sudo rsync -avz <mount-point>/files /mnt/<new-target>

Make sure that .ocdata and .htaccess were synced to the new directory.

ls -a | grep -i "^\.[A-Z]"

Adjust ownCloud’s configuration

Adjust oc_storages table

Connect to your database and enter following commands:

use owncloud;

Update the oc_storages Table

Run the SQL below:

UPDATE oc_storages
  SET id='local::/mnt/owncloud/data/'
  WHERE id='local::/var/www/owncloud/data/';

Update the oc_accounts Table

You next need to update the home column in the oc_accounts table. This column contains the absolute path for user folders, e.g., /mnt/owncloud/data/my_user.

If a user does not have the path already set, you have to identify the users id and set the path with the following command, user by user. This example assumes the user name is my_user and their id is 1. Note that id’s are incremental, meaning the account you created first will have id 1 and so on.

Run the SQL below:

UPDATE oc_accounts SET home='/mnt/owncloud/data/my_user'
  WHERE id=1;

For all users who already have a path like /var/www/owncloud/data/ in your database, you can use the REPLACE command:

UPDATE oc_accounts
  SET home = REPLACE(
    home,
    '/var/www/owncloud/data/',
    '/mnt/owncloud/data/'
  );

For more information follow the complete MySQL REPLACE command syntax.

Please don’t copy and paste this example verbatim — nor any of the others. They are examples only.

Update the oc_jobs table

The next area to check is the oc_jobs table. The logrotate process may have hard-coded a non-standard (or old) value for the data path. To check it, run the SQL below and see if any results are returned:

SELECT * FROM oc_jobs
  WHERE class = 'OC\Log\Rotate';

If results are returned, run the SQL below to update them, changing the id value as appropriate.

UPDATE oc_jobs
  SET argument = REPLACE(
    argument,
    '\\/var\\/www\\/owncloud\\/data\\/',
    '\\/mnt\\/owncloud/data\\/'
  )
  WHERE id = <id of the incorrect record>;
The old data path will be written with \/. Therefore you must add one, additional, backslash, like this: \\/.

Fix the config.php Settings

To fix the config.php settings:

docker compose exec owncloud occ config:system:set --value /mnt/owncloud/data datadirectory

Adjust config.php

  1. Change the datadirectory key in your config.php to the new path. To do so, start an editor of your choice and open /var/www/owncloud/config/config.php

  2. Change the value of the key from 'datadirectory' ⇒ '/var/www/owncloud/data', to 'datadirectory' ⇒ '/mnt/owncloud/data',.

Disable Maintenance Mode

To disable maintenance mode of your instance run the following command:

docker compose exec owncloud occ maintenance:mode --off

Start the Web Proxy Server

Follow the web proxies server description for how to enable access to teh ownCloud instance.

Scan the Files

docker compose exec owncloud occ files:scan --all