LINUX下通过FTP来备份MYSQL数据

发表于:2007-06-13来源:作者:点击数: 标签:
以下代码介绍了如何通过 Linux 下的FTP来备份Mysql 数据库 的数据。 #!/bin/bash ############### Mysql Backup FTP ################ #1. mkdir /home/mysqlbackup #2. chmod 700 MysqlDatebackup.sh #3. vi /etc/crontab , 30 03 * * * root /home/mysqlba

以下代码介绍了如何通过Linux下的FTP来备份Mysql数据库的数据。

#!/bin/bash

############### Mysql Backup & FTP ################

#1. mkdir /home/mysqlbackup

#2. chmod 700 MysqlDatebackup.sh

#3. vi /etc/crontab , 30 03 * * * root /home/mysqlbackup/MysqlDatebackup.sh

#everyday 03:30 the MysqlDatebackup.sh will work

#System Setup

host=202.100.222.2 #ftp host

UserName=test #ftp user name

Passwd=test #fto user password

function Iint()

{

backup_path=/home/mysqlbackup #set saved backup path

file=$path-mysql-$(date +%Y-%m-%d).tar.gz

backupCWD=/usr/local/mysql/data/$path #set backup file,the mysql path

tar -czf $backup_path/$file $backupCWD

#file tar

cd $backup_path

#file ftp

ftp -i -n <<!

open $host

user $UserName $Passwd

if [ ! [ -d WEB-BACK/$path ]]; then

mkdir MYSQL-BACK/$path

fi

cd MYSQL-BACK/$path

put $file

bye

!

}

/etc/init.d/mysqld stop >/dev/null 2>&1

path=database1 #datebase1

Iint

path=datebase2 #datebase2

Iint

/etc/init.d/mysqld start >/dev/null 2>&1

rm -rf $backup_path/*.tar.gz

echo "ftp back ok!"

(责任编辑:城尘 68476636-8003)



原文转自:http://www.ltesting.net

...