这个是我写的第一个shell文件,请大家多多指教
MySQLbackup.sh 是备份整个MySQL数据库的数据
[code:1:c4b67eae16]#!/bin/bash
############### MySQL Backup & FTP ################
#Power By SBear 2004-01-20 2:10
#E-mail:sbear_ji@126.com
#http://www.1842.net
#
http://www.CnLinux.net
#1. mkdir /home/backup
#2. chmod 700 MySQLbackup.sh
#3. vi /etc/crontab , 30 03 * * * root /home/backup/MySQLbackup.sh
#everyday 03:30 the MySQLbackup.sh will work
#System Setup
host=192.168.0.3 #ftp host
UserName=ftp #ftp user name
Passwd=ftp #fto user password
backup_path=/home/backup #set saved backup path
file=mysql-$(date +%Y%m%d).tar.gz
backupCWD=/usr/local/mysql/var #set backup file,the mysql database
#stop mysql database server
/usr/bin/killall mysqld
#/etc/rc.c/init.d/mysqld stop
sleep 5s #stop 5 second
#file tar
tar -czf $backup_path/$file $backupCWD
sleep 10s
#start mysql database server
/usr/local/mysql/bin/mysqld_safe --user=mysql & #set your mysqld path
#/etc/rc.d/init.d/mysqld start
cd $backup_path
sleep 1s
#file ftp
ftp -i -n <<!
open $host
user $UserName $Passwd
put $file
bye
!
sleep 10s
rm -rf $backup_path/$file[/code:1:c4b67eae16]
DBbackup.sh 是备份单个数据库的数据
[code:1:c4b67eae16]#!/bin/bash
############### MySQL One DataBase's Backup & FTP ################
#Power By SBear 2004-01-20 2:40
#E-mail:sbear_ji@126.com
#http://www.1842.net
#
http://www.CnLinux.net
#1. mkdir /home/backup
#2. chmod 700 DBbackup.sh
#3. vi /etc/crontab , 30 03 * * * root /home/backup/DBbackup.sh
#everyday 03:30 the DBbackup.sh will work
#System Setup
#ftp Info
host=192.168.0.3 #ftp host
UserName=ftp #ftp user name
Passwd=ftp #fto user password
#MySQL Info
SQL_host=localhost #MySQL host
SQL_User=root #MySQL UserName
SQL_Passwd=abc #User Password
SQL_db=test #database name
backup_path=/home/backup #set saved backup path
file=$SQL_db-$(date +%Y%m%d).tar.gz
MySQL_path=/usr/local/mysql/bin #set the mysql database bin path
cd $backup_path
#export database
$MySQL_path/mysqldump -h $SQL_host -u$SQL_User -p$SQL_Passwd --databases $SQL_db>$SQL_db.dump
sleep 5s
#file tar
tar -czf $backup_path/$file $SQL_db.dump
sleep 10s
cd $backup_path
sleep 1s
#file ftp
ftp -i -n <<!
open $host
user $UserName $Passwd
put $file
bye
!
sleep 10s
rm -rf $backup_path/$file
rm -rf $backup_path/$SQL_db.dump
[/code:1:c4b67eae16]