#! /Bin/bash # Name of the database to be backed up DB_NAME = & quot; xxx & quot; # Name of the database to be backed up DB regularly backs up the database on a daily basis in Linux
1. on the home page, we need to write a script named bakdata. sh. the storage path is/root/bakdata. sh. The content is as follows:
PHP #! /Bin/bash # Name of the database to be backed up DB_NAME = "xxx" # Name of the database to be backed up DB_USER = "xxx" # password of the database to be backed up DB_PASS = "xxx" # MySQL installation Path (based on actual conditions) BIN_DIR = "/usr/local/mysql/bin" # directory of the file to be backed up BACK_DIR = "/var/mysql_bak" # backup format (daily storage) DATE = "'date + % Y % m % d'" $ BIN_DIR/mysqldump -- opt-u $ DB_USER-p $ DB_PASS $ DB_NAME> $ BACK_DIR/$ date. SQL
1234567891011121314 |
#! /Bin/bash # Name of the database to be backed up DB_NAME = "xxx" # Name of the database to be backed up DB_USER = "xxx" # password of the database to be backed up DB_PASS = "xxx" # MySQL installation Path (based on actual conditions) BIN_DIR = "/usr/local/mysql/bin" # directory of the file to be backed up BACK_DIR = "/var/mysql_bak" # backup format (daily storage) DATE = "'date + % Y % m % d'" $ BIN_DIR/mysqldump -- opt-u $ DB_USER-p $ DB_PASS $ DB_NAME> $ BACK_DIR/$ date. SQL |
2. use the crontab command in Linux to regularly execute scripts.
Crontab-e
3. write the following content and save and exit (data is backed up at every day ).
PHP # bakdata 15 00 ***/bin/bash/root/bakdata. sh
12 |
# Bakdata15 00 ***/bin/bash/root/bakdata. sh |