Move Nextcloud Data to an External Drive Without Breaking Storage

For a conventional Linux install, mount the external drive persistently, copy the complete data directory while Nextcloud is offline, then symlink the original path to the new location. Do not simply change datadirectory in config.php: Nextcloud tracks local storage by absolute path, so a direct path change can orphan files and shares.

This example assumes a package or archive install. Docker, Snap, and appliance installs map paths differently; adapt the mount to that deployment instead of copying these host paths blindly.

What is confirmed, and what depends on your server

PointWhat to do
Verified: Nextcloud uses the absolute path to identify local storage. A careless move can orphan files or shares.Keep the configured path stable with a symlink; preserve all contents, including .ncdata.
Setup-dependent: data path, HTTP user, filesystem, and service names vary.Check your effective config and confirm the disk preserves required Linux ownership and permissions.
Disk-dependent: reliable boot mounting and power cannot be assumed.Mount it by UUID, test the mount after reboot, and prevent Nextcloud from starting when the data disk is absent.

The Files app’s external-storage mount adds a secondary location; it does not move the primary data directory. Use it for an extra folder or share, and migrate the data directory when the server’s own files and metadata must live on the drive.

1. Back up Nextcloud and identify the source path

Back up the database, config/, data directory, custom apps, and themes. Confirm the database backup is restorable; copying files alone is not a complete rollback.

Find the data path in config/config.php or with occ config:system:get datadirectory, then identify the HTTP user. Examples use www-data and /var/www/nextcloud/data; substitute your actual values. Do not format a drive containing files you need.

A Linux disk utility showing a selected external drive, an ext4 filesystem, and a mount-point field
Illustration: a disk utility view shows the external drive and filesystem details to confirm before mounting it for Nextcloud.

2. Mount the drive at a stable path

Run lsblk -f and note the partition’s filesystem UUID. Names such as /dev/sdb1 can change, so use the UUID in the mount configuration.

For a Linux server using ext4, create a mount point and add a line like this to /etc/fstab, replacing the sample UUID with the actual one:

UUID=YOUR-DRIVE-UUID /srv/nextcloud-disk ext4 defaults 0 2

Use the type already on the partition; this line does not format it. Verify that the filesystem preserves ownership and permissions Nextcloud needs.

Mount and verify it before placing any data on it:

sudo mkdir -p /srv/nextcloud-disk
sudo mount /srv/nextcloud-disk
findmnt /srv/nextcloud-disk

Confirm the output identifies the external partition. If using nofail, also gate web/PHP services on the mount; otherwise a missing disk may leave an empty mount-point directory that receives writes. A systemd drop-in can use RequiresMountsFor=/srv/nextcloud-disk. Keep the drive connected while Nextcloud runs.

A terminal editor showing a UUID-based filesystem entry for a mounted external volume
Illustration: a UUID entry in the filesystem table represents a persistent mount configuration rather than a device-name shortcut.

3. Put Nextcloud in maintenance mode and copy the data

Maintenance mode blocks logins but does not stop every scheduled job. Pause Nextcloud cron or its systemd timer, stop sync clients, and stop web/PHP services before copying so no requests change files mid-move.

sudo -E -u www-data php /var/www/nextcloud/occ maintenance:mode --on

With the scheduler disabled and web/PHP services stopped, copy the data directory as root to preserve ownership, permissions, ACLs, and hidden files:

sudo mkdir -p /srv/nextcloud-disk/data
sudo rsync -Aavx --numeric-ids /var/www/nextcloud/data/ /srv/nextcloud-disk/data/

The trailing slash copies directory contents. Keep the old copy; check rsync for errors and confirm .ncdata is present at the new directory’s top level.

A dark terminal window showing a file-copy command with progress rows
Illustration: a terminal copy view represents transferring the complete data directory while Nextcloud is stopped.

4. Preserve the old path with a symlink

Nextcloud’s troubleshooting manual recommends linking the original path to the new directory. After verifying the copy, rename the old directory for rollback and create the link:

sudo mv /var/www/nextcloud/data /var/www/nextcloud/data.pre-move
sudo ln -s /srv/nextcloud-disk/data /var/www/nextcloud/data
readlink -f /var/www/nextcloud/data

Confirm the path resolves to /srv/nextcloud-disk/data. The web user must traverse parent directories and read .ncdata and write to the target:

sudo -u www-data test -r /var/www/nextcloud/data/.ncdata
sudo -u www-data test -w /var/www/nextcloud/data

If a check fails, correct ownership or parent permissions for your web user; do not make the directory world-writable. Some web servers must allow symlinks. If that is not possible, do not edit oc_storages manually: Nextcloud calls that method unsupported and warns it can break the database.

A terminal with move and symlink commands, followed by a path inspection line
Illustration: the terminal view shows the original data path being linked to the external-drive directory.

5. Restart and verify before removing the rollback copy

Start web/PHP and re-enable the scheduler. Confirm the mount and symlink, then turn off maintenance mode:

findmnt /srv/nextcloud-disk
sudo -E -u www-data php /var/www/nextcloud/occ status
sudo -E -u www-data php /var/www/nextcloud/occ maintenance:mode --off

Sign in, open existing files and shares, and upload/download a small file. Check Nextcloud and web-server logs, then reboot in a maintenance window to confirm the disk mounts before Nextcloud starts.

Keep data.pre-move and the database backup until reboot and normal sync succeed. If the move fails, enable maintenance mode, stop the app, and restore the original directory and service state. A broad files:scan cannot fix a wrong mount.

Verification

Verify the disk mounts at boot, the original path resolves to it, the web user can read and write, and existing files plus a small upload work. If Nextcloud reports missing files after reboot, stop the app and check the mount before allowing writes.

References: Nextcloud guidance for moving the data directory; Nextcloud backup and maintenance mode guidance; Nextcloud data-directory location and ownership; Nextcloud external storage as a secondary mount; Linux mount documentation for UUID identifiers; systemd mount dependencies.

Leave a Comment

Move Nextcloud Data to an External Drive Without Breaking Storage

Move Nextcloud Data to an External Drive Without Breaking Storage

Safely move a Linux Nextcloud data directory to an external drive using a persistent UUID mount, maintenance mode, a verified copy, and the original-path symlink.

Nextcloud Database Error After an Update: What to Check First

Restore Nextcloud access after an update by diagnosing SQL errors, checking database connectivity, and safely completing interrupted migrations.

Reset a Lost Nextcloud Admin Password with OCC

Use Nextcloud’s OCC command to reset an administrator password from the server shell, with guidance for usernames, permissions, and external login providers.

Add the HSTS Header at the HTTPS Endpoint Serving Nextcloud

Clear Nextcloud’s HSTS warning by setting the header at Apache, NGINX, or your TLS proxy, then verify the public HTTPS response safely.

Troubleshoot Nextcloud App Installs That Report No Internet

Troubleshoot Nextcloud App Installs That Report No Internet

Trace App Store installation failures to DNS, HTTPS, proxy, TLS, or configuration issues from the Nextcloud server itself.

Tame Nextcloud Preview CPU Spikes with a Scheduled Queue

Move thumbnail work to a controlled background schedule, trim unused preview sizes, and verify the queue without overwhelming your Nextcloud server.

Get Nextcloud Desktop Sync Moving Past “Processing Files”

Find the file, exclusion rule, connection issue, or client database state holding up Nextcloud sync, then verify uploads and downloads safely.

Clear the Nextcloud OPcache Warning by Adjusting the Right Limit

Find the PHP OPcache limit triggering Nextcloud’s warning, update the correct web PHP configuration, restart safely, and verify the result.

Connect Nextcloud to CODE Docker: Setup and Tradeoffs

Connect Nextcloud to CODE Docker: Setup and Tradeoffs

Compare built-in and Docker-based CODE, then connect Collabora Online to Nextcloud through a secure HTTPS reverse proxy.

Build a Resilient Nextcloud Cluster with Galera

Plan a reliable Nextcloud HA deployment with shared storage, Redis locking, quorum-aware MariaDB routing, and practical failover checks.