38
32

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

mysqldump で作成したファイルを分割する

Last updated at Posted at 2013-08-09

データベースごとに分離する

reg="/^CREATE DATABASE .*\`[a-zA-Z0-9_]*\`.*/"
csplit -z -f mysqldump_ -k mysqldump-full.dump "$reg" {*}
  • mysqldump00 コメントのみ
  • mysqldump01~ 各種データーベース毎のファイル

ファイルにデータベースの名前を設定する。

for file in $(ls -1 mysqldump_* )
do
# mv
fname=mysqldump
mv -v $file "${fname}_$(grep 'USE `' $file | sed -e 's@.*`\(.*\)`;@\1@ig')" 
# done
done

テーブルごとに分離する。

for fname in $(ls mysqldump_*)
do
# csplit
csplit -z -f ${fname}_ -k ${fname} "/^CREATE TABLE \`[a-zA-Z0-9_]*\`/" {*}
#done
done

ファイルにテーブルの名前を設定する。

2015-05-18-renew
for file in $(ls -1 mysqldump_*_* ); 
do 
table_name=$(grep "CREATE TABLE" $file | cut -d '`' -f 2); 
mv ${file} ${table_name}.sql; 
done;
for file in $(ls -1 mysqldump_*_* )
do 
# mv
fname=$( echo $file | sed -e "s@\(mysqldump_.*\)_[^_]*@\1@ig" );
mv -v $file "${fname}_$(grep 'CREATE TABLE `' $file | sed -e 's@.*`\(.*\)`.*@\1@ig')" ; 
# done
done

CREATE と INSERT を分離

for file in $(ls mysqldump_*_*)
do
# csplit
csplit -z -f ${file}_ -k ${file} "/^LOCK TABLES/" {2}
#done
done
38
32
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
38
32

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?