You only need to follow the three steps below, and everything is under your control:
Step 1: configure the backup directory on the server Code :
--------------------------------------------------------------------------------
Mkdir/var/lib/mysqlbackup
CD/var/lib/mysqlbackup
--------------------------------------------------------------------------------
Step 2: Write the backup script code:
--------------------------------------------------------------------------------
VI dbbackup. Sh
--------------------------------------------------------------------------------
Paste the following code 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 permission
Code:
--------------------------------------------------------------------------------
Chmod + x dbbackup. Sh
--------------------------------------------------------------------------------
Step 3: Use crontab to regularly execute the backup script code:
--------------------------------------------------------------------------------
Crontab-e
--------------------------------------------------------------------------------
If you back up data at three o'clock P.M. every day, add the following code,
Code:
--------------------------------------------------------------------------------
20 15 ***/var/lib/mysqlbackup/dbbackup. Sh
--------------------------------------------------------------------------------
Done!
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.