Somehow at least one user on our NC has uploaded a lot of .nextcloud placeholder files to the server (I’m assuming they switched from VFS to local syncing without cleaning out their dedicated external hard drive.) However, I haven’t been able to determine which user did this, so I have to assume that any and all users have uploaded these files.
Unfortunately, the files are scattered all throughout hundreds, or more, folders and the NC web UI doesn’t present search results of files in way that I can search for “.nextcloud”, select all, and delete them. Now I’m trying to determine whether occ can help me find and remove all these placeholder files. My 2 primary questions concerning this, as I haven’t seen them addressed or documented are:
Can occ files search based on file type alone, or with a wildcard for the actual filename?
Can occ files perform a search across all user accounts without having to re enter the command for each individual user?
To help prevent more being uploaded, I have set up a file access flow to deny clients the ability to upload these files, but now I need to address the ones already on the server.
this can be done using a script to scrape the data directory on the host using find & delete followed by occ files:scan --all
here’s an example script for deleting all files in a defined path, min. directory depth 2, older than 7 days. you’ll need to adjust it to suit your needs for finding certain files with defined extension i.e. find $TARGET -type f -name "*.nextcloud" -delete ;
#!/bin/bash
##############################################################
# DESCRIPTION #
##############################################################
# Find and delete all files from a defined nextcloud path
# older than 7 days, run script daily as root cronjob
##############################################################
# VARIABLES #
##############################################################
LOG=".../logs/nextcloud-cleanup.log" ## define path to logfile
TARGET="/.../nextcloud/data/__groupfolders/1" ## define target
##############################################################
# SCRIPT #
##############################################################
### become root for manual issue, otherwise root crontab
sudo pwd;
### find and delete files and directories! mindepth 2
sudo find $TARGET -mindepth 2 -mtime +7 >>$LOG ;
sudo find $TARGET -mindepth 2 -mtime +7 -delete ;
### Nextcloud cleanup jobs
echo "SCAN FILES AND PERFORM SOME MAINTENANCE";
sudo occ files:repair-tree -n -vvv;
sudo occ files:scan --all -n -vvv;
sudo occ files:scan-app-data -n -vvv;
sudo occ files:cleanup -n -vvv;
## force purge trashbin per user and groupfolders
echo "PURGE TRASHBIN";
sudo occ trashbin:cleanup --all-users ;
sudo occ groupfolders:trashbin:cleanup -f ;
exit