Xjjdoc.cn has a detailed classification of 200+ original articles, making it easier to read. Welcome to collect.
Every year, there is news that the library has been deleted and run away. In reality, it is easy to delete libraries, but difficult to run away. Practitioners are full of tears.
It’s not always subjective malice, it’s just that the commands are too dangerous. When operating online, be sure to keep a clear head and remember to be careless.
Who believes you when you say you misoperated?
Be sure to keep in mind:
- Do not log in to the online server after drinking
- It is strictly forbidden to log in the online server after a quarrel
- It is strictly prohibited to operate the online environment after working overtime for a long time
- Do not try unfamiliar commands online
- Backup important systems first
1. Preparation
Take a deep breath when executing a dangerous command. First run ifconfig, or IP addr, to verify that you are on the correct server.
$ ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host LO valid_lft forever preferred_lft forever Inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 00:16:3e:34:e9:a9 BRD FF :ff:ff:ff:ff: FF inet 172.19.26.39/20 BRD 172.19.31.255 scope Global Dynamic noprefixroute eth0 VALID_lft 313267185sec preferred_lft 313267185sec inet6 fe80::216:3eff:fe34:e9a9/64 scope link valid_lft forever preferred_lft foreverCopy the code
At this point, take another deep breath and run the PWD command to make sure you are in the correct directory.
$ pwd
/etc/nginx
Copy the code
And then you can see if the command you’re executing is a dangerous command.
2. Run the rm -rf command
-rf Deletes files recursively, causing data loss. If there is an extra space, or/is not complete, or the file has a special symbol, resulting in the error operation of the file deletion is mostly.
rm -rf ./* => rm -rf /
rm -rf abc/ => rm -rf abc /
Copy the code
Run the rm command at a slow speed. Press complete, be sure to wait until the screen displays the operation.
In addition, the rm pit in the script is not small, for example:
rm -rf ${p}/*
Copy the code
If the p variable is not set, the result is disastrous, and the command is equivalent to rm -rf /. So rm has another piece of advice: before executing rm in a script, check whether the relevant variables are empty.
3. The chmod command
Chmod is used to change directory and file permissions. If not handled properly, chmod has the same consequences as RM.
Here’s a very heavy-handed approach to recovery. Before executing this command, back up all file permissions. This uses the getfacl command.
getfacl -R / > chmod.txt
Copy the code
During recovery, execute
setfacl --restore=chmod.txt
Copy the code
It will play back the file’s permissions, sometimes saving lives.
4. The cat command
Can the cat command also fail? Yes, and seriously, because you’ve mastered an advanced skill: redirects.
If you want to append something to a file, you use cat >> file. If you accidentally type one less >, sorry, your file is lost.
Echo echo echo echo echo echo echo echo echo echo echo echo echo echo
Before you do this, be sure to count the arrows with each deep breath.
5. The dd command
The DD command is cool and echoes xJjDog’s JJ. The command is as follows:
dd if=/dev/zero of=/dev/sda bs=512 count=1
Copy the code
The above command is used to format the hard disk. If you have this command in your clipboard, and it accidentally gets stuck in the command line, your data will evaporate.
6. The cp command
The cp command will overwrite, and if you regret it, it will be very difficult to find the original file.
You are advised to add alias cp =’cp -i’. The I parameter indicates that a backup will be generated during copy. Most of the time it doesn’t work. Sometimes it works.
The same way we buy insurance.
Similar to the mv command, you can also add -i.
7. The tar command
Don’t think tar is safe. I’ve lost data with tar.
First, if the decompressed tar -xf file is already in the current directory, overwrite the original folder and files. Overwriting these two words, a lot of times means unsafe.
8. Vim command
Vim is prone to open large files, resulting in high memory usage. If oom-killer of the operating system is triggered, other normal processes will die.
If you run :wq too fast, the file will be inconsistent or even corrupted.
Use commands like less or more to view information. It’s more efficient and it’s safer.
If you really have to use Vim, keep using the View command, which is vim’s read-only mode.
9. mkfs.*
Commands like mkfs.ext4, which will format the hard disk, are generally used for online environment initialization, otherwise do not execute.
10. MySQL
(1) use mysql -u
--safe-updates, --i-am-a-dummy, -U
Copy the code
Use mysql -u to prevent delete and update operations without WHERE conditions. When an UPDATE or DELETE is issued without the WHERE or LIMIT keyword, mysql refuses to execute it.
Alias is also a good helper. You can set alias like this:
alias mysql='mysql -U'
Copy the code
(2) Use transactions for important operations
Start transaction Confirms commitCopy the code
(3) DML error rollback, can use binlog2SQL
(4) Be careful with DDL operations
DDL often means huge potholes, table locks, deletions, data shifts, and often catastrophic. DDL operations on the entire table, or all rows and columns in the table, create exclusive locks, which generate crazy I/OS and seriously affect production.
Any one of these could be fatal.
Take a close look at the DDL, try to do it at the bottom of the business, and try to do it inplace.
End
Online is worth ten thousand dollars. Be careful. Caution is the ultimate driver. In a dangerous online environment, the pursuit of things is not fast, but steady.
After all, in mature companies, the approval phase can take days, so why do you care so much about a few seconds?