<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>飞扬轻狂&#039;s blog &#187; 数据备份</title>
	<atom:link href="http://blog.fallseir.com/tag/%e6%95%b0%e6%8d%ae%e5%a4%87%e4%bb%bd/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.fallseir.com</link>
	<description>我心飞扬 我意轻狂</description>
	<lastBuildDate>Thu, 06 May 2010 07:13:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/><cloud domain='blog.fallseir.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>使用mysqldump进行单表备份</title>
		<link>http://blog.fallseir.com/2008/10/mysqldump_tables/</link>
		<comments>http://blog.fallseir.com/2008/10/mysqldump_tables/#comments</comments>
		<pubDate>Fri, 10 Oct 2008 09:17:39 +0000</pubDate>
		<dc:creator>飞扬轻狂</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[笔记]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysqldump]]></category>
		<category><![CDATA[X shell]]></category>
		<category><![CDATA[数据备份]]></category>

		<guid isPermaLink="false">http://blog.fallseir.com/?p=99</guid>
		<description><![CDATA[写了一个shell脚本 对数据库中每个表进行备份 这样可以方便的在表中进行筛选 bak_db_table.sh &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; # bak_db_table.sh db db_host db_user db_passwd > log.txt # by fallseir at 20081010 if [ $1 ] # 如果没有参数 then echo database $1; else echo 'backup database tables to gzip files sh bak_db_table.sh db [db_host] [db_user] [db_passwd] '; exit; fi # 参数赋值 [ $1 ] &#038;&#038; db=$1 [ $2 ] [...]]]></description>
			<content:encoded><![CDATA[<p>写了一个shell脚本 对数据库中每个表进行备份 这样可以方便的在表中进行筛选</p>
<p>bak_db_table.sh<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<pre>
# bak_db_table.sh db db_host db_user db_passwd > log.txt
# by fallseir at 20081010

if [ $1 ] # 如果没有参数
then
echo database $1;
else
echo 'backup database tables to gzip files
sh bak_db_table.sh db [db_host] [db_user] [db_passwd]
'; exit;
fi

# 参数赋值
[ $1 ] &#038;&#038; db=$1
[ $2 ] &#038;&#038; dbh=$2
[ $3 ] &#038;&#038; dbu=$3
[ $4 ] &#038;&#038; dbp=$4

# 配置数据库参数
[ $dbh ] &#038;&#038; dbh="-h"$dbh
[ $dbu ] &#038;&#038; dbu="-u"$dbu
[ $dbp ] &#038;&#038; dbp="-p"$dbp

#如果不存在 以db命名的目录 则创建
[ -a $db ] || mkdir $db; echo "mkdir $db"

# 获取数据库中的表列表
echo 'list=(`echo "show tables;"|mysql -h$dbh -u$dbu -p$dbp $db`)'
list=(`echo "show tables;"|mysql $dbh $dbu $dbp $db`)
# 获取表个数
tbcount=$((${#list[@]}-2))
if [ $tbcount= -2 ] # 如果表不存在 或数据库连接失败
then
  echo empty tables in $db or connent failed! ; exit 1;
fi
echo table count: $tbcount

# 对每个表进行备份 并压缩
# 使用gzip -d $file 进行解压
# 使用 mysql $database < $bakfile 进行恢复
for (( i = 1 ; i < ($tbcount+1) ; i ++ ))
do
  table=${list[$i]}
  echo back table $table
  mysqldump $dbh $dbu $dbp $db $table | gzip -c > $db/177.6.db.$db.$table.gz
# $? 前一命令的返回值, 0 为成功 1为失败 但mysqldump没有遵守这个约定
  echo back table $table $?
  sleep 10
done
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.fallseir.com/2008/10/mysqldump_tables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
