Difference between revisions of "RecycleBin"

From SME Server
Jump to navigationJump to search
(→‎Extras: add instructions to modify templates-custom.)
 
(22 intermediate revisions by 7 users not shown)
Line 1: Line 1:
 +
{{Languages}}
 
===Problem===
 
===Problem===
Deleted files in ibays are lost forever.
 
  
===Scenario===  
+
Deleted files in ibays or in users home directories on the server are lost forever.
 +
 
 +
=== Scenario ===  
 +
 
 
This has been a long known issue for network admins. Files stored on another computer/server. Accidentaly hit the DELETE key. Poof! Gone. Files aren't in the local Recycle bin on the local computer. This is especially frustrating for admins who map profile parts back to the server. The users desktop, documents, etc never find their way into the local recycle bin as the users expect.
 
This has been a long known issue for network admins. Files stored on another computer/server. Accidentaly hit the DELETE key. Poof! Gone. Files aren't in the local Recycle bin on the local computer. This is especially frustrating for admins who map profile parts back to the server. The users desktop, documents, etc never find their way into the local recycle bin as the users expect.
  
===Solution===
+
=== Enable Recycle Bin for ibays ===
Turn on the Recycle Bin.
 
  
 
  db accounts setprop ibayname RecycleBin enabled
 
  db accounts setprop ibayname RecycleBin enabled
 +
db accounts setprop ibayname KeepVersions enabled
 
  signal-event ibay-modify ibayname
 
  signal-event ibay-modify ibayname
  
An admin can now go and retrieve the files on the server.
+
The first property enables the Recycle Bin feature. The second property KeepVersions ensures that when a file is deleted with the same name as one that was previously deleted the latest deleted file will be called “Copy #x of filename”.
 +
 
 +
=== Enable Recycle Bin for users ===
 +
 
 +
db configuration setprop smb RecycleBin enabled
 +
db configuration setprop smb KeepVersions enabled
 +
 
 +
Expand the template...
 +
 
 +
/sbin/e-smith/expand-template /etc/samba/smb.conf
 +
 
 +
Remember to restart service...
 +
 
 +
/etc/rc7.d/S91smb restart
 +
 
 +
{{Warning box|After making changes with the commands shown, you need to logoff your workstation and log back in again so those new access permissions are included in your login session. Recycle Bin will then function as expected.}}
 +
 
 +
The Recycle Bin folder will be created automatically the first time a file is deleted, so you will not see the folder until you delete something.
 +
 
 +
An admin can then go and retrieve the files on the server.
 +
 
 +
=== Recycle Bin Locations ===
 +
 
 +
For ibays the Recycle Bin is located at:
 +
 
 +
/home/e-smith/files/ibays/ibayname/files/Recycle Bin
 +
 
 +
For users the Recycle Bin is located at:
 +
 
 +
/home/e-smith/files/users/username/home/Recycle Bin
 +
 
 +
=== Automatic Cleaning Of Recycle Bin Content ===
 +
 
 +
The simple script below can be used to clean out the various Recycle Bins on a regular basis.
 +
 
 +
Note that this script is setup to use the last changed file attribute to selectively deletes files after they have been in the Recycle Bin for 30 days.
 +
 
 +
Setup the script to run either daily or weekly from cron.
 +
{{Tip box |msg= If after running the script you receive empty notification emails and you've checked the date flags of the files in the recycle bin and know that they should be removed, try changing the '-ctime' parameter to '-mtime'. [[bugzilla:7596]]
 +
You can check the output by running this at the command prompt to see if any files are now being flagged for removal (you can adjust the number of days as you wish):
 +
 
 +
find /home/e-smith/files/users/*/home/Recycle\ Bin/* -type f -mtime +30 -print }}
 +
<pre>
 +
#!/bin/bash
 +
 
 +
# ensure finds includes hidden files in the Recycle Bins
 +
shopt -s dotglob
 +
 
 +
echo "+------------------------------------------------------------------------------+"
 +
echo "|                          Samba recycle-bin cleaner                          |"
 +
echo "+------------------------------------------------------------------------------+"
 +
 
 +
URF=$(find /home/e-smith/files/users/*/home/Recycle\ Bin/* -type f -ctime +30)
 +
if [ "$URF" !=  "" ]
 +
then
 +
    printf "| %-76s |\n" "The following user recycle bin files were deleted:"
 +
    IFS=$'\n'
 +
    for file in $URF
 +
    do
 +
        printf "| - %-74s |\n" "$file"
 +
        rm -f "$file"
 +
    done
 +
else
 +
    printf "| %-76s |\n" "There were no old user recycle bin files to delete."
 +
fi
 +
 
 +
echo "+------------------------------------------------------------------------------+"
 +
 
 +
IRF=$(find /home/e-smith/files/ibays/*/files/Recycle\ Bin/* -type f -ctime +30)
 +
if [ "$IRF" !=  "" ]
 +
then
 +
    printf "| %-76s |\n" "The following ibays recycle bin files were deleted:"
 +
    IFS=$'\n'
 +
    for file in $IRF
 +
    do
 +
        printf "| - %-74s |\n" "$file"
 +
        rm -f "$file"
 +
    done
 +
else
 +
    printf "| %-76s |\n" "There were no old ibays recycle bin files to delete."
 +
fi
 +
 
 +
echo "+------------------------------------------------------------------------------+"
  
 +
URD=$(find /home/e-smith/files/users/*/home/Recycle\ Bin/* -type d -empty)
 +
if [ "$URD" != "" ]
 +
then
 +
    printf "| %-76s |\n" "The following users recycle bin directories were deleted:"
 +
    IFS=$'\n'
 +
    for folder in $URD
 +
    do
 +
        printf "| - %-74s |\n" "$folder"
 +
        rm -rf "$folder"
 +
    done
 +
else
 +
    printf "| %-76s |\n" "There were no old user recycle bin directories to delete."
 +
fi
  
===Extras===
+
echo "+------------------------------------------------------------------------------+"
To change recyclebin name you must to change this files
 
  
/etc/e-smith/templates/etc/smb.conf/10recyclebin
+
IRD=$(find /home/e-smith/files/ibays/*/files/Recycle\ Bin/* -type d -empty)
/etc/e-smith/templates/etc/smb.conf/ibays/10recyclebin
+
if [ "$IRD" != "" ]
 +
then
 +
    printf "| %-76s |\n" "The following ibays recycle bin directories were deleted:"
 +
    IFS=$'\n'
 +
    for folder in $IRD
 +
    do
 +
        printf "| - %-74s |\n" "$folder"
 +
        rm -rf "$folder"
 +
    done
 +
else
 +
    printf "| %-76s |\n" "There were no old ibays recycle bin directories to delete."
 +
fi
  
Modifying this line: <br>
+
echo "+------------------------------------------------------------------------------+"
    $vfs->{recycle}->{repository} = "Recycle Bin";<br>
+
</pre>
<br>
 
Where you change the "Recycle Bin" for something else. Eg. In Brazil would be "Lixeira"<br>
 
The SME way to do this is to create a custom template. Try to avoid change those files directly! <br>
 
  
To change the custom-template do this:
+
=== Changing the Recycle Bin name ===
  
* Create the proper folder structure:
+
You can change the name of the recycle bin by making a copy of the template fragment into the templates-custom tree and making your modifications there.
 +
<ol></li><li>Create the proper folder structure:
  
 
  mkdir -p /etc/e-smith/templates-custom/etc/smb.conf/ibays
 
  mkdir -p /etc/e-smith/templates-custom/etc/smb.conf/ibays
  
* Copy the template fragment to the template-custom tree
+
</li><li>Copy the template fragment to the template-custom tree
  
 
  cp /etc/e-smith/templates/etc/smb.conf/ibays/10recyclebin /etc/e-smith/templates-custom/etc/smb.conf/ibays
 
  cp /etc/e-smith/templates/etc/smb.conf/ibays/10recyclebin /etc/e-smith/templates-custom/etc/smb.conf/ibays
  
* Use any editor to make your changes in the copied file
+
</li><li>Use any editor to make your changes in the copied file
 +
 
 +
nano /etc/e-smith/templates-custom/etc/smb.conf/ibays/10recyclebin
 +
Modifying this line:
 +
 
 +
$ibay_vfs->{recycle}->{repository} = "Recycle Bin";
 +
 
 +
to whatever you like for a name:
 +
 
 +
$ibay_vfs->{recycle}->{repository} = "Add your name here";
 +
{{Tip box|You can make the recycle bin hidden by adding a dot as a first character of the recycle bin name}}
  
vi /etc/e-smith/templates-custom/etc/smb.conf/ibays/10recyclebin
+
</li><li>Now let the server take the necessary actions to have the changes reflected for all ibays (replace <nowiki><ibayname></nowiki> with the ibayname):
Modifying this line: <br>
 
    $vfs->{recycle}->{repository} = "Recycle Bin";<br>
 
to
 
    $vfs->{recycle}->{repository} = "Lixeira";<br>
 
(or whatever name you like) and save your changes after finish making modifications (use ESC :wq on vi editor)
 
  
* Now let the server take the necessarry actions to have the changes reflected for the ibays
 
 
  signal-event ibay-modify <ibayname>
 
  signal-event ibay-modify <ibayname>
where <ibayname> is the ibay you´re changing to have a RecycleBin name different.<br>
+
</li></ol>
 
 
  
<br>
 
TIP: <br>
 
1) If your name has a DOT as first character, so it will be invisible! Eg: ".Lixeira"<br>
 
You could try by doing modification directly on /etc/e-smith/templates/etc/smb.conf/10recyclebin and if it works, change the template-custom.
 
<br><br>
 
2) I prefer this way because if I mess with something, I can just rebuild template using the signal-event stated above.
 
  
 
----
 
----
 
[[Category: Howto]]
 
[[Category: Howto]]
 +
[[Category:Administration:File and Directory Access]]

Latest revision as of 12:43, 13 January 2019


Problem

Deleted files in ibays or in users home directories on the server are lost forever.

Scenario

This has been a long known issue for network admins. Files stored on another computer/server. Accidentaly hit the DELETE key. Poof! Gone. Files aren't in the local Recycle bin on the local computer. This is especially frustrating for admins who map profile parts back to the server. The users desktop, documents, etc never find their way into the local recycle bin as the users expect.

Enable Recycle Bin for ibays

db accounts setprop ibayname RecycleBin enabled
db accounts setprop ibayname KeepVersions enabled 
signal-event ibay-modify ibayname

The first property enables the Recycle Bin feature. The second property KeepVersions ensures that when a file is deleted with the same name as one that was previously deleted the latest deleted file will be called “Copy #x of filename”.

Enable Recycle Bin for users

db configuration setprop smb RecycleBin enabled
db configuration setprop smb KeepVersions enabled

Expand the template...

/sbin/e-smith/expand-template /etc/samba/smb.conf

Remember to restart service...

/etc/rc7.d/S91smb restart


Warning.png Warning:
After making changes with the commands shown, you need to logoff your workstation and log back in again so those new access permissions are included in your login session. Recycle Bin will then function as expected.


The Recycle Bin folder will be created automatically the first time a file is deleted, so you will not see the folder until you delete something.

An admin can then go and retrieve the files on the server.

Recycle Bin Locations

For ibays the Recycle Bin is located at:

/home/e-smith/files/ibays/ibayname/files/Recycle Bin

For users the Recycle Bin is located at:

/home/e-smith/files/users/username/home/Recycle Bin

Automatic Cleaning Of Recycle Bin Content

The simple script below can be used to clean out the various Recycle Bins on a regular basis.

Note that this script is setup to use the last changed file attribute to selectively deletes files after they have been in the Recycle Bin for 30 days.

Setup the script to run either daily or weekly from cron.

Information.png Tip:
If after running the script you receive empty notification emails and you've checked the date flags of the files in the recycle bin and know that they should be removed, try changing the '-ctime' parameter to '-mtime'. bugzilla:7596

You can check the output by running this at the command prompt to see if any files are now being flagged for removal (you can adjust the number of days as you wish):

find /home/e-smith/files/users/*/home/Recycle\ Bin/* -type f -mtime +30 -print


#!/bin/bash

# ensure finds includes hidden files in the Recycle Bins
shopt -s dotglob

echo "+------------------------------------------------------------------------------+"
echo "|                           Samba recycle-bin cleaner                          |"
echo "+------------------------------------------------------------------------------+"

URF=$(find /home/e-smith/files/users/*/home/Recycle\ Bin/* -type f -ctime +30)
if [ "$URF" !=  "" ]
then
    printf "| %-76s |\n" "The following user recycle bin files were deleted:"
    IFS=$'\n'
    for file in $URF
    do
        printf "| - %-74s |\n" "$file"
        rm -f "$file"
    done
else
    printf "| %-76s |\n" "There were no old user recycle bin files to delete."
fi

echo "+------------------------------------------------------------------------------+"

IRF=$(find /home/e-smith/files/ibays/*/files/Recycle\ Bin/* -type f -ctime +30)
if [ "$IRF" !=  "" ]
then
    printf "| %-76s |\n" "The following ibays recycle bin files were deleted:"
    IFS=$'\n'
    for file in $IRF
    do
        printf "| - %-74s |\n" "$file"
        rm -f "$file"
    done
else
    printf "| %-76s |\n" "There were no old ibays recycle bin files to delete."
fi

echo "+------------------------------------------------------------------------------+"

URD=$(find /home/e-smith/files/users/*/home/Recycle\ Bin/* -type d -empty)
if [ "$URD" != "" ]
then
    printf "| %-76s |\n" "The following users recycle bin directories were deleted:"
    IFS=$'\n'
    for folder in $URD
    do
        printf "| - %-74s |\n" "$folder"
        rm -rf "$folder"
    done
else
    printf "| %-76s |\n" "There were no old user recycle bin directories to delete."
fi

echo "+------------------------------------------------------------------------------+"

IRD=$(find /home/e-smith/files/ibays/*/files/Recycle\ Bin/* -type d -empty)
if [ "$IRD" != "" ]
then
    printf "| %-76s |\n" "The following ibays recycle bin directories were deleted:"
    IFS=$'\n'
    for folder in $IRD
    do
        printf "| - %-74s |\n" "$folder"
        rm -rf "$folder"
    done
else
    printf "| %-76s |\n" "There were no old ibays recycle bin directories to delete."
fi

echo "+------------------------------------------------------------------------------+"

Changing the Recycle Bin name

You can change the name of the recycle bin by making a copy of the template fragment into the templates-custom tree and making your modifications there.

  1. Create the proper folder structure: mkdir -p /etc/e-smith/templates-custom/etc/smb.conf/ibays
  2. Copy the template fragment to the template-custom tree cp /etc/e-smith/templates/etc/smb.conf/ibays/10recyclebin /etc/e-smith/templates-custom/etc/smb.conf/ibays
  3. Use any editor to make your changes in the copied file nano /etc/e-smith/templates-custom/etc/smb.conf/ibays/10recyclebin Modifying this line: $ibay_vfs->{recycle}->{repository} = "Recycle Bin"; to whatever you like for a name: $ibay_vfs->{recycle}->{repository} = "Add your name here";
    Information.png Tip:
    You can make the recycle bin hidden by adding a dot as a first character of the recycle bin name

  4. Now let the server take the necessary actions to have the changes reflected for all ibays (replace <ibayname> with the ibayname): signal-event ibay-modify <ibayname>