Migrating from ownCloud to Nextcloud

In case it helps others, here are my notes from manually migrating my server from ownCloud 9.0.2 to Nextcloud 9.0.50. Follow this at your own risk and keep in mind these commands are specific to my environment, install locations, etc. so adjust for your setup accordingly. I also recommend testing/reviewing backups before upgrading to make sure your data is safe and you have a way to recover.

Iโ€™ve got a manual install on a LEMP stack. My setup consists of:

  • Ubuntu 16.04 LTS
  • NGINX 1.11.1
  • PHP 7.0.4-7ubuntu2.1 (cli) ( NTS )
  • MariaDB 10.1.13

Backup Everything

Reference: https://doc.owncloud.org/server/9.0/admin_manual/maintenance/backup.html

Enable Maintenance Mode

sudo -u www-data php /var/www/html/cloud.lan/occ maintenance:mode --on

Backup Folders

mkdir -p ~/Documents/backup/

sudo rsync -Aax /var/www/html/cloud.lan ~/Documents/backup/owncloud-web-dirbkp_`date +"%Y%m%d"`/
sudo rsync -Aax /var/oc_data/ ~/Documents/backup/owncloud-oc_data-dirbkp_`date +"%Y%m%d"`/

Backup Database

mysqldump --lock-tables -u vance -p owncloud > ~/Documents/backup/owncloud-sqlbkp_date +"%Y%m%d".bak

Download & Verify Source of New Release

sudo curl -L https://download.nextcloud.com/server/releases/nextcloud-9.0.50.tar.bz2 -o /usr/local/src/nextcloud-9.0.50.tar.bz2

sudo curl -L https://download.nextcloud.com/server/releases/nextcloud-9.0.50.tar.bz2.sha256 -o /usr/local/src/nextcloud-9.0.50.tar.bz2.sha256

cat /usr/local/src/nextcloud-9.0.50.tar.bz2.sha256

echo "6c067d01416462dffb80862468a3f1b43307e48b9f8f023d544875dfa5db2ddf /usr/local/src/nextcloud-9.0.50.tar.bz2" | sha256sum -c -

sudo curl -L https://download.nextcloud.com/server/releases/nextcloud-9.0.50.tar.bz2.asc -o /usr/local/src/nextcloud-9.0.50.tar.bz2.asc

curl -L https://nextcloud.com/nextcloud.asc -o nextcloud.asc

gpg --import nextcloud.asc

rm nextcloud.asc

gpg --verify /usr/local/src/nextcloud-9.0.50.tar.bz2.asc /usr/local/src/nextcloud-9.0.50.tar.bz2

Start Installation


cd /usr/local/src/

sudo tar -xjf /usr/local/src/nextcloud-9.0.50.tar.bz2

Stop Web Server

sudo kill -QUIT $( cat /var/run/nginx.pid )

Rename old ownCloud directory

sudo mv /var/www/html/cloud.lan /var/www/html/cloud.lan.old

Move new source code into place

sudo cp -r /usr/local/src/nextcloud /var/www/html/cloud.lan

Restore old config

sudo cp /var/www/html/cloud.lan.old/config/config.php /var/www/html/cloud.lan/config/config.php

If you keep your data/ directory in your owncloud/ directory, copy it from your old version of ownCloud to your new owncloud/. If you keep it outside of owncloud/ then you donโ€™t have to do anything with it, because its location is configured in your original config.php, and none of the upgrade steps touch it.

If you are using 3rd party applications, look in your new owncloud/apps/ directory to see if they are there. If not, copy them from your old apps/ directory to your new one. Make sure the directory permissions of your third party application directories are the same as for the other ones.

Restart NGINX

sudo nginx

Resolve permissions

sudo chown --recursive www-data:www-data /var/www/html/cloud.lan

Start upgrade
sudo -u www-data php /var/www/html/cloud.lan/occ upgrade

I encountered an error about โ€œPHP module mb multibyte not installed.โ€
sudo apt-get update && sudo apt-get install php7.0-mbstring

Re-start upgrade

sudo -u www-data php /var/www/html/cloud.lan/occ upgrade

Secure permissions

cd /usr/local/bin

sudo cp set-owncloud-permissions.sh set-nextcloud-permissions.sh

Reference: https://docs.nextcloud.org/server/9/admin_manual/installation/installation_wizard.html#strong-perms-label for ideas on how to write a permissions setting script. Mine is below:


printf "Creating possible missing Directories\n"
mkdir -p $ocdata
mkdir -p $ocpath/assets

printf "chmod Files and Directories\n"
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750
find ${ocdata}/ -type f -print0 | xargs -0 chmod 0640
find ${ocdata}/ -type d -print0 | xargs -0 chmod 0750

printf "chown Directories\n"
chown -R ${rootuser}:${htgroup} ${ocpath}/
chown -R ${htuser}:${htgroup} ${ocpath}/apps/
chown -R ${htuser}:${htgroup} ${ocpath}/config/
chown -R ${htuser}:${htgroup} ${ocdata}/
chown -R ${htuser}:${htgroup} ${ocpath}/themes/
chown -R ${htuser}:${htgroup} ${ocpath}/assets/

chmod +x ${ocpath}/occ

printf "chmod/chown .htaccess\n"
if [ -f ${ocpath}/.htaccess ]
  chmod 0644 ${ocpath}/.htaccess
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess
if [ -f ${ocdata}/.htaccess ]
  chmod 0644 ${ocdata}/.htaccess
  chown ${rootuser}:${htgroup} ${ocdata}/.htaccess

sudo ./set-nextcloud-permissions.sh

Disable Maintenance Mode

sudo -u www-data php /var/www/html/cloud.lan/occ maintenance:mode --off

Login as Admin and Check for warnings. If all is good, feel free to clean up downloads, etc.