MySQL Tutorial: Ways to secure a safe backup of the MySQL database

Source: Internet
Author: User

This is one of the sections of my last article on security. It is a well-known fact that the MySQL database backup of your running Web site is extremely important.

Just follow the 3 steps below, and everything is under your control:

First Step: Configure the backup directory on the server

Code:

Mkdir/var/lib/mysqlbackup
Cd/var/lib/mysqlbackup
Step Two: Write a backup script

Code:

VI dbbackup.sh

Paste the following code, be sure to change the Username,password and dbname.

Code:

#!/bin/sh
#Username to access the MySQL server
Username= "USERNAME"
# Username to access the MySQL server
Password= "PASSWORD"
# List of Dbnames for Backup
Dbname= "DBName"
#date Timestamp for log message
Date= '/bin/date +%y-%m-%d_%hh%mm '
#output file
Outdir= "/var/lib/mysqlbackup/"
Outfile= "Ip_bindass". $DATE. " Sql.gz "
#working Directory
Dir= "/var/lib/mysqlbackup/"
#cd $DIR
# MySQL Backup
/usr/bin/mysqldump--database $DBNAME--opt--single-transaction-u$username-p$password /usr/bin/gzip-9 > $ Outdir$outfile

Change Backup Script Permissions

Code:

chmod +x dbbackup.sh


Step three: Perform backup scripts with crontab timing

Code:

Crontab-e

If you back up 3 o'clock in the afternoon 20 daily, add the following code,

Code:


Get!



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.