Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
moving_nextcloud_data [2022/03/01 18:00]
warmachine created
moving_nextcloud_data [2022/03/01 19:09] (current)
warmachine
Line 1: Line 1:
 ===== Moving a Next Cloud Datastore ===== ===== 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 +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  
 + 
 <color #ed1c24>ref:</color> [[https://help.nextcloud.com/t/howto-change-move-data-directory-after-installation/17170]] <color #ed1c24>ref:</color> [[https://help.nextcloud.com/t/howto-change-move-data-directory-after-installation/17170]]
  
 +turn maintenance mode on for nextcloud:
 +
 +<code>sudo -u www-data php /path/to/nextcloud/occ maintenance:mode --on</code>
 +
 +make a new directory for your data, copy your data to it, and have nextcloud's user take ownership:
 +
 +<code>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</code>
 +
 +modify nextcloud config to point to this new path:
 +
 +<code>nano /path/to/nextcloud/config/config.php
 +'datadirectory' => '/new/path/to/data',</code>
 +       
 +change the location in the database:
 +
 +<code>mysqldump -u<rootuser> -p > /path/to/dbdump/dump.sql</code>
 +
 +<code>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</code>
 +      
 +Inside the MySQL console:
 +
 +<code>
 +use <nextclouddb>;
 +update oc_storages set id='local::/new/path/to/data/' where id='local::/path/to/data/'; 
 +quit;
 +</code>
 +      
 +Again outside the MySQL console
 +
 +<code>unset dbuser dbpassword</code>
 + 
 +turn maintenance mode off:
 +
 +<code>sudo -u www-data php /path/to/nextcloud/occ maintenance:mode --off</code>
 +
 +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:
 +
 +<code>rm -R /path/to/data //old location!!
 +rm /path/to/dbdump/dump.sql</code>
  
Last modified: le 2022/03/01 18:00