ownCloud + Nextcloud migration script for v6.0 update

Hi there,

as DietPi v6.0 was just released and we decided to not allow direct updating due to heavy internal changes, I wrote a small migration script, that allows easier transfer of your ownCloud and/or Nextcloud instance.
It includes:

  • Backup of database into datadir (to preserve your settings and apps data)
  • Backup of installation into datadir (to guarantee compatibility of installation version and database, in case of e.g. manual beta update, and preserve manually installed apps)
  • Optional moving of datadir to an external USB stick or whatever you want to use to transfer it to the new server/updated DietPi system.

Usage:

  1. Download: wget https://raw.githubusercontent.com/Fourdee/DietPi/master/.meta/dietpi-cloud-migration
  2. Allow script execution: chmod +x dietpi-cloud-migration
  3. Execute the script: ./dietpi-cloud-migration /mnt/<external_whatever>/nextcloud_data The path/argument is optional, if not given, you would need to manually move your ownCloud/Nextcloud datadir to the desired backup location after script execution.
  4. Carefully watch the scripts output. It should notify you about errors, however, I can’t give a guarantee of course.
  5. Check the backup made, there should be your whole datadir with additional dietpi-…cloud-database-backup.sql (database backup) and dietpi-…cloud-installation-backup/ (cloud installation folder backup) inside.
  6. If you are sure, everything went well, you can umount/plug-off the backup drive/stick/card and play the fresh v6.0 image onto your machine.
  7. After successful first run of the new system. Plug+mount the backup drive again. Copy/rsync the backup datadir to your desired location, where you finally want it. By default this is /mnt/dietpi_userdata/nextcloud_data respectively …/owncloud_data. You can move the whole DietPi userdata via dietpi-software, the mnt location will remain the same. If you want your ownCloud/Nextcloud datadir outside of dietpi_userdata, you can adjust this via dietpi.txt by SOFTWARE_OWNCLOUD_DATADIR respectively SOFTWARE_NEXTCLOUD_DATADIR value.
  8. At last just install ownCloud/Nextcloud via dietpi-software. The installation should automatically recognize the existing datadir and the backups inside and will recover them for you. If everything went well, then you should be able to access your cloud instance, if nothing happened, besides some tweaks, we made in between: E.g. see your URL appearing without /index.php/ now, if Apache is used, and some other background optimizations.

I tested the script up and down on my testing system, however, as always can’t guarantee, everything is working fine on your machine. So as always, if it’s about backing up sensible/important/personal data, be careful and recheck everything, to be sure that everything is there. The migration script, as well as ownCloud/Nextcloud installation/uninstallation does not touch the datadir. So if anything goes wrong, you should find your data still in place.

Legend, many thanks for doing this :slight_smile:

Awesome!!! Thanks!

Ok, I’ve taken the plunge and in the process of upgrading to v6 (160.6 I think).

I have followed the instructions here to backup and transfer my owncloud instance (stored on an external hard drive) Upon trying to browse my instance I get the following in the web browser.

Exception occurred while logging exception: Failed to connect to the database: An exception occured in driver: SQLSTATE[HY000] [1698] Access denied for user 'oc_kellis'@'localhost'
#0 /var/www/owncloud/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(429): OC\DB\Connection->connect()
#1 /var/www/owncloud/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(389): Doctrine\DBAL\Connection->getDatabasePlatformVersion()
#2 /var/www/owncloud/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(328): Doctrine\DBAL\Connection->detectDatabasePlatform()
#3 /var/www/owncloud/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(623): Doctrine\DBAL\Connection->getDatabasePlatform()
#4 /var/www/owncloud/lib/private/DB/Connection.php(144): Doctrine\DBAL\Connection->setTransactionIsolation(2)
#5 /var/www/owncloud/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php(172): OC\DB\Connection->__construct(Array, Object(Doctrine\DBAL\Driver\PDOMySql\Driver), Object(Doctrine\DBAL\Configuration), Object(Doctrine\Common\EventManager))
#6 /var/www/owncloud/lib/private/DB/ConnectionFactory.php(145): Doctrine\DBAL\DriverManager::getConnection(Array, Object(Doctrine\DBAL\Configuration), Object(Doctrine\Common\EventManager))
#7 /var/www/owncloud/lib/private/Server.php(529): OC\DB\ConnectionFactory->getConnection('mysql', Array)
#8 /var/www/owncloud/lib/composer/pimple/pimple/src/Pimple/Container.php(113): OC\Server->OC\{closure}(Object(OC\Server))
#9 /var/www/owncloud/lib/private/AppFramework/Utility/SimpleContainer.php(108): Pimple\Container->offsetGet('DatabaseConnect...')
#10 /var/www/owncloud/lib/private/ServerContainer.php(86): OC\AppFramework\Utility\SimpleContainer->query('DatabaseConnect...')
#11 /var/www/owncloud/lib/private/Server.php(1213): OC\ServerContainer->query('DatabaseConnect...')
#12 /var/www/owncloud/lib/private/Server.php(248): OC\Server->getDatabaseConnection()
#13 /var/www/owncloud/lib/composer/pimple/pimple/src/Pimple/Container.php(113): OC\Server->OC\{closure}(Object(OC\Server))
#14 /var/www/owncloud/lib/private/AppFramework/Utility/SimpleContainer.php(108): Pimple\Container->offsetGet('AccountMapper')
#15 /var/www/owncloud/lib/private/ServerContainer.php(86): OC\AppFramework\Utility\SimpleContainer->query('AccountMapper')
#16 /var/www/owncloud/lib/private/Server.php(1059): OC\ServerContainer->query('AccountMapper')
#17 /var/www/owncloud/lib/private/Server.php(254): OC\Server->getAccountMapper()
#18 /var/www/owncloud/lib/composer/pimple/pimple/src/Pimple/Container.php(113): OC\Server->OC\{closure}(Object(OC\Server))
#19 /var/www/owncloud/lib/private/AppFramework/Utility/SimpleContainer.php(108): Pimple\Container->offsetGet('UserManager')
#20 /var/www/owncloud/lib/private/ServerContainer.php(86): OC\AppFramework\Utility\SimpleContainer->query('UserManager')
#21 /var/www/owncloud/lib/private/Server.php(1052): OC\ServerContainer->query('UserManager')
#22 /var/www/owncloud/lib/private/Server.php(314): OC\Server->getUserManager()
#23 /var/www/owncloud/lib/composer/pimple/pimple/src/Pimple/Container.php(113): OC\Server->OC\{closure}(Object(OC\Server))
#24 /var/www/owncloud/lib/private/AppFramework/Utility/SimpleContainer.php(108): Pimple\Container->offsetGet('UserSession')
#25 /var/www/owncloud/lib/private/ServerContainer.php(86): OC\AppFramework\Utility\SimpleContainer->query('UserSession')
#26 /var/www/owncloud/lib/private/Server.php(1076): OC\ServerContainer->query('UserSession')
#27 /var/www/owncloud/lib/private/Log.php(430): OC\Server->getUserSession()
#28 /var/www/owncloud/lib/public/Util.php(169): OC\Log->logException(Array, Array)
#29 /var/www/owncloud/lib/base.php(433): OCP\Util::logException('base', Object(Doctrine\DBAL\DBALException))
#30 /var/www/owncloud/lib/base.php(579): OC::initSession()
#31 /var/www/owncloud/lib/base.php(994): OC::init()
#32 /var/www/owncloud/index.php(53): require_once('/var/www/ownclo...')
#33 {main}

Is anyone able to help me trouble shoot this. thank you.
Keith.

Thanks for the report. Can you please check your database users permissions:

mariadb -e "show grants for 'oc_kellis'@'localhost'"

Hello MichaIng , is that script is working with last Dietpi v7? Will be some upgrade? I need to move my nextcloud installation from Rpi4(32 bit image) to Mini PC (64bit). I have dietpi_userdata on external usb hdd. Is that script good for me?

Regards,
Przemek

Yes, it should work still fine. Also no risk in testing it since it creates the backup only but does not remove any existing files.