Hi there!
I have a Nextcloud 15 installation with more than 1000 users and LDAP auth.
Each user receives some shared files every day, so very soon his root folder is becoming a mess.
Is there any way to automatically move some (not all with a config parameter) files to another folder?
I know it can be done via webdav, but you mus know the password of each user to do this.
Can I use cron for this task?
Or maybe it’s better to user PostLogin hook?
Please show me a way to control files that was shared to user without knowing user’s password.
No, it did not work (
I need to move shared files using some logic, so I think that my way is to use Hooks…
If someone has ever done something like this, please suggest a direction)
config.php:
‘skeletondirectory’ => ‘/var/www/nextcloud/data/skeleton/’,
In /var/www/nextcloud/data/skeleton/ there is a SharedFiles folder
Then running shell script (to create SharedFiles folder for already active users):
for d in */ ; do
mkdir -p "$d"SharedFiles
echo “$d”
done
echo “changing ownership”
chown -R www-data:www-data /var/www/nextcloud/data/
echo “ownership changed”
echo “rescanning data folders”
sudo -u www-data /usr/bin/php /var/www/nextcloud/./occ files:scan --all
echo “folders rescanned”
“Finished!”
exit 0
Run sql script:
UPDATE oc_share SET file_target = ‘/SharedFiles’ || file_target where item_type = ‘file’ and file_target not ilike ‘/SharedFiles/%’ and uid_owner in (select distinct uid FROM public.oc_group_admin as admin_list);
The SQL script will run by cron
UPD ‘skeletondirectory’ => ‘/var/www/nextcloud/data/skeleton/’, seems not working now for ldap and local users
Could be not most efficient way to do this (for me it takes too long), you can do rescan of exact folder for exact user. This will reduce time to rescan, e.g.
... --path "user_id/files/path"
or
... --path "user_id/files/mount_name"
or
... --path "user_id/files/mount_name/path"
I wrote short script to rescan external shares only and run it via cron like few times per day, it is few times faster as rescan --all.
Also make chown of whole data folder on a bigger installations will be inefficient. Try to find “wrong” users and then execute chown, e.g. (took it from here, explanation):
Thank you very much for improvements!
scan --all is because the script will be run only once, I’ve fixed the skeleton folder (seems that the order of parameters in config.php matters)
for using scan --path the boolean variable ‘directory_created’ would be needed to determine the need to rescan the folder
And special thanks for find /var/www/nextcloud/data/ ! -user www-data -exec chown www-data:www-data {} \!
Hi, just to inform other users, which are searching for a solution.
I had the same problem and wrote a Nextcloud App, which can be installed on the server, which automatically moves shared folders to a new custom directory. The app is based on PHP and is completely integrated into the Nextcloud server. It listens for share events and directly modifies them.
I am using this app together with the Les Pas Android app to share and edit pictures with my family.