CentOS回收站网络共享
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.recycle
subdirectory 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 (\\<
CentOS_IP>
\SharedFolder
) and provide the Samba credentials. Deleted files will now appear in the .recycle/<
username>
directory on the CentOS server.
Key Notes
- Exclusions: Modify
recycle:exclude
to skip temporary files (e.g.,*.tmp
,*.log
) from the recycle bin. - Size Limits: Set
recycle:maxsize
to a specific value (e.g.,100M
) to prevent the recycle bin from consuming too much disk space. - Automatic Cleanup: Use
cron
jobs 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.
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: CentOS回收站网络共享
本文地址: https://pptw.com/jishu/718784.html