1. vi/home/zhangy/database_bak.sh
2.
3. #!/bin/sh
4. # File:/home/zhangy/database_bak.sh
5. # Database Info bakupmysql TANK 2009/11/04
6. Db_user= "Root" #用户名
7. db_pass= "********" # Password
8. Db_name= "MyBlog" # Name of the data to be backed up
9.
# others VARs
Date= ' Date +%y_%m_%d ' # Date to back up
Yesterday= ' date-d yesterday +%y_%m_%d ' # Delete yesterday's backup
13.
Bin_dir= "/usr/local/mysql/bin"
Bck_dir= "/home/zhangy/database_bak" # Backup path
16.
CD $BCK _dir
18.
19. # Delete Previous backup of this database, because my Linux below also have 2G hard disk space, depressed.
If [f $YESTERDAY $db_name ". sql"]
Then.
Rm-f $YESTERDAY $db_name ". sql"
Fi.
24.
25. # Backup
${bin_dir}/mysqldump--opt-u${db_user}-p${db_pass} ${db_name} > ${bck_dir}/${date}${db_name}.sql
vi/home/zhangy/database_bak.sh
#!/bin/sh
# File:/home/zhangy/database_bak.sh
# Database Info bakupmysql TANK 2009/11/04
db_user= "Root" #用户名
Db_pass= "********" # Password
Db_name= "MyBlog" # Name of the data to be backed up
# others VARs
Date= ' Date +%y_%m_%d ' # Date to back up
Yesterday= ' date-d yesterday +%y_%m_%d ' # Delete yesterday's backup
Bin_dir= "/usr/local/mysql/bin"
Bck_dir= "/home/zhangy/database_bak" # Backup path
CD $BCK _dir
# Delete Previous backup of this database, because my Linux also has 2G hard disk space, depressed.
If [-F $YESTERDAY $db_name ". sql"]
Then
Rm-f $YESTERDAY $db_name ". sql"
Fi
# Backup
${bin_dir}/mysqldump--opt-u${db_user}-p${db_pass} ${db_name} > ${bck_dir}/${date}${db_name}.sql
Two, regular execution
put the shell inside the crontab.
# to see if Crond started
[root@blackghost cron]# ps-e|grep crond
21519? 00:00:00 crond
# open crontab
[root@blackg Host cron]# crontab-e
# Add a line inside
* */home/zhangy/database_bak.sh
# Check to see if added
[Root@blackghost cron] # crontab-l
#
# don't EDIT this FILE manually!! Use Crontab-e INSTEAD.
#
#
* * */usr/sbin/run-cron/etc/cron.hourly
* */usr/sbin/run-cron/etc/cron.daily
22 * * 0/usr/sbin/run-cron/etc/cron.weekly
1 * */usr/sbin/run-cron/etc/cron.monthly
* */home/zh angy/www/bb.php
* */sbin/shutdown-h now
* */home/zhangy/database_bak.sh
Then exit