Is there a way to update NC automatically?

Support intro

Sorry to hear you’re facing problems :slightly_frowning_face:

help.nextcloud.com is for home/non-enterprise users. If you’re running a business, paid support can be accessed via portal.nextcloud.com where we can ensure your business keeps running smoothly.

In order to help you as quickly as possible, before clicking Create Topic please provide as much of the below as you can. Feel free to use a pastebin service for logs, otherwise either indent short log examples with four spaces:

example

Or for longer, use three backticks above and below the code snippet:

longer
example
here

Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can :heart:

Nextcloud version (eg, 20.0.5): 22.2.7
Operating system and version (eg, Ubuntu 20.04): Ubuntu 20.04 LTS
Apache or nginx version (eg, Apache 2.4.25): 2.4.41
PHP version (eg, 7.4): 7.4

Hi,
Is there a way to update NC automatically ?

Bernd

Hello,

I guess if you install NextCloud via Snap, then it will auto update itself !!

Thanks.

Another option is to install Nextcloud AIO GitHub - nextcloud/all-in-one: Nextcloud AIO stands for Nextcloud All In One and provides easy deployment and maintenance with most features included in this one Nextcloud instance.. There auto-updates are available when you enable daily backups.

1 Like

One more option: http://nextcloudpi.com
(Not only for Pi‘s)

@bernd.lentes
I think it is not a hard job to update Nextcloud
sudo -u www-data php updater/updater.phar

The problem is that you must at some point upgrade Ubuntu 20.04 LTS to Ubuntu 22.04 LTS. I think that no automatic updater will take you up. For updates and in case of errors you should always have some knowledge anyway or better leave it alone.

If you host Nextcloud in the internet you can change to a Managed Nextcloud (e.g. with your own domainname) and your hoster upgrades the Nextcloud for you.

1 Like

The snap and AIO will update PHP for you automatically so new OS updated do not need to be applied that often. Also OS updates will likely not break your instance as Nextcloud is containerized.

1 Like

Snap upgrades Ubuntu 20.04 LTS to Ubuntu 22.04 LTS and to Ubuntu 24.04 LTS? I thank rather the update of the operating system leads to the update of Snap. Thank you. Learned something again.

No :wink: But you don’t have to upgrade to the latest LTS release, in order to get e.g new PHP versions, beacuase the Snap is more or less self contained. Same goes for Nextcloud AIO. As long as you can run a supported Docker and Docker Compose version on it, you can run Nextcloud AIO.

1 Like

Of course you are right. But I was referring more to the longer-term upgrade such as 2, 4, 6 or 8 years. At some point you also have to change the Ubuntu version. Also the view that you could skip an LTS release is wrong. Thus, Snap only helps indirectly and in the short term.

Yes you need to upgrade the OS at some point but breakage of the Nextcloud is very unlikely when you run Nextcloud with AIO or snap since the instance is then containerized which will likely not break it upon the OS update.

Well technically you cannot skip it but you can use the same version for five years and then you have to do two release-upgrades in order to upgrade to the latest version :wink:

1 Like

@szaimen @bb77
Yes you are both right. But mostly these people who think they must not upgrade LTS after two years (and yes they are right) gets more problems after four or five years. Often the Nextcloud or other software is then also hopelessly outdated. Ubuntu LTS is a little bit like Windows XP and Windows 10. No need for dist-upgrade over a lot of years. Users and admins ike it.

Ubuntu release cycle | Ubuntu

Containers have the advantage that the content may be current but the cover may be outdated. Whereas often it is the other way around. :wink:

1 Like

If there are other things installed natively on the instance, I agree with you. With a minimal installation that is only used for snaps, there will hardly be any problems. I asume the snap deamon will be upgraded anyways, because they have to make sure that every snap is running on every supported Ubuntu version. But I’m not a 100% sure about that.

2 Likes

Not as a builtin straight out of the box feature. This is not adviceable anyway. Can you automate NC update/upgrade? Yes.

Automating without proper backup and restore strategy, is a dangerous path. There has been cases where NC updates has stalled, failed or bricked a NC instance.
Because each installation is unique for most part, it is not possible to make one solution for backup-restore routine, hence not possible to deliver an automated update feature in a safe way. However:

NC can be updated by CLI, and the updater script will end without updating, if there is no new version. Lookup the CLI occ commands in the documentation, and you are set to go.
My own setup can do this, however I use the no backup parameter, as I do automatic snapshotting each day using the builtin snapshotting scheduler in LXC, as I runs NC in a linux container. So all I has to do if an automated backup was going wrong, was to revert to yesterday snapshot, or the snapshot created just before update procedure. Then all I has to do is to disable my cronjob, report the issue to nextcloud, revert to older snapshot, and thats it.

So the answer is yes. There is an easy way, if you have a clear overview of your environment, and knows what you are doing. Script it. This is mine. Bear in mind that this is my “manuel” script, as my fully automated, robots the console inputs, and is unique to me.

#! /bin/bash

PHPCOMMAND="sudo -u www-data php8.0"
#$ commands[0]="sudo -u www-data php8.0"
commands[0]="/var/www/nextcloud/updater/updater.phar --no-backup"
commands[1]="/var/www/nextcloud/occ db:add-missing-indices"
commands[2]="/var/www/nextcloud/occ maintenance:data-fingerprint"
commands[3]="/var/www/nextcloud/occ maintenance:mode --off"
commands[4]="/var/www/nextcloud/occ maintenance:data-fingerprint"

for i in "${commands[@]}"; do eval $PHPCOMMAND $i; done

#sudo -u www-data php8.0 /var/www/nextcloud/updater/updater.phar --no-backup && 
#sudo -u www-data php8.0 /var/www/nextcloud/occ db:add-missing-indices && 
#sudo -u www-data php8.0 /var/www/nextcloud/occ maintenance:data-fingerprint && 
#sudo -u www-data php8.0 /var/www/nextcloud/occ maintenance:mode --off && 
#sudo -u www-data php8.0 /var/www/nextcloud/occ maintenance:data-fingerprint

1 Like

That is why AIO for example requires the daily backup to pass before updating Nextcloud.

You can one-click configure automatic updates in NextcloudPi.
Do note we offer a very conservative release cycle.
Example, 24 has not been automatically rolled out yet.
It is the most conservative release cycle available afaik, but it is also a simple apache/mariadb/redis setup with webui / cli control of updates, backups, etc.

1 Like

I created some time ago this script to do some optimizacions and update automatically:
First of all… I created for root user… This is a bad practise. Create it for www-data user, it is more secure.

Creating script:
sudo nano /root/optim_update_NC.sh

The script:

#!/bin/bash
echo "TAREA DE OPTIMIZACION DE NEXTCLOUD"
echo "\n  - Vaciando REDIS"
redis-cli -s /var/run/redis/redis-server.sock <<EOF
FLUSHALL
quit
EOF
echo "  - Limpia la cache los archivos que ya no existan"
sudo -u www-data php /var/www/nextcloud/occ files:cleanup
echo "  - Escaneo de archivos en el sistema de archivos"
sudo chown -R www-data:www-data /mnt/HDD1/NC_data
sudo -u www-data php /var/www/nextcloud/occ files:scan --all
sudo -u www-data php /var/www/nextcloud/occ files:scan-app-data
echo "\n  - Arreglando permisos en /var/www/nextcloud"
sudo chown -R www-data:www-data /var/www/nextcloud
echo "\n  - Versión actual"
sudo -u www-data php /var/www/nextcloud/occ -V
echo "\n  - Try to update"
sudo -u www-data php /var/www/nextcloud/updater/updater.phar --no-interaction 
echo "\n  - Run upgrade routines after updating"
sudo -u www-data php /var/www/nextcloud/occ upgrade -n
echo "\n  - Arreglar cosas varias"
echo "\n      - BBDD: Add Missing Indices"
sudo -u www-data php /var/www/nextcloud/occ db:add-missing-indices -n 
echo "\n      - BBDD: Add Missing Primary Keys"
sudo -u www-data php /var/www/nextcloud/occ db:add-missing-primary-keys -n
echo "\n      - BBDD: Add Missing Columns"
sudo -u www-data php /var/www/nextcloud/occ db:add-missing-columns -n
echo "\n      - BBDD: Filecache bigInt"
sudo -u www-data php /var/www/nextcloud/occ db:convert-filecache-bigint -n
echo "\n      - PHP: output_buffering=Off"
sudo -u www-data sed -i "s/output_buffering=.*/output_buffering=Off/" /var/www/nextcloud/.user.ini
echo "\n"
echo "\n  - Actualizando apps"
sudo -u www-data php /var/www/nextcloud/occ update:check
sudo -u www-data php /var/www/nextcloud/occ app:update --all
echo ""
#echo "  - Reiniciando servicio Apache y PHP"
#/usr/sbin/service php7.3-fpm restart
#/usr/sbin/service apache2 restart
echo "\n  - Fin del script"
exit 0

Make it executable:
sudo chmod +x /root/optim_update_NC.sh

Trying it:
sudo sh /root/optim_update_NC.sh

Edit crontaf of root account:
sudo crontab -e

And writing in it an automatic execution of this script every 2AM

# Tarea para optimizar NextCloud a las 2AM
0 2 * * * /root/optim_update_NC.sh > /dev/null 2>&1

The content in a script to only update is the following:

echo "\n  - Arreglando permisos en /var/www/nextcloud"
sudo chown -R www-data:www-data /var/www/nextcloud
echo "\n  - Try to update"
sudo -u www-data php /var/www/nextcloud/updater/updater.phar --no-interaction 
echo "\n  - Run upgrade routines after updating"
sudo -u www-data php /var/www/nextcloud/occ upgrade -n
echo "\n  - Actualizando apps"
sudo -u www-data php /var/www/nextcloud/occ update:check
sudo -u www-data php /var/www/nextcloud/occ app:update --all