Just follow the 3 steps below, and everything is under your control:
First step: Configure the backup directory code on the server:
--------------------------------------------------------------------------------
Mkdir/var/lib/mysqlbackup
Cd/var/lib/mysqlbackup
--------------------------------------------------------------------------------
Step Two: Write 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= "Passwor" D "# List of Dbnames for Backup dbname=" dbname "#date timestamp to 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: Use Crontab to execute backup script code regularly:
--------------------------------------------------------------------------------
Crontab-e
--------------------------------------------------------------------------------
If you back up 3 o'clock in the afternoon 20 daily, add the following code,
Code:
--------------------------------------------------------------------------------
* * */var/lib/mysqlbackup/dbbackup.sh
--------------------------------------------------------------------------------
Get!
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.