Skip to content

Commit 06fe8b0

Browse files
docs(admin): rewrite deleted files configuration chapter
Update, expand, and clarify trash-bin retention policies, size limits, interactions with quotas, background jobs details, and the various commands based on the current files_trashbin implementation. Assisted-by: Copilot:gpt-5.6-luna Signed-off-by: Josh <josh.t.richards@gmail.com>
1 parent e376814 commit 06fe8b0

1 file changed

Lines changed: 333 additions & 48 deletions

File tree

Lines changed: 333 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,342 @@
1-
=========================
2-
Deleted Items (trash bin)
3-
=========================
1+
=============
2+
Deleted Files
3+
=============
44

5-
If the trash bin app is enabled (default), this setting defines the policy
6-
for when files and folders in the trash bin will be permanently deleted.
5+
Introduction
6+
------------
7+
8+
When a file or folder is deleted, Nextcloud normally moves it to the trash bin
9+
instead of deleting it immediately. This allows the item to be restored later.
10+
11+
Items in the trash bin are permanently deleted when one of the following occurs:
12+
13+
- The account owner selects *Delete permanently*.
14+
- The configured retention policy expires the item.
15+
- The effective trash-bin size limit is exceeded and the item is eligible for
16+
removal to free space.
17+
18+
Logged-in accounts can access their trash bin by selecting *Deleted files* in
19+
the **Files** area of the Nextcloud Web interface. Items in the trash bin can
20+
be restored, downloaded, or permanently deleted.
21+
22+
For information about using the trash bin as an account holder, see the
23+
:doc:`Deleted files <../user_manual/en/files/deleted_file_management>` section
24+
of the User Manual.
25+
26+
.. note:: If the *Versions* app is enabled, versions associated with a deleted
27+
file are moved to the trash bin and are restored when the file is restored.
28+
29+
When a file is restored, Nextcloud attempts to restore it to its original
30+
location. If that location no longer exists or is not writable, the file is
31+
restored to the account's files root. If a file with the same name already
32+
exists, the restored file receives a unique name.
33+
34+
This functionality is provided by the *Deleted files* app, whose application
35+
ID is ``files_trashbin``. The app provides:
36+
37+
- The web interface for viewing, restoring, downloading, and permanently
38+
deleting items.
39+
- The trash-bin filesystem integration.
40+
- Automatic expiration through a background job.
41+
- The ``trashbin:size``, ``trashbin:expire``, ``trashbin:cleanup``, and
42+
``trashbin:restore`` commands.
43+
44+
Policy Configuration
45+
--------------------
46+
47+
The ``files_trashbin`` app uses two related mechanisms to determine when items
48+
are permanently deleted:
49+
50+
- A time-based retention policy configured with
51+
``trashbin_retention_obligation``.
52+
- An effective trash-bin size limit, configured explicitly or calculated from
53+
the account's available space.
54+
55+
The default retention policy is ``auto``. In the default configuration, items
56+
are retained for at least 30 days. After that minimum retention period, eligible
57+
items may be permanently deleted when space is needed.
58+
59+
The default effective trash-bin size is calculated as follows:
60+
61+
- For an account with a quota, the trash bin may use up to 50% of the
62+
account's remaining quota space.
63+
- For an account without a quota, the trash bin may use the available
64+
filesystem space.
65+
- If an explicit global or per-account trash-bin size is configured, that
66+
value overrides the calculated default.
67+
68+
The 50% calculation is based on the account's **remaining** quota space, not
69+
the account's total quota. For example, if an account has a 10 GB quota and is
70+
already using 8 GB, the default trash-bin allowance is calculated from the
71+
remaining 2 GB.
72+
73+
When the effective trash-bin limit is exceeded, Nextcloud processes the oldest
74+
items first. An item can be removed to free space only when it is eligible
75+
under the configured retention policy.
76+
77+
The global retention policy is configured with the
78+
``trashbin_retention_obligation`` setting in ``config/config.php``:
79+
80+
.. code-block:: php
81+
82+
'trashbin_retention_obligation' => 'auto',
83+
84+
Available retention policy values are described below. ``D1`` and ``D2`` are
85+
numbers of days.
86+
87+
``auto``
88+
The default policy. This is equivalent to ``auto, auto``.
89+
90+
Files and folders are retained for at least 30 days. After 30 days, they may
91+
be permanently deleted when space is needed.
92+
93+
``D1, auto``
94+
Files and folders are retained for at least ``D1`` days. After that, they
95+
may be permanently deleted when space is needed.
96+
97+
``auto, D2``
98+
Files and folders may be permanently deleted when space is needed,
99+
regardless of age. In addition, all items older than ``D2`` days are
100+
permanently deleted automatically, even when space is not currently needed.
101+
102+
``D1, D2``
103+
Files and folders are retained for at least ``D1`` days. Items older than
104+
``D2`` days are permanently deleted automatically.
105+
106+
If the effective trash-bin size is exceeded, items older than ``D1`` days
107+
may also be deleted early to free space, oldest first. Items younger than
108+
``D1`` days are protected from size-based cleanup.
109+
110+
Items older than ``D2`` days are deleted automatically even when space is
111+
not currently needed. If ``D2`` is smaller than ``D1``, Nextcloud adjusts
112+
the effective maximum retention period to ``D1``.
113+
114+
``disabled``
115+
Automatic trash-bin expiration is disabled. Files and folders remain in the
116+
trash bin until they are manually deleted or another operation removes them.
117+
118+
A single numeric value is also accepted. The value is used as the minimum
119+
retention period, while the default maximum retention period is 30 days. If
120+
the resulting maximum period would be shorter than the minimum period, the
121+
maximum is raised to match the minimum.
122+
123+
For example, ``10`` is equivalent to ``10, 30``: items are retained for at
124+
least 10 days and are automatically deleted once they exceed 30 days. By
125+
contrast, ``45`` is equivalent to ``45, 45``, because the default maximum
126+
of 30 days is shorter than the 45-day minimum and is therefore raised to
127+
match it.
7128

8129
.. note::
9130

10-
If the user quota limit is exceeded due to deleted files in the trash bin,
11-
retention settings will be ignored and files will be cleaned up until
12-
the quota requirements are met.
13-
14-
The app allows for two settings, a minimum time for trash bin retention,
15-
and a maximum time for trash bin retention.
16-
Minimum time is the number of days a file will be kept, after which it
17-
may be deleted. Maximum time is the number of days at which it is guaranteed
18-
to be deleted.
19-
Both minimum and maximum times can be set together to explicitly define
20-
file and folder deletion. For migration purposes, this setting is installed
21-
initially set to "auto", which is equivalent to the default setting in
22-
Nextcloud.
23-
24-
You may alter the default pattern in ``config.php``. The default setting is
25-
``auto``, which sets the default pattern::
26-
27-
'trashbin_retention_obligation' => 'auto',
28-
29-
Available values:
30-
31-
* ``auto``
32-
default setting. keeps files and folders in the trash bin for 30 days
33-
and automatically deletes anytime after that if space is needed (note:
34-
files may not be deleted if space is not needed).
35-
* ``D, auto``
36-
keeps files and folders in the trash bin for D+ days, delete anytime if
37-
space needed (note: files may not be deleted if space is not needed)
38-
* ``auto, D``
39-
delete all files in the trash bin that are older than D days
40-
automatically, delete other files anytime if space needed
41-
* ``D1, D2``
42-
keep files and folders in the trash bin for at least D1 days and
43-
delete when exceeds D2 days (note: files will not be deleted automatically if space is needed)
44-
* ``disabled``
45-
trash bin auto clean disabled, files and folders will be kept forever
46-
47-
Background job
131+
Unlike ``auto``, ``D1, auto``, and ``auto, D2``, this form (including a
132+
bare numeric value) disables purely space-triggered cleanup of the trash
133+
bin. Items may still be removed early if the trash-bin size limit is
134+
exceeded, but only once they are older than the minimum retention period
135+
(``D1``).
136+
137+
For clarity, use the explicit ``D1, D2`` form when configuring a numeric
138+
retention policy.
139+
140+
Trash-bin Size Limits
141+
---------------------
142+
143+
The ``trashbin:size`` command configures or displays the effective trash-bin
144+
size.
145+
146+
To display the global default and any per-account values:
147+
148+
.. code-block:: console
149+
150+
sudo -u www-data php occ trashbin:size
151+
152+
To configure a global trash-bin size:
153+
154+
.. code-block:: console
155+
156+
sudo -u www-data php occ trashbin:size 10G
157+
158+
To configure a size for a specific account:
159+
160+
.. code-block:: console
161+
162+
sudo -u www-data php occ trashbin:size --user USER_ID 10G
163+
164+
The ``size`` argument accepts values understood by Nextcloud's file-size
165+
parser, such as ``500M`` or ``10G``.
166+
167+
A per-account value takes precedence over the global value. If no per-account
168+
value is configured, the account uses the global value. If neither value is
169+
configured, Nextcloud uses the calculated default based on the account's
170+
remaining quota space or available filesystem space.
171+
172+
To display the configured value for one account:
173+
174+
.. code-block:: console
175+
176+
sudo -u www-data php occ trashbin:size --user USER_ID
177+
178+
Changing a per-account size schedules cleanup for that account. Changing the
179+
global size causes existing trash bins to be cleaned up, although an account's
180+
trash bin can temporarily exceed the newly configured size until cleanup is
181+
performed or another item is moved to the trash bin.
182+
183+
Interaction with Quotas
184+
~~~~~~~~~~~~~~~~~~~~~~~
185+
186+
An explicit trash-bin size is independent of the account quota. It can
187+
therefore be used for accounts both with and without quotas.
188+
189+
For accounts with quotas, the following order applies:
190+
191+
#. A per-account ``trashbin_size`` value is used when configured.
192+
#. Otherwise, the global ``files_trashbin`` ``trashbin_size`` value is used
193+
when configured.
194+
#. Otherwise, the default limit is calculated from 50% of the account's
195+
remaining quota space.
196+
197+
When no explicit trash-bin size is configured for an account without a quota,
198+
the available filesystem space is used to determine whether the trash bin
199+
needs cleanup.
200+
201+
Trash-bin cleanup does not necessarily remove all deleted files when an
202+
account exceeds its quota. Items are removed according to the retention policy
203+
and in oldest-first order until the effective trash-bin space requirement is
204+
satisfied.
205+
206+
Background Jobs
207+
---------------
208+
209+
The ``files_trashbin`` app registers a background job for policies with a
210+
configured maximum retention age, such as ``auto, D2`` and ``D1, D2``. The job
211+
runs at a 30-minute interval, processes accounts in batches of 10, and runs
212+
for no more than 30 minutes per invocation.
213+
214+
For the default ``auto`` policy and other policies without a configured
215+
maximum retention age, the background job does not perform an expiration pass.
216+
For ``disabled``, automatic expiration is disabled.
217+
218+
Space-based cleanup can instead be scheduled when trash-bin usage or available
219+
space changes.
220+
221+
The background job is controlled by the ``files_trashbin`` app configuration
222+
value ``background_job_expire_trash``. It is enabled by default.
223+
224+
To disable the background job:
225+
226+
.. code-block:: console
227+
228+
sudo -u www-data php occ config:app:set \
229+
--value=no files_trashbin background_job_expire_trash
230+
231+
To re-enable it, remove the override:
232+
233+
.. code-block:: console
234+
235+
sudo -u www-data php occ config:app:delete \
236+
files_trashbin background_job_expire_trash
237+
238+
When the background job is disabled, administrators can run expiration
239+
manually with ``occ trashbin:expire`` or configure an external system task to
240+
run that command.
241+
242+
Other Commands
48243
--------------
49244

50-
To permanently delete files a background jobs runs every 30 minutes.
51-
It's possible to deactivate the background job and setup a (system) cron to expire the versions via occ.
245+
The below operations are useful under certain circumstances, but do not typically
246+
need to be used directly.
247+
248+
Expiring Items Manually
249+
~~~~~~~~~~~~~~~~~~~~~~~
250+
251+
To expire eligible items for all accounts:
252+
253+
.. code-block:: console
254+
255+
sudo -u www-data php occ trashbin:expire
256+
257+
To expire eligible items for one or more accounts:
258+
259+
.. code-block:: console
260+
261+
sudo -u www-data php occ trashbin:expire USER_ID
262+
263+
.. code-block:: console
264+
265+
sudo -u www-data php occ trashbin:expire USER_ID_1 USER_ID_2
266+
267+
The command displays a progress bar when processing all accounts. Use
268+
``--quiet`` to suppress the progress bar:
269+
270+
.. code-block:: console
271+
272+
sudo -u www-data php occ trashbin:expire --quiet
273+
274+
For any active retention policy, including the default ``auto`` policy,
275+
``trashbin:expire`` performs a full expiration pass: it deletes items that
276+
exceed the configured maximum age, and it also deletes items to satisfy the
277+
effective trash-bin size limit when needed, subject to the retention
278+
policy's minimum age.
279+
280+
If trash-bin expiration is disabled (``trashbin_retention_obligation`` set
281+
to ``disabled``), ``trashbin:expire`` does not delete any items and exits
282+
with a non-zero status.
283+
284+
Space-based cleanup can also be triggered automatically outside of
285+
``trashbin:expire`` and the background job — for example, when a file is
286+
moved to the trash bin or when a change to the account's available space
287+
causes the effective trash-bin limit to be exceeded.
288+
289+
The trash-bin expiration command is provided by the
290+
``files_trashbin`` app:
291+
292+
.. code-block:: console
293+
294+
sudo -u www-data php occ list files_trashbin
295+
296+
Removing All Trashed Items
297+
~~~~~~~~~~~~~~~~~~~~~~~~~~
298+
299+
To immediately and permanently delete **all** trashed items for all users
300+
from all configured user backends, bypassing the retention policy entirely,
301+
use ``trashbin:cleanup --all-users``:
302+
303+
.. code-block:: console
304+
305+
sudo -u www-data php occ trashbin:cleanup --all-users
306+
307+
To clean up the trash bin for one or more specific accounts:
308+
309+
.. code-block:: console
310+
311+
sudo -u www-data php occ trashbin:cleanup USER_ID_1 USER_ID_2
312+
313+
The command requires either one or more account IDs or ``--all-users``.
314+
These forms are mutually exclusive.
315+
316+
.. danger::
317+
318+
This command deletes trashed items unconditionally and does not honor
319+
the configured retention policy. Deleted items cannot be recovered.
320+
321+
Restoring All Trashed Items
322+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
323+
324+
To restore all trashed items for one or more accounts:
325+
326+
.. code-block:: console
327+
328+
sudo -u www-data php occ trashbin:restore USER_ID_1 USER_ID_2
329+
330+
To restore trashed items for all users from all configured user backends:
331+
332+
.. code-block:: console
52333
53-
Deactivate background job: ``occ config:app:set --value=no files_trashbin background_job_expire_trash``
334+
sudo -u www-data php occ trashbin:restore --all-users
54335
55-
Activate background job: ``occ config:app:delete files_trashbin background_job_expire_trash``
336+
Account IDs and ``--all-users`` are mutually exclusive. The command requires
337+
one or the other.
56338

57-
Expire versions: ``occ trashbin:expire`` or ``occ trashbin:expire --quiet`` (without the progress bar)
339+
The command supports additional filters, including ``--since``, ``--until``,
340+
and ``--scope`` (``user``, ``groupfolders``, or ``all``), as well as
341+
``--dry-run`` to preview which items would be restored without performing any
342+
action. See ``occ trashbin:restore --help`` for details.

0 commit comments

Comments
 (0)