Reset / Delete files of all users

Hi all,

I deployed Nextcloud recently and populated it with a lot of files, users and groups. I figured that I used the wrong sharing mechanism. Thus, I would like to reset the (almost) the entire system: While I would like to keep registered users, groups, etc., I would like to reset (delete) all files of every user. In particular, all users should start with the same “blank sheet”, i.e with no files.

Is this possible?

You can delete the USERS data directory and a new skeleton will be copied on the next login.

or

Backup your database -> Delete NC -> Install NC -> Restore DB -> occ files:scan

Obviously both options do not care about any DATA.

Dear Vincent,

thanks for the reply. Regarding the first approach of deleting the USERS data directories would foresee to delete:

{owncload_install_dir}/data/user1
{owncload_install_dir}/data/user2
{owncload_install_dir}/data/usern ?

This keeps the users themselves but merely deletes the data?

Thanks

So I tested the first approach of deleting the respective user directories below the data directory.

Before deleting the user directory of user “foo”, I logged into the web interface of Nextcloud with user “foo” and uploaded a file “bar”. Next, I deleted {owncloud_install_dir}/data/foo, logged into the web interface of Nextcloud again with “foo” and the file “bar” was still visible.

Moreover, running occ files:scan --all now results in the following error:

Home storage for user foo not writable

I checked permissions of {owncloud_install_dir}/data/foo} and those are the same as the other user directories (owned by www-data). Finally, I cannot upload any files anymore with user “foo” via the web interface.

Seems like this is not a good approach to reset everything or I was doing something wrong.

You are right it did not copy a new skeleton.

I don’t know how many users you have to do but the error is solved with manualy creating directory files in user1

sudo rm -Rf /nc/data/user1
sudo -u www-data mkdir -p /nc/data/user1/files
sudo -u www-data php /var/www/nc/occ files:scan user1

Please post a few outputs like

ls -la /var/www/html/nextcloud/data/foo

so we can see all (rwx) is also correct.

Dear Vincent,

creating the files subdirectory indeed solves the problem. Creating these subdirectories shall be no problem as I can write a quick shell script.

Indeed, your proposed solution seems to work as it clears all files of users. However, it seems like the process has to be executed in strict order of:

  1. Delete user directory
  2. mkdir -p {user}/files
  3. occ files:scan --all

I validated it with a test user and will not conduct it with all operational users.

Best

Agreed it is not a good solution it leaves alot of garbage in the recent activities and database.

I cannot think of any other solution at the moment.

Perhaps you can create emty folders in “user”:

cache, files, files_external, files_versions, uploads

Set all folders correct for your nextcloud/webserver-user.

For my user “test” there are only the folders “files” and “cache” and “cache” is empty.

Where is your post with “ls -al …”

Hi devnull,

I guess my situation was already sorted by my last post. Which effect would creating the folders cache, files, files_external have?

Regarding ls -al all the user dirs inside “data” and their subdirs have 755 permissions (octal) and www-data:www-data ownership.

Cheers

Sorry than i can not help. But perhaps cut-and-paste errors and configuration. Words often are not completely or with errors. You can change names in cut-and-paste before posting in the forum.

Hi devnull,

all fine thanks. Like stated previously, the error of failed uploads was solved by creating the files subdirectory and if one strictly adheres to the order of executing the individual steps, this approach solves all my problems posted initially.

1 Like