There was a long time ago csdn the user "Account password Disclosure" event, if their 09-year backup file is encrypted, I think the loss will not be so heavy. So when we back up the database, we also need to encrypt the backup file, in the past in case. The following is a script that backs up MySQL and encrypts it.
The code is as follows |
Copy Code |
#!/bin/sh #mysqlbackup #加密的密码 Encryptpasswd= "123456" Cd/usr/local/mysql/bin ./mysqldump--opt-uroot-p ' 123444 ' dbname |gzip-9 >/usr/local/mysqlbackup/db-' date + '%y-%m-%d_%h-%m '. gz Cd/usr/local/mysqlbackup Echo ${ENCRYPTPASSWD} | GPG--yes-c--passphrase-fd 0 db-' date + '%y-%m-%d_%h-* '. gz #删除源文件 RM-RF db-' date +%y-%m-%d_%h-* '. gz #删除20天前的备份 Find/usr/local/mysqlbackup-mtime +20-name "*.gz"-exec rm-rf {}; |
Decrypt the file gpg db-backup.gz.gpg and then enter the password.
Under Linux, you can use the GPG command to encrypt and decrypt files, and GPG will be pre-installed in almost every release.
If you want to encrypt a file named Diary.txt, simply type:
The code is as follows |
Copy Code |
Gpg-c Diary.txt |
The dialog box will automatically pop up to ask for an encrypted password:
After two input password to determine, will be in the directory generated DIARY.TXT.GPG, this is the encrypted file, do not forget to delete the original document OH ~
In the case of decryption, enter:
The code is as follows |
Copy Code |
GPG DIARY.TXT.GPG |
Enter the correct password and the diary.txt will be regenerated in the current directory.
The commands for encrypting file Z1 using the AES256 algorithm are:
The code is as follows |
Copy Code |
#gpg--cipher-algo aes256-c Z1.txt |