Skip to main content

Trash

JuiceFS keeps deleted files in Trash for a certain period of time before the actual deletion from object storage. Files remain billable even in Trash. Users may restore or delete files from Trash in JuiceFS console.

Trash is automatically enabled when users create a file system. Default expiration is 1 day for free plan, 7 days for professional plan. Users may modify this setting in JuiceFS Console.

Move files to Trash

Execute the rm command in shell, target files will be moved into the Trash directory. But when it comes to deleting large amount of files, we recommend using juicefs rmr, this command deals with metadata directly (bypassing POSIX API), thus is much faster.

Being moved to Trash, these files will no longer be a part of the original directory, but the actual data is still kept in object storage. If the path of deleted files already exists in Trash, multiple versions will be kept.

Note that Trash does not apply to the following conditions:

  • Trash is only valid for files, the directory will be deleted immediately. When restoring files, the original directory structure is restored, but the previous directory attributes cannot be maintained. In particular, if an empty directory is deleted, it cannot be recovered.
  • Trash does not apply to the command juicefs snapshot -d <path> which will delete the snapshot immediately instead of moving it to Trash. However, snapshot deleted using rm <path> will be moved to Trash instead.
  • Trash does not apply to files created by juicefs import. The metadata of the imported files will be deleted immediately, while the content in object storage is not affected.

Delete from Trash

Files remain billable even in Trash (object storage, too). Users can manually delete files from Trash in JuiceFS Console:

  1. Switch to the "Trash" tab in the file system page
  2. Select one or more files to be deleted
  3. Click "Delete" button

You can also achieve this under the .trash directory under the root directory of the mount point, but note that due to performance reasons, the maximum number of files that can be viewed in this directory is limited to 1 million. Assuming mount point being /jfs, use something like this:

# If .trash directory is not found, upgrade JuiceFS Client and remount
cd /jfs
# If .trash directory contains more than a million files, depending on distribution, this command may not be able to cover all target files
find .trash -name '*.tmp' | xargs rm -f

Once deletion is submitted, file metadata will be removed from the Metadata server, and these files will cease to contribute to JuiceFS billing. But know that the object storage blocks will remain and always be scheduled to garbage collection according to the trash expiration time at which files are deleted. Changing expiration time after deleting files from trash will not affect object storage deletion schedule for files previously deleted.

For files already deleted, chunks in object storage are not deleted strictly according to its expiration time, so if you noticed that chunks aren't deleted on time, no need to worry too much because JuiceFS carries out garbage expiration in a fixed speed, by telling clients to execute GC in background jobs, asynchronously. That's why at least one JuiceFS Client must be started (must not disable background job) for Trash to function correctly. All JuiceFS Client (FUSE mount, Hadoop Java SDK, and S3 Gateway) behaves roughly the same way in this regard. If no JuiceFS Client is running at all, files in trash will not be expired and garbage collected.

Restore from Trash

Users can restore files from Trash in JuiceFS Console

  1. Switch to the "Trash" tab in the file system page
  2. Select one or more files to be restored
  3. Click "Restore" button

You can also achieve this under the .trash directory under the root directory of the mount point, but note that due to performance reasons, the maximum number of files that can be viewed in this directory is limited to 1 million. Assuming mount point being /jfs, use something like this:

# If .trash directory is not found, upgrade JuiceFS Client and remount
cd /jfs
# If .trash directory contains more than a million files, depending on distribution, this command may not be able to cover all target files
find .trash -name '*.tar.gz' -exec mv {} . \;

When recovering files from trash, know that:

  • The parent directories of the files will be created automatically and owned by root (similar to sudo mkdir -p), which might be different from the original ownership and permissions and needs manual adjustment.
  • If the path of file to be restored already exists, the restore operation will append a sequence number to the file name to avoid name collision, such as the file /a/b/c.txt in trash will be restored to /a/b/c.txt-1.
  • If multiple files are selected to restore, they will be restored in the listed order. Files whose path conflict with the ones restored before them will be skipped.