Can't Upgrade via built-in updater due to "Can't Create Backup" step

Hello, I am having trouble updating Nextcloud from v21.0.5 to latest v 22.2.0. When I go to the web updater, Nextcloud can’t Create Backup and so it stops there.
I re-tried the update several times and nothing.

image

The only thing different I’ve done recently was that I moved the data folder from /var/www/nextcloud-data/ to a mounted drive in /mnt/nextcloud-data/ which is a network drive on my NAS. I had to mess with the /etc/fstab file in order automount this drive into this mountpoint, which included adding the following options uid=www-data,gid=www-data,file_mode=0770,dir_mode=0770.

Aside from that, I see in the /var/www/log/apache2/nextcloud.error file says something about Permission denied in /var/www/nextcloud/updater/index.php on line 529. When I look at line 529 of that file all it says is:

$state = copy($fileInfo->getRealPath(), $backupFolderLocation . $fileName);

When looking at this link https://docs.nextcloud.com/server/latest/admin_manual/maintenance/update.html I see that
Create backup: creates a backup of the existing code base in /updater-INSTANCEID/backups/nextcloud-CURRENTVERSION/ inside of the data directory (this does not contain the /data directory nor the database).

I opened the updater.log in /mnt/nextcloud-data/updater.log and I see the following lines:

2021-10-11T17:02:14-0400 TQBpiTnQj7 [error] POST request failed with other exception
2021-10-11T17:02:14-0400 TQBpiTnQj7 [error] Exception: Exception
Message: Could not copy "/var/www/nextcloud/config/config.php.bak" to "/mnt/nextcloud-data/updater-ocxx0ed04fpq/backups/nextcloud-21.0.5.1-1633986115/config/config.php.bak". Source /var/www/nextcloud/config/config.php.bak is not readable. Destination /mnt/nextcloud-data/updater-ocxx0ed04fpq/backups/nextcloud-21.0.5.1-1633986115/config/config.php.bak is not writable
Code:0

So it seems this in fact is some sort of permissions problem which I don’t know how to fix.

I don’t understand why it would say that:
Source /var/www/nextcloud/config/config.php.bak is not readable.

The next statement:
Destination /mnt/nextcloud-data/updater-ocxx0ed04fpq/backups/nextcloud-21.0.5.1-1633986115/config/config.php.bak is not writable
is more likely since this is the mounted network share, although permissions do show www-data with access, since I included the options in the fstab file for uid=www-data,gid=www-data,file_mode=0770,dir_mode=0770.

Another odd thing is that since I moved the data folder to the mounted one at /mnt/nextcloud-data, I am unable to sudo cd /mnt/nextcloud-data. When I try that I get sudo: cd: command not found.

Thank you for any help.

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

The issue you are facing: Nextcloud can’t ‘Create Backup’ when trying to update to Nextcloud 22.2.0

Is this the first time you’ve seen this error? (Y/N): YES

Steps to replicate it:

  1. Login to web interface as administrator
  2. Go to settings - overview and ‘Open Updater’
  3. Click ‘Start update’

The output of your Nextcloud log in Admin > Logging:

Couldn't find anything relevant here

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'instanceid' => 'xxxxxxxxxx',
  'passwordsalt' => 'xxxxxxxxxx',
  'secret' => 'xxxxxxxxxx',
  'trusted_domains' =>
  array (
    0 => 'nextcloud.example.com',
  ),
  'datadirectory' => '/mnt/nextcloud-data/',
  'dbtype' => 'mysql',
  'version' => '21.0.5.1',
  'overwrite.cli.url' => 'https://nextcloud.example.com',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost:3306',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'dbuser',
  'dbpassword' => 'dbuserpass',
  'installed' => true,
  'mail_smtpmode' => 'smtp',
  'mail_sendmailmode' => 'pipe',
  'mail_from_address' => 'nextcloud',
  'mail_domain' => 'example.com',
  'mail_smtpauth' => 1,
  'mail_smtphost' => 'xxxxxxxxxx',
  'mail_smtpport' => '1025',
  'mail_smtpname' => 'nextcloud@example.com',
  'mail_smtppassword' => 'xxxxxxxxxx',
  'mail_smtptimeout' => 30,
  'remember_login_cookie_lifetime' => 1296000,
  'session_lifetime' => 2700,
  'session_keepalive' => false,
  'auto_logout' => true,
  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' =>
  array (
    'host' => 'xxxxxxxxxx',
    'port' => 6379,
  ),
  'maintenance' => false,
  'updater.release.channel' => 'stable',
  'theme' => '',
  'loglevel' => 2,
  'default_phone_region' => 'US',
  'trashbin_retention_obligation' => 'auto, 30',
  'updater.secret' => 'xxxxxxxxxx',
);

The output of your Apache/nginx/system log in /var/log/____:

This is the output of /var/www/log/apache2/nextcloud.error:

[Mon Oct 11 14:55:35.303985 2021] [proxy_fcgi:error] [pid 540034:tid 140024037234432] [client 192.168.XXX.XXX:52726] AH01071: Got error 'PHP message: PHP Warning:  copy(/var/www/nextcloud/config/config.php.bak): failed to open stream: Permission denied in /var/www/nextcloud/updater/index.php on line 529'

I opened the updater.log in /mnt/nextcloud-data/updater.log and I see the following lines

2021-10-11T17:02:14-0400 TQBpiTnQj7 [error] POST request failed with other exception
2021-10-11T17:02:14-0400 TQBpiTnQj7 [error] Exception: Exception
Message: Could not copy "/var/www/nextcloud/config/config.php.bak" to "/mnt/nextcloud-data/updater-ocxx0ed04fpq/backups/nextcloud-21.0.5.1-1633986115/config/config.php.bak". Source /var/www/nextcloud/config/config.php.bak is not readable. Destination /mnt/nextcloud-data/updater-ocxx0ed04fpq/backups/nextcloud-21.0.5.1-1633986115/config/config.php.bak is not writable
Code:0

So it seems this in fact is some sort of permissions problem which I don’t know how to fix.

I don’t understand why it would say that:
Source /var/www/nextcloud/config/config.php.bak is not readable.

The next statement:
Destination /mnt/nextcloud-data/updater-ocxx0ed04fpq/backups/nextcloud-21.0.5.1-1633986115/config/config.php.bak is not writable
is more likely since this is the mounted network share, although permissions do show www-data with access, since I included the options in the fstab file for uid=www-data,gid=www-data,file_mode=0770,dir_mode=0770.

Another odd thing is that since I moved the data folder to the mounted one at /mnt/nextcloud-data, I am unable to sudo cd /mnt/nextcloud-data. When I try that I get sudo: cd: command not found.

Please learn all about sudo
The command is useless.

If you are root you can use the command without sudo.
You need sudo:
a.) execute command for e.g. www-data from e.g. root with with sudo -u www-data
b.) change from normal user e.g. to root: sudo -s

I got this today after having upgraded my RPi4B running my Instance of NC from “Buster 10/64” to “Bullseye 11/64” .

Running “sudo chown -R www-data:www-data /var/www/nextcloud/” resolved it for me.

2 Likes

Hi, I recently had the error “Create Backup” again when updating from 27.0.1 to 27.0.2. After such a long time again? What’s going on? Actually, I’ve been running through some updates lately without any problems, even 26.0.4 → 27.0.1, and now I get the “Create Backup” error when updating from 27.0.1 to 27.0.2 with Updater. What’s going on? I had to install the 27.0.2 release manually !!!

user@nc:/home$ cd /var/www/nc.example.com
user@nc:/var/www/nc.example.com$ ls -la
total 184
drwxr-xr-x 15 www-data www-data  4096 Aug 14 11:07 .
drwxr-xr-x  4 root     root      4096 Oct 10  2022 ..
-rw-r--r--  1 root     root      3127 Aug 14 11:03 .htaccess
-rw-r--r--  1 root     root       101 Aug 14 11:07 .user.ini
drwxr-xr-x 45 root     root      4096 Aug 14 11:03 3rdparty
-rw-r--r--  1 root     root     23796 Aug 14 11:06 AUTHORS
-rw-r--r--  1 root     root     34520 Aug 14 11:06 COPYING
drwxr-xr-x 56 www-data www-data  4096 Aug 14 11:06 apps
drwxr-xr-x  2 www-data www-data  4096 Aug 14 11:52 config
-rw-r--r--  1 root     root      4095 Aug 14 11:04 console.php
drwxr-xr-x 24 root     root      4096 Aug 14 11:04 core
-rw-r--r--  1 root     root      6317 Aug 14 11:06 cron.php
drwxr-xr-x  2 www-data www-data  4096 Oct 10  2022 data
drwxr-xr-x  2 root     root     12288 Aug 14 11:07 dist
-rw-r--r--  1 root     root       156 Aug 14 11:06 index.html
-rw-r--r--  1 root     root      3456 Aug 14 11:07 index.php
drwxr-xr-x  6 root     root      4096 Aug 14 11:06 lib
-rwxr-xr-x  1 root     root       283 Aug 14 11:07 occ
drwxr-xr-x  2 root     root      4096 Aug 14 11:06 ocm-provider
drwxr-xr-x  2 root     root      4096 Aug 14 11:03 ocs
drwxr-xr-x  2 root     root      4096 Aug 14 11:04 ocs-provider
-rw-r--r--  1 root     root      3187 Aug 14 11:07 public.php
-rw-r--r--  1 root     root      5597 Aug 14 11:07 remote.php
drwxr-xr-x  4 root     root      4096 Aug 14 11:04 resources
-rw-r--r--  1 root     root        26 Aug 14 11:06 robots.txt
-rw-r--r--  1 root     root      2452 Aug 14 11:07 status.php
drwxr-xr-x  3 www-data www-data  4096 Aug 14 11:04 themes
drwxr-xr-x  2 www-data www-data  4096 Oct  6  2022 updater
-rw-r--r--  1 root     root       383 Aug 14 11:03 version.php
user@nc:/var/www/nc.example.com$ cd updater
user@nc:/var/www/nc.example.com/updater$ sudo php updater.phar
Nextcloud Updater - version: v26.0.0beta2-9-g64e2e4c dirty

Current version is 27.0.2.

Update to Nextcloud 27.0.2 available. (channel: "stable")
Following file will be downloaded automatically: https://download.nextcloud.com/server/releases/nextcloud-27.0.2.zip
Open changelog ↗

Steps that will be executed:
[ ] Check for expected files
[ ] Check for write permissions
[ ] Create backup
[ ] Downloading
[ ] Verify integrity
[ ] Extracting
[ ] Enable maintenance mode
[ ] Replace entry points
[ ] Delete old files
[ ] Move new files in place
[ ] Done

Start update? [y/N] y

Info: Pressing Ctrl-C will finish the currently running step and then stops the updater.

[✔] Check for expected files
[✔] Check for write permissions
[✔] Create backup
[✔] Downloading
[✔] Verify integrity
[✔] Extracting
[✔] Enable maintenance mode
[✔] Replace entry points
[✔] Delete old files
[✔] Move new files in place
[✔] Done

Update of code successful.

Should the "occ upgrade" command be executed? [Y/n] Y
An unhandled exception has been thrown:
OCP\HintException: [0]: Memcache \OC\Memcache\APCu not available for local cache (Is the matching PHP module installed and enabled?)

Keep maintenance mode active? [y/N] y
Maintenance mode kept active
user@nc:/var/www/nc.example.com/updater$ ls -la
total 848
drwxr-xr-x  2 www-data www-data   4096 Oct  6  2022 .
drwxr-xr-x 15 www-data www-data   4096 Aug 14 12:13 ..
-rw-r--r--  1 root     root      66626 Aug 14 12:13 index.php
-rw-r--r--  1 root     root     790206 Aug 14 12:13 updater.phar
user@nc:/var/www/nc.example.com/updater$ cd ..
user@nc:/var/www/nc.example.com$ ls -la
total 184
drwxr-xr-x 15 www-data www-data  4096 Aug 14 12:13 .
drwxr-xr-x  4 root     root      4096 Oct 10  2022 ..
-rw-r--r--  1 root     root      3127 Aug 14 12:09 .htaccess
-rw-r--r--  1 root     root       101 Aug 14 12:13 .user.ini
drwxr-xr-x 45 root     root      4096 Aug 14 12:10 3rdparty
-rw-r--r--  1 root     root     23796 Aug 14 12:12 AUTHORS
-rw-r--r--  1 root     root     34520 Aug 14 12:12 COPYING
drwxr-xr-x 56 www-data www-data  4096 Aug 14 12:12 apps
drwxr-xr-x  2 www-data www-data  4096 Aug 14 12:13 config
-rw-r--r--  1 root     root      4095 Aug 14 12:10 console.php
drwxr-xr-x 24 root     root      4096 Aug 14 12:10 core
-rw-r--r--  1 root     root      6317 Aug 14 12:12 cron.php
drwxr-xr-x  2 www-data www-data  4096 Oct 10  2022 data
drwxr-xr-x  2 root     root     12288 Aug 14 12:13 dist
-rw-r--r--  1 root     root       156 Aug 14 12:12 index.html
-rw-r--r--  1 root     root      3456 Aug 14 12:13 index.php
drwxr-xr-x  6 root     root      4096 Aug 14 12:12 lib
-rwxr-xr-x  1 root     root       283 Aug 14 12:13 occ
drwxr-xr-x  2 root     root      4096 Aug 14 12:12 ocm-provider
drwxr-xr-x  2 root     root      4096 Aug 14 12:09 ocs
drwxr-xr-x  2 root     root      4096 Aug 14 12:10 ocs-provider
-rw-r--r--  1 root     root      3187 Aug 14 12:13 public.php
-rw-r--r--  1 root     root      5597 Aug 14 12:13 remote.php
drwxr-xr-x  4 root     root      4096 Aug 14 12:10 resources
-rw-r--r--  1 root     root        26 Aug 14 12:12 robots.txt
-rw-r--r--  1 root     root      2452 Aug 14 12:13 status.php
drwxr-xr-x  3 www-data www-data  4096 Aug 14 12:10 themes
drwxr-xr-x  2 www-data www-data  4096 Oct  6  2022 updater
-rw-r--r--  1 root     root       383 Aug 14 12:10 version.php
user@nc:/var/www/nc.example.com$ ./occ upgrade
Cannot write into "config" directory!
This can usually be fixed by giving the web server write access to the config directory.

But, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it.
See https://docs.nextcloud.com/server/27/go.php?to=admin-config
user@nc:/var/www/nc.example.com$ sudo php --define apc.enable_cli=1 occ upgrade
Nextcloud or one of the apps require upgrade - only a limited number of commands are available
You may use your browser or the occ upgrade command to do the upgrade
Setting log level to debug
Updating database schema
Updated database
Starting code integrity check...
Finished code integrity check
Update successful
Maintenance mode is kept active
Resetting log level

user@nc:~$ sudo chown root:www-data /var/www/nc.example.com/config/config.php
user@nc:~$ sudo chmod 660 /var/www/nc.example.com/config/config.php
user@nc:~$ sudo nano /var/www/nc.example.com/config/config.php
true -> false

Note: Some app folders have a different owner than the user of the web server. This can happen if apps have been installed manually. Check the permissions of the following app folders. Question: How to fix this?

user@nc:/var/www/nc.example.com$ sudo chown -R www-data:www-data /var/www/nc.example.com/apps

Question: Is it possible that the Nextcloud administration can avoid such disasters so that I don’t have to solve such bugs at the age of 70? :hot_face:

You are running the command as root, which is probably the reason why many of the files and directories are owned by root instead of www-data.

And here you are trying to run occ upgrade with your normal user account instead of www-data.

Please try the following:

Fix Ownership and permissions:

sudo chown -R www-data:www-data /var/www/nc.example.com
sudo find /var/www/nc.example.com -type d -exec chmod 750 {} \;
sudo find /var/www/nc.example.com -type f -exec chmod 640 {} \;

Then run the updater as www-data, with the following command:

sudo -u www-data /var/www/nc.example.com/updater/updater.phar

If it still fails, you can try to run occ upgrade manually:

sudo -u www-data php --define apc.enable_cli=1 /var/www/nc.example.com/occ upgrade

You are the adminstrator of your server, nobody else.

Sorry, I have to say that, but those weren’t bugs in the product that caused your issues, that was caused by incorrect operations on your part.

  1. Do not run the updater or any occ commands as root or with your normal user. Always use sudo -u www-data

  2. If you have to change anything manually as root adjust the permissions and ownership manually afterwards… Or don’t change anything manually if you are not sure what side-effects it might cause :wink:

1 Like

Yes, yes, I apologize for my impatience. In the past, when I was still a software engineer myself, I would certainly have followed all this. I was just a little angry because this Create Backup error happened to me on both Nextcloud instances. So I have to look into the matter by following the last hints from you. Thank you so much and stay healthy!

1 Like

No worries. :slight_smile:

And yes, that’s an know issue which usually can be be avoided by passing the --apc.enable_cli=1 argument to PHP when running occ upgrade. (however in your case it might also be failing due to wrong permissions)

You can also enbable apcu permanently by adding the following line…

apc.enable_cli=1

to the following file:

/etc/php/8.2/mods-available/apcu.ini

You might need to replace 8.2 with the actual PHP version on your system in the above example, and of course the php-apcu module must be installed for it to work.

1 Like

Oh, yes, the other day I had another error where I had to add Acpu and install Redis:

user@nc:~$ sudo apt-get install php-apcu
user@nc:~$ sudo apt-get install redis-server php-redis

And then I had to add config.php file:

  'memcache.local' => '\\OC\\Memcache\\APCu',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' =>
  array (
    'host' => 'localhost',
    'port' => 6379,
  ),

Is it this issue that you mean?

Not directly, because that dosen’t enable APCu for CLI commands.

In order to make use of APCu from the command line, you either have to pass --apc.enable_cli=1 with every single PHP command that should use it, or you can enable it globally by adding it to /etc/php/8.2/mods-available/apcu.ini, as in my example.

Many thanks for your help. It works great !!! :100:

2 Likes

I’ve had to resort to running the upgrade script manually in the step from 27.0.1 to 27.1.0. The web based upgrade just failed on the backup step with no hints. Turned out that the permissions were wrong on config\config.php.bak - ended up as root whereas on my client’s system, Nextcloud runs under nginx on Centos v7. The steps were:

chown -R nginx: /data/nextcloud
sudo -u nginx php --define apc.enable_cli=1 /data/nextcloud/updater/updater.phar
sudo -u nginx php --define apc.enable_cli=1 /data/nextcloud/occ upgrade
sudo -u nginx php --define apc.enable_cli=1 /data/nextcloud/occ maintenance:mode --off

Change /data/nextcloud path for your install location. Change nginx if running under a different account. The --define apc.enable_cli=1 parameter is only needed if you use APC caching. The updater.phar script will ask if you want to run occ upgrade. If you use APC caching, this will fail because it doesn’t supply the require parameter. Hence the reason the upgrade is run as a separate step.

I had same problem with ver 28.0.3 update - this resolves it.