If you are like me who want to have unlimited cloud storage and at the same time would like to have the convenient of accessing your files from any device anywhere, and you are skeptical with using the public cloud storage for any valid reason. I believe you would want to run your own cloud storage. That’s if you are technical enough to setup one for yourself.
ownCloud is available as open source which you can hosted it your own or at a trusted service provider, or choose ownCloud.online. They also have Software-as-a-Service collaboration platform hosted in Germany.
Sounded a bit commercial in the above statement, but I have no intention to promote ownCloud here. I have no any financial benefit gained by publishing this article. I am merely just want to share my experience and as well as using this article to document down the experience.
I have been using ownCloud on my Synology Disk Station(DS) for a while since I have owned the DS. I felt it is the time to move my ownCloud into a more “open” environment instead of DS. “open” in terms of being able to easily updates the ownCloud if there is new version available. It is not easy to maintain and upgrade the ownCloud in DS as it is not the supported apps in DS218Play. I custom installed the ownCloud and I had forgotten how I had gotten it done in the first place. That’s the sign that I should have run it outside of DS.
Luckily I have an Acer Aspire R3700 laying around in good condition. This is a very old little fella but I had not been able to have it run for long duration without having it to shutdown by itself. Recently some online posts hinted me that it could be caused by overheating and finally I confirmed that the processor fan was not in good condition. I managed to find the replacement from AliExpress and the heating problem is resolved and happily running it with Ubuntu 20.04.
Here it goes the story of migrating the few hundreds GB of files into new ownCloud. I am not going to cover the installation which you should be able to follow through from the ownCloud installation guide.
Ubuntu has this little problem with every time when you had done an install or update, it will prompt a message recommending you to auto-remove unused / left over software packages. Never ever do this. Doing this will broke the ownCloud installation which it removes those packages that you have just installed for ownCloud. Many have complain about this over the forum. I have gone through it and you do not want to. What a dumb thing it is.
Migrating ownCloud
First thing I did is to create a new shared storage in my DS with the proper permissions.
Next, I need to enable the ssh service in DS.
Turn On ownCloud Maintenance Mode
If you are the only soul that is using the ownCloud, you can just stop the ownCloud server by stopping the apache2 service. This can be done from the Package Center in the DS.
If there are many souls are using the ownCloud, you can enable maintenance mode in ownCloud with the following command. You will have to run this command in the ownCloud web content path by ssh into your DS.
sudo php occ maintenance:mode --on
In DS, the current PHP version set in the OS may not be the current PHP version supported or used by the existing ownCloud. You will have to find the correct PHP version in the DS OS. In my case, I will have to run the command with the full path pointing to the correct PHP version.
sudo -u http /volume1/@appstore/PHP7.2/usr/local/bin/php72 occ maintenance:mode --on
Migrating Existing ownCloud Data Files
Next, I need to migrate the data files from the existing ownCloud storage into the new storage. The recommended approach is to use rsync so that you can maintain all the files attributes such as the files modified timestamp. This is to avoid your ownCloud client to re-sync the entire files storage when you brought them back into the new ownCloud server.
sudo rsync -avxt /volume1/owncloud/data/<user dir> /volume1/owncloud_data/
In the above example, my existing storage is at /volume1/owncloud and the actual user files are in the data directory. I was moving them to the new location called /volume1/owncloud_data/. I was doing the rsync by each user directory instead of the whole data directory so that I can have a shorter file copying process and I could easily fix the problem if anything goes wrong.
The reason for having another set of file storage in the same DS is I want to keep the original ownCloud intake in case my new installation ends with problem, and I will still have my original ownCloud to serve me.
I did not migrate the Marketplace Apps as per what ownCloud manual suggested. I tried the first time and the migration failed miserably, maybe my apps are too old. The number of apps is small and will not be painful if I have to reinstall them in the new ownCloud. For the second time attempting, what I did is to uninstall all existing 3rd party apps before I proceed to migrate the database.
Migrating ownCloud MariaDB Database
I was using MariaDB provided by DS Package Center. I have forgotten the database username and password, so I headed to the $OWNCLOUD_HOME/config/config.php file to retrieve it. For ownCloud version 9, it seems the password is not encrypted by default. This is unlucky but lucky for me.
<?php
$CONFIG = array (
'instanceid' => 'xxxxxxxxxx',
'passwordsalt' => '+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'trusted_domains' =>
array (
1 => 'my.domain.name',
),
'datadirectory' => '/volume1/owncloud/data',
'overwrite.cli.url' => 'https://mypublic.owncloud.domain/owncloud',
'dbtype' => 'mysql',
'version' => '10.2.0.5',
'dbname' => 'owncloud',
'dbhost' => '127.0.0.1:3306',
'dbtableprefix' => 'oc_',
'dbuser' => 'mydbuser',
'dbpassword' => 'dbpassword',
'logtimezone' => 'UTC',
'apps_paths' =>
array (
0 =>
array (
'path' => '/volume1/web/owncloud/apps',
'url' => '/apps',
'writable' => false,
),
1 =>
array (
'path' => '/volume1/web/owncloud/apps-external',
'url' => '/apps-external',
'writable' => true,
),
),
'installed' => true,
'mail_domain' => 'email.com',
'mail_from_address' => 'emailid',
'mail_smtpmode' => 'smtp',
'mail_smtpauthtype' => 'LOGIN',
'mail_smtpauth' => 1,
'maintenance' => true,
);
Next, I run the following command in the ssh shell to export the database into a file.
mysqldump --single-transaction -h localhost -u owncloud -ppassword owncloud > owncloud-dbbackup.bak
I copied this file into the Acer Aspire and run the following command to import the database.
mysql -h localhost -u owncloud -ppassword owncloud < owncloud-dbbackup.bak
The next thing you need to do is to update 2 database table content manually otherwise your ownCloud will not works. This is not documented in ownCloud migration manual as fas as I am aware. I have taken some time to finally figured this out.
In your new ownCloud database server, login to the MySQL or MariaDB. Do a query to take a look at the oc_accounts content.
MariaDB [owncloud]> select * from oc_accounts;
The following is what you will be receiving. You will notice the path for the user storage is not correct for the home column. You need to manually update the path using SQL command. Note that the following screen capture is after I had changed them to the correct path.
I might be wrong but if I remember correctly the path values for the home column are not being updated by ownCloud own “php occ upgrade” process. Please let me know if I am wrong.
The next database table that you need to update is oc_storages. You will see that there a 2 ids with old storage path and new storage path.
What I did is to delete both the data entry that starts with local:: and insert a new record with local::/media/owncloud_data/ as the id and the rest using back the data values from the old id.
Using the New ownCloud
After you have double checks all are in place with proper configurations. You will need to perform the ownCloud upgrade process. There is 2 ways to do this. With Apache web server started but in maintenance mode at your new ownCloud. You can go to web browser and navigate to the ownCloud server URL. The ownCloud web page will prompt you to perform the upgrade process from the website by clicking the button to proceed.
The other option is you can go to the command prompt, change path to the ownCloud web content root path and execute the following. This is the prefer mode if you have large environment to migrate.
sudo -u www-data php occ upgrade
Once everything success. It is now the time to turn off the maintenance mode at your new ownCloud server.
sudo -u www-data php occ maintenance:mode --off
If all works as expected, your ownCloud client should be able to resume operation as usual without they even notice it.
If you ownCloud server cannot write to the storage, make sure the storage is configured with the proper write permission.
Final Words
I will not say the above information may help for enterprise users but I hope this article helps to save you from cracking your brain cells too much in figuring out how to migrate your ownCloud, specially some of those detail that is not documented else where.