Nextcloud Backup and Update
This article contains information about an older version of Nextcloud. We will revise the article shortly.
Upgrade Time! Nextcloud 12.0.5 is out now
The current version of Nextcloud 12.0.5 comes with some important changes. As with the previous updates, the focus of Nextcloud is on security and stability. Therefore an upgrade or a change to the new version 12.0.5 is worthwhile in any case. You can see a complete overview of the new fixes in the Nextcloud Server Changelog. Nextcloud is a very comprehensive open source software with which you can set up your own cloud storage. Independent of the big players like Dropbox and Co., you can run your Nextcloud completely free and without annoying limits and privacy concerns.
In the first part of this article we will show you how to make a secure backup of your cloud. This will put you on the safe side if something fails during the update. And the second part shows you how to upgrade your Nextcloud manually.
If you don’t have your own Nextcloud yet and still ended up on this article, you can learn how to install Nextcloud here:
Activate maintenance mode
Before you start your backup, you should put Nextcloud into maintenance mode.
sudo -u www-data php occ maintenance:mode --on
The maintenance:mode prevents inconsistencies in your data, closes active sessions and prevents new logins.
If you want to be very careful, you can also set your server to maintenance:mode. Change the file config.php in your Nextcloud directory under config/config.php. Set the value “maintenance” => false to “maintenance” => true. But remember to change the value at the end. 😉
Back up Nextcloud data
In this step we back up the most important thing, your Nextcloud data directory.
Change to your Webroot directory, where your Nextcloud installation is located:
The file config.php in the subfolder config/ contains the path to your data directory. Just check with nano which path is stored in your ‘datadirectory’:
If your data directory is located outside your Nextcloud installation folder, you don’t need to do anything, as this folder remains unaffected by the upgrade.
In case your data is in the installation folder, you need to save it now.
Simply pack your data into a tar archive and place it under root:
tar cvzf /root/nextcloud-data`date +”%Y%m%d”`.tar.gz /your/datadirectory/
Back Up Nextcloud Config
Then create a backup of your Nextcloud config.php file.
We simply move the file to root, execute the following command:
cp /var/www/html/nextcloud/config/config.php /root/
Backup Nextcloud database
In the last step you create a backup of the Nextcloud database.
You can find out the name of your database with the following command:
mysql -u root -p -e "show databases"
After entering your root password for MariaDB/MySQL you should see an overview like this:
As you can see, the database in our case is called Nextcloud by default.
With the mysqldump utility you can make a backup of your database.
mysqldump -u root -p your-database-name > ~/nextcloud.sql
This command creates a dump file of your database named nextcloud.sql and places it in your root directory. If anything goes wrong during the upgrade, you can use it to restore your Nextcloud database.
Check! All data secure! Now we can download the latest available version of Nextcloud. Currently it is Nextcloud version is 12.0.5.
Change back to your root directory and download Nextcloud:
Then you have to stop your web server.
service nginx stop
Now rename your old Nextcloud directory:
mv /var/www/html/nextcloud/ /var/www/html/nextcloud-old
and copy your new Nextcloud into the Webroot:
cp -Rv nextcloud /var/www/html/
After that you have to move your saved config.php file into the new Nextcloud folder:
cp /root/config.php /var/www/html/nextcloud/config/
If you had your datadirectory under Nextcloud/, you also have to copy this folder back.
tar xvzf [dein-nextcloud-data-backup.tar.gz] -C /var/www/html/nextcloud/
If you have used any 3rd party applications, check the new folder under nextcloud/apps/ to see if they are there. If not, just copy them from your old apps/ directory to the new one.
Set the folder permissions again explicitly for your installation and your datadirectory:
chown -R www-data:www-data /var/www/html/nextcloud chown -R www-data:www-data [/your/datadirectory]
And restart the web server.
service nginx restart
Ready to upgrade?
In the last step you start the upgrade using occ.
Change to your new Nextcloud directory and start the upgrade with the following command:
sudo -u www-data php occ upgrade
The update process takes from a few minutes to a few hours, depending on the size of your installation. If all goes well, you will see a success message at the end of the upgrade, otherwise an error message will tell you what went wrong.
Did you manage it? Then log in to your cloud and check in the admin area if your settings have been applied correctly. You should also see your new version number here. Also check if all your apps and third-party apps are activated.
If Nextcloud has spit out an error message for you, hopefully this troubleshooting can help you.
Of course, the manual upgrade means a little more effort, but this gives you maximum control. If you like it a bit more comfortable, you can use the built-in updater, which works very well now and is suitable for anyone who doesn’t have root access or small setups.
If you liked our tutorial, just sign up for the tutorial newsletter on the right!
Have Fun! 🙂Zurück zur Tutorial Übersicht Back to Tutorial Overview
This article contains information about an older version of Nextcloud. We will revise the article shortly. Upgrade Time! Nextcloud 12.0.5 is out now The current version of Nextcloud 12.0.5 comes with some important changes. As with the previous updates, the focus of Nextcloud is on security and stability. Therefore an upgrade or a change to […]
Thank you for your feedback!
We will get back to you as soon as the article is finished.