Moving a Next Cloud Datastore

this is particularly useful if you've used turnkey linux, or if you've installed nextcloud on a VM and want to move the storage to a NAS

ref: https://help.nextcloud.com/t/howto-change-move-data-directory-after-installation/17170

turn maintenance mode on for nextcloud:

sudo -u www-data php /path/to/nextcloud/occ maintenance:mode --on

make a new directory for your data, copy your data to it, and have nextcloud's user take ownership:

mkdir -p /new/path/to/data
cp -a /path/to/data/. /new/path/to/data
chown -R www-data:www-data /new/path/to/data

modify nextcloud config to point to this new path:

nano /path/to/nextcloud/config/config.php
'datadirectory' => '/new/path/to/data',

change the location in the database:

mysqldump -u<rootuser> -p > /path/to/dbdump/dump.sql
dbuser=$(awk -F\' "/'dbuser'/{print \$4;exit}" /path/to/nextcloud/config/config.php)
dbpassword=$(awk -F\' "/'dbpassword'/{print \$4;exit}" /var/www/nextcloud/config/config.php)
mysql -u$dbuser -p$dbpassword

Inside the MySQL console:

use <nextclouddb>;
update oc_storages set id='local::/new/path/to/data/' where id='local::/path/to/data/'; 
quit;

Again outside the MySQL console

unset dbuser dbpassword

turn maintenance mode off:

sudo -u www-data php /path/to/nextcloud/occ maintenance:mode --off

After that, carefully test Nextcloud, the files inside web ui, shares, tags, comments etc. If everything is working fine and Nextcloud indeed handles the files on the new location, you could remove the backups:

rm -R /path/to/data //old location!!
rm /path/to/dbdump/dump.sql

Discussion

Enter your comment. Wiki syntax is allowed:
 
Last modified: le 2022/03/01 19:09