In Linux, use mysqldump to regularly back up MySQL databases:
- #! /Bin/bash
- PATH =/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin :~ /Bin
- Export PATH
- Export LANG = en_US.UTF-8
- Savedir =/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 that [my_pwd] is directly added without spaces after-p below.
Then, place the sh script in the/log/sh/directory and grant the execution permission. Finally, enter the linux scheduled task crond and add the following script:
- # Run-parts daily5Point02Sub-execution databasebak. sh
- 01* *** Root run-parts/etc/cron. hourly
- 02 4* ** Root run-parts/etc/cron. daily
- 22 4**0Root run-parts/etc/cron. weekly
- 42 4 1** Root run-parts/etc/cron. monthly
- 02 5* ** Root sh/log/sh/databasebak. sh
After saving the information, restart crond and service crond restart!