You only need to follow the three steps below, and everything is under your control:
Step 1: configure the Backup Directory code on the server:
--------------------------------------------------------------------------------
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!