In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
For rm this command is quite evil, if there is no backup it is quite difficult to restore, but now it seems that there is a tool called extundelete can restore, but need to uninstall the partition, if the root partition deleted, it is not good to do!! However, there are ways to prevent rm from being deleted by mistake. The methods are as follows:
There is a recycl.zip package, in fact, there are two scripts, recycle script and rm script. I have made a slight modification to the two scripts. If there are more machines, you can build saltstack or puppet tools. What we did at that time was combined with saltstack. You can push commands to salt client on master salt. It is very convenient. The premise is to build salt master and salt client on the server. When building salt, you need to build yum source of salt. Install this package epel-release-6-8.noarch.rpm. yum install -y salt.
To use the recycle program, manually execute the following two commands
mkdir ~/.recycle ###Create recycle directory (this step was added in script)
alias rm='/usr/local/bin/rm' ### /usr/local/rm Change to the path where rm is stored in the attachment (this can be pushed using salt)
Note: rm This path must be other than/bin/rm and/sbin/rm, because it will call the/bin/rm and/sbin//rm commands first, so it will not take effect.
(mv recycle.zip /usr/loca/bin
cd /usr/local/bin
unzip recycle.zip
chmod +x recycle
chmod +x rm)
There are two commands in the attachment: rm and recycle
1.rm Delete files and folders, usage is similar to the rm command
2.recycle Display the contents of the recycle bin: it can be sorted by name or by deletion time.
recycle -d can enter the mode of sorting the recycle bin: the usage example is as follows
recycle -d -empty Empty the recycle bin
recycle -d -t 3 Empty files from 3 days ago
recycle -d -s 5 Empty files over 5 MB
recycle -d -t 3 -s 5 Empty files larger than 5 MB 3 days ago
Changes in script:
In order to avoid interaction in the scheduled task, the script that prompts yes or no is deleted. The #line represents the original one, and the following line is changed by itself.
recycle : ###yesOrNo "empty the recycle " && $RM -rfv $RECYCLE_DIR/* && echo.ok recycle emptyed || return 0
$RM -rfv $RECYCLE_DIR/* && echo.ok recycle emptyed
rm: 1. Determine whether the ~/.recycle directory exists: Add to script: [ -d ~/.recycle ]|| mkdir ~/.recycle
2. Add a warm reminder to ××× back
mv -- "$1" "${RECYCLE_DIR}/${DATE}_${st}_${1}" \
&& echo.ok removed $t \`$1\`;
echo ------------------------------;
echo "If you need to recover, please go to the ~/.recycle directory to retrieve it. "
Execute on the salt master server, push process:
cd /srv/salt/files (rm recycle directory)
salt '*' cp.get_file salt://files/rm /usr/local/bin/rm (* represents all clients under salt)
salt '*' cp.get_file salt://files/recycle /usr/local/bin/recycle
salt '*' cmd.run 'chmod a+x /usr/local/bin/rm'
salt '*' cmd.run 'chmod a+x /usr/local/bin/recycle'
salt '*' cmd.run 'echo "alias rm='/usr/local/bin/rm'" >> /etc/bashrc'
salt '*' cmd.run 'source /etc/bashrc'
Add scheduled tasks on the salt master server:
crontab -e
* 5 */15 * * /usr/bin/salt '*' cmd.run '/usr/local/bin/recycle -d -empty' &> /dev/null
* 1 */15 * * /usr/bin/salt '*' cmd.run '/bin/mv /home/dev/.recycle/* /root/.recycle/' &> /dev/null
* */1 * * * /usr/bin/salt '*' cmd.run '/usr/local/bin/recycle.sh' &> /dev/null
[root@redmine files]# cat recycle.sh
#!/ bin/bash
size=`du /root/.recycle/ | awk '{print $1}'`
date=`date +%F`
if [ $size -gt 10485760 ]; then
recycle -d -empty &> /dev/null
echo "Date deleted: $date" >>/var/log/recycl. log
fi
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.