YunoHost-Apps / nextcloud_ynh

Nextcloud package for YunoHost
https://nextcloud.com/
GNU Affero General Public License v3.0
144 stars 62 forks source link

Upgrade fails due to moving data elsewhere and deleting the original directory #485

Open MayeulC opened 2 years ago

MayeulC commented 2 years ago

Describe the bug

Upgrading to the latest version.

I previously moved the nextcloud data off to an external disk, editing /var/www/nextcloud/config/config.php and the value datadirectory. Everything was running smoothly until the upgrade.

It looks like it happened because I recently cleaned up the /home/yunohost.app/nextcloud directory, removing /home/yunohost.app/nextcloud/data in the process.

Context

Steps to reproduce

Expected behavior

The original data directory should not be critical to the success of the upgrade operation. Ideally, the data directory should be read from the nextcloud configuration file. Even better, that file should be editable from the web admin.

Logs

chown: impossible d'accéder à '/home/yunohost.app/nextcloud/data': Aucun fichier ou dossier de ce type
[Error] Upgrade failed.
2022-04-29 19:33:12,872: DEBUG - + chown -R nextcloud: /var/www/nextcloud /home/yunohost.app/nextcloud/data
2022-04-29 19:33:14,229: WARNING - chown: impossible d'accéder à '/home/yunohost.app/nextcloud/data': Aucun fichier ou dossier de ce type
2022-04-29 19:35:31,713: DEBUG - + find /home/yunohost.app/nextcloud/ -type f -print0
2022-04-29 19:35:31,713: DEBUG - + xargs -0 chmod 0640
2022-04-29 19:35:31,716: WARNING - chmod: opérande manquant après « 0640 »

If applicable and useful, add screenshots to help explain your problem.

MayeulC commented 2 years ago

Restoration succeeded with:

mkdir /home/yunohost.app/nextcloud/data
# Just creating the above was not enough, as `find /home/yunohost.app/nextcloud/ -type f -print0` returns an empty list
touch /home/yunohost.app/nextcloud/data/moved
yunohost backup restore nextcloud-pre-upgrade1 --apps nextcloud --debug

I proceeded to upgrade, and it worked. I'm going to perform the same on my second Nextcloud instance, but the scripts should probably handle that case better.

Edit: new error on the second instance: https://paste.yunohost.org/raw/oqaxicawug

Adding to the above touch /home/yunohost.app/nextcloud__2/data/nextcloud.log solves the issue.

Aaaamu commented 1 year ago

I found this thread researching if i can move nextcloud data directory. it seems not advisable at the moment. My question is, if it would work with symlinks as described in solution 2 of this post: https://help.nextcloud.com/t/howto-change-move-data-directory-after-installation/17170 ?

MayeulC commented 1 year ago

@Aaaamu I have been doing this for years; with the occasional issue such as this one.

I did more or less the same as in the instructions here: https://yunohost.org/en/app_nextcloud#ii-migrate-nextcloud-data

It's probably a good idea to create a dummy file in /home/yunohost.app/nextcloud/data/ as I did above with touch /home/yunohost.app/nextcloud/data/moved, just in case this issue happens.

Salamandar commented 1 year ago

This is a bug. I also have this issue but I didn't move the directory: there's just no files in it. the find fails, and the chmod too. You should do something like

while read file; do

done <<< find

Or, better, a recursive chmod command without find !

KaeruCT commented 1 year ago

I ran into this issue as well.

My biggest gripe is that it also prevents backups from being restored, because the restore process will try to create the log file in the hardcoded datadir:

https://github.com/YunoHost-Apps/nextcloud_ynh/blob/cda1eaf85230547c0a51609f028357c75990771e/scripts/restore#L172

# Make sure a log file exists (mostly for CI tests)
logfile="/home/yunohost.app/$app/data/nextcloud.log"
if [ ! -f "$logfile" ]; then
    touch "$logfile"
    chown $app: "$logfile"
fi

I had to create the directory /home/yunohost.app/$app/data/ manually before being able to restore the backup.

Jaxom99 commented 1 year ago

This workaround is also needed when restoring on a new server, at least for version 24.0.7~ynh1. Doing :

mkdir /home/yunohost.app/nextcloud/data
touch /home/yunohost.app/nextcloud/data/moved

made it work !