Backup SQL scripts for MySQL database backup and encryption

Source: Internet
Author: User
Tags decrypt gpg

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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.