QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 600|回复: 1

MySQL数据自动备份并且ftp的shell文件

[复制链接]
发表于 2004-1-20 03:51:27 | 显示全部楼层 |阅读模式
这个是我写的第一个shell文件,请大家多多指教

MySQLbackup.sh 是备份整个MySQL数据库的数据
[code:1]#!/bin/bash

############### MySQL Backup & FTP ################
#Power By SBear 2004-01-20 2:10
#E-mail:[email protected]
#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]


DBbackup.sh 是备份单个数据库的数据
[code:1]#!/bin/bash

############### MySQL One DataBase's Backup & FTP ################
#Power By SBear 2004-01-20 2:40
#E-mail:[email protected]
#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]

大家也可以到我的站下载
http://www.1842.net
发表于 2004-1-20 03:53:19 | 显示全部楼层
good job! :-)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-11-15 06:07 , Processed in 0.038708 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表