Dump-cut » История » Версия 4
Андрей Волков, 2015-04-13 17:16
1 | 1 | Андрей Волков | h1. Dump-cut |
---|---|---|---|
2 | |||
3 | Перобразование дампа в схему: |
||
4 | |||
5 | <pre> |
||
6 | 2 | Андрей Волков | nice -n19 bzcat db.backup-2011-07-15.sql.bz2 \ |
7 | |nice -n19 awk ' |
||
8 | BEGIN{ |
||
9 | sc=1; |
||
10 | sd=0; |
||
11 | wr=1 |
||
12 | } |
||
13 | { |
||
14 | if ((sc==0)&&(sd==1)&&($0 ~ /^COPY /)) { |
||
15 | wr=0; |
||
16 | printf ("\n%s",$2) >"/dev/stderr" |
||
17 | } |
||
18 | if ((sc==1)&&($0 ~ /^-- Data for Name: /)) { |
||
19 | sd=1; |
||
20 | sc=0; |
||
21 | }; |
||
22 | if (wr==1) print $0; |
||
23 | if ((wr==0)&&($0 ~ /^\\\.$/)) { |
||
24 | wr=1; |
||
25 | sd=0; |
||
26 | sc=1 |
||
27 | }; |
||
28 | if (NR%1000==0) printf "." > "/dev/stderr" |
||
29 | } |
||
30 | END{ |
||
31 | printf "\nDONE\n" > "/dev/stderr" |
||
32 | }' \ |
||
33 | |nice -n19 bzip2 -9 > db-cut.backup-2011-07-15-schema.sql.bz2 |
||
34 | 1 | Андрей Волков | </pre> |
35 | 3 | Андрей Волков | |
36 | 4 | Андрей Волков | h2. Выкусывание таблиц из дампа |
37 | 3 | Андрей Волков | |
38 | <pre> |
||
39 | pv -petraW blizko.backup-2014-01-30.sql.bz2 | nice -n19 bunzip2 | nice -n19 sed -e -n '/^COPY products (.*) FROM stdin;$/,/^\\.$/p;/^\\.$/q' | nice -n19 gzip -3 > products-2014-01-30_00-51.sql.gz |
||
40 | </pre> |