nextcloud / docker

⛴ Docker image of Nextcloud
https://hub.docker.com/_/nextcloud/
GNU Affero General Public License v3.0
5.8k stars 1.8k forks source link

[Bug]: Existing directories deleted from /var/www/html PV when deploying docker image on kubernetes #1925

Open anomaly256 opened 1 year ago

anomaly256 commented 1 year ago

⚠️ This issue respects the following points: ⚠️

Bug description

I just moved my existing data directory to data-backup and rm'd the other files from the pv in order to start fresh as I was having issues with the original install that had been upgraded and moved many times since Nextcloud forked from Owncloud.

I was expecting to be able to move my files back into the new data dir once provisioned and issue a files:scan to reimport them.

Yet for some reason, the Nextcloud docker image's provisioning scripts just arbitrarily deletes the existing content of the PV? Including directories it doesn't even handle itself?

Why?

Luckily I have most of my family photos backed up etc. But why? Why do this? Fail with an error message if you want to prevent existing directories getting in the way of anything but don't just delete them without warning. This is just.... why??

Steps to reproduce

  1. Rename existing data dir
  2. Remove nextcloud base files and DB to start a fresh install
  3. Panic as your renamed data-dir is deleted when it need not be

Expected behavior

Don't delete directories you don't typically manage. OR fail with a warning if you must and force the operator to take an action instead of dropping their files without any kind of prompting - not in the cli nor in the provisioning UI. Just .. why???

Installation method

Official All-in-One appliance

Operating system

Debian/Ubuntu

PHP engine version

PHP 8.1

Web server

Apache (supported)

Database engine version

PostgreSQL

Is this bug present after an update or on a fresh install?

Fresh Nextcloud Server install

Are you using the Nextcloud Server Encryption module?

None

What user-backends are you using?

Configuration report

No response

List of activated Apps

Just the base apps

Nextcloud Signing status

No response

Nextcloud Logs

No response

Additional info

Your options for source only list community docker images but the docker hub repo says "official"

anomaly256 commented 1 year ago

Should also note that this pv+pvc were pre-existing and not defined by the k8s deployment, the old contents were present initially until the nextcloud:production docker image's provisioning scripts ran.

anomaly256 commented 1 year ago

I'm guessing this from https://github.com/nextcloud/docker/blob/master/25/apache/entrypoint.sh#L150

rsync $rsync_options --delete --exclude-from=/upgrade.exclude /usr/src/nextcloud/ /var/www/html/

is to blame. --delete passed to rsync before checking any other dirs exist apart from those in /usr/src/nextcloud

edit: Thanks for moving this to the right place @szaimen

patman-cp commented 1 year ago

I hit this when trying to get a corrupted and failed nextcloud setup working again - I wanted to leave existing files as-is so pointed the nextcloud volume at my existing directory and was surprised when all existing files were wiped.

Luckily I backed up the every thing first - I was about to backup only the app store files, but decided backing up everything was a better idea. These files aren't critical to me, so I didn't have an existing backup (these are mainly images and videos I don't have space for on my phone but I want to keep them).

Not sure how I'll get the previous files into this new instance.

patman-cp commented 10 months ago

Opened a PR here:

https://github.com/nextcloud/docker/pull/2063

PatrickHuetter commented 10 months ago

This issue is huge. Had a running nextcloud instance and today it deleted the whole data directory after a docker container restart within kubernetes! Luckily i have some backup but this is really critical for a cloud software!

joshtrichards commented 1 month ago

Docs note this today and describe how to add additional custom folders if necessary (though it's probably best to place them outside of Nextcloud's installation folder entirely as noted too): https://github.com/nextcloud/docker?tab=readme-ov-file#custom-volumes

patman-cp commented 1 month ago

Docs note this today

That's not a justification for leaving this as-is. Plus the documentation doesn't anything about using a named volume, it's placement at the end of the documentation makes it seem like a minor warning, and it's in the "Custom volumes" section so it looks like it only applies if you are using an additional custom volume.

At a minimum this should fail rather than silently delete existing data - the user can easily delete the data themselves or script this for repeated uses.

joshtrichards commented 1 month ago

Yes, hence why the issue isn't closed out. My comment was updating on the status of things.

Your associated PR (thank you, btw) has had review comments on it for months. If you want something to change, look there. :)