#!/bin/bashpath=/bin:/sbin:/usr/bin:/usr/sbin:/usr/Local/bin:/usr/Local/sbin:~/bin export PATH export LANG=en_us. utf-8Savedir=/Log/database_bak/CD"$savedir" Time="$ (date +"%Y-%m-%d %H:%M:%s")"mysqldump-U [My_user]-p[my_pwd] [db_name] > [db_name]-"$time". sql
Note here that the following-p does not have spaces directly added [MY_PWD]
The sh script is then placed in the/log/sh/directory and given execute permissions, and finally into the Linux timed task Crond, adding the following script:
run-parts databasebak.sh 01 * * * * * * root Run-parts/etc/cron.hourly 4 * * * Root run-parts/ Etc/cron. daily 22 4 * * 0 Root Run-parts/etc/cron. weekly 42 1 * * Root run-parts/etc/cron. monthly 02 5 * * * root sh/log /sh/databasebak.sh
Finally save good after restart Crond,service crond restart can!
Regular backup of MySQL database using mysqldump in Linux