Configuring a Recycle Bin for Network Shares in CentOS
To implement a recycle bin feature for network-shared folders in CentOS (typically via Samba), follow these structured steps. This ensures deleted files are retained in a structured recovery directory instead of being permanently removed.
1. Install and Enable Samba
First, ensure Samba is installed (required for network sharing) and its dependencies are up to date.
sudo yum install samba samba-client samba-common -y
sudo systemctl start smb
sudo systemctl enable smb
2. Create the Shared Folder and Recycle Bin Directory
Choose a directory to share (e.g., /data/shared) and create a subdirectory for the recycle bin (e.g., .recycle). The recycle bin directory will store deleted files, organized by user (using %U for the username).
sudo mkdir -p /data/shared
sudo mkdir -p /data/shared/.recycle
3. Configure Samba for the Shared Folder
Edit the Samba configuration file (/etc/samba/smb.conf) to define the shared folder and enable the recycle bin feature. Add the following section at the end of the file:
[SharedFolder]
comment = Shared Folder with Recycle Bin
path = /data/shared
browseable = yes
writable = yes
valid users = @shared_users # Replace with your user/group
create mask = 0775
directory mask = 0775
vfs objects = recycle
recycle:repository = .recycle/%U # Per-user recycle bin
recycle:keeptree = yes # Retain original directory structure
recycle:versions = yes # Keep multiple versions of files
recycle:maxsize = 0 # Unlimited size (set to a value like 100M for limits)
recycle:exclude = *.tmp|*.log # Files to exclude from recycle bin
Key parameters:
vfs objects = recycle: Enables the recycle bin module.recycle:repository = .recycle/%U: Stores deleted files in a.recyclesubdirectory named after the user (e.g.,.recycle/john).recycle:keeptree = yes: Maintains the original folder structure of deleted files.recycle:versions = yes: Prevents overwriting of files with the same name (keeps versions).
4. Set Permissions for the Shared Folder
Ensure the shared folder and recycle bin have correct ownership and permissions. Replace shared_users with your actual user/group:
sudo chown -R root:shared_users /data/shared
sudo chmod -R 2775 /data/shared # Sets SGID to inherit group ownership
sudo chmod -R 1777 /data/shared/.recycle # Sticky bit: Users can only delete their own files
5. Create a Samba User and Restart Services
Add a Samba user (must be a system user first) and restart Samba to apply changes:
sudo useradd -m shared_user # Create system user
sudo smbpasswd -a shared_user # Set Samba password
sudo systemctl restart smb
6. Mount the Shared Folder on a Client (Optional)
To test the shared folder from a Windows client, map it using the UNC path (\\) and provide the Samba credentials. Deleted files will now appear in the .recycle/ directory on the CentOS server.
Key Notes
- Exclusions: Modify
recycle:excludeto skip temporary files (e.g.,*.tmp,*.log) from the recycle bin. - Size Limits: Set
recycle:maxsizeto a specific value (e.g.,100M) to prevent the recycle bin from consuming too much disk space. - Automatic Cleanup: Use
cronjobs to periodically empty old files from the recycle bin (e.g., delete files older than 30 days). - Firewall: Ensure the firewall allows Samba traffic (ports 137-139 and 445) if using a firewall.
This setup provides a functional recycle bin for network shares, ensuring data recovery and structured file management.
以上就是关于“CentOS回收站网络共享”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm