wyrm 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 85b0989b28233c55407b8c0277970f7b733235f1
4
- data.tar.gz: d12c0b1ccf156bbc808cf302b2c2ad0ded122b52
3
+ metadata.gz: da207f92151b080d31039a364c1a2c50022f01ff
4
+ data.tar.gz: ddf38f48b42597ed08671cb67fadd8457e425e07
5
5
  SHA512:
6
- metadata.gz: 301e296b3108284415d4041773ecb45f92907128fc548886c79b63d7db14683d4fdf79ad4515cee5bf6122b6e5a0a66528e716e29a779c56b1e3a72f01158bf2
7
- data.tar.gz: 14084646f239d950c8def8056fc7cc9ea54a458dccbd04384ebeee68bf6103f4f881f84ef1aa44fd56cd24839aeb73e31e8bd617091a3a0b88602fff7bfb898d
6
+ metadata.gz: 03e699a00d14fa7baacc286b886cf35074766b7b6b3b8e6e10fde08779ded7fda4930f9666bad95274bf773f8fe33f1916f3836414e98c188c81963b3a01459c
7
+ data.tar.gz: 0052a0b096e62662223f9e4a9da2cfd79e2908f033f83a7a9201463aac3ec9f56407299b68e461b9b850f39ea8c3da5e53c48ad7510561d680b601a38ce739ca
@@ -1,3 +1,7 @@
1
+ == 0.4.1
2
+ * Improve docs and examples
3
+ * make pbzip2 somewhat configurable.
4
+
1
5
  == 0.4.0
2
6
  * Update for released ruby-2.3 Queue#close
3
7
  * use &. instead of andand
@@ -9,5 +13,6 @@
9
13
 
10
14
  == 0.3.3
11
15
  * minor fix when src/dst directory not found
16
+
12
17
  == 0.3.2
13
18
  * update for >=sequel-4.10.0 internal syntax (Dataset#clause_sql removed)
data/README.md CHANGED
@@ -4,15 +4,15 @@
4
4
  [![Build Status](https://travis-ci.org/djellemah/wyrm.png?branch=master)](https://travis-ci.org/djellemah/wyrm)
5
5
  -->
6
6
 
7
- Transfer a database from one rdbms to another (eg mysql to postgres). Either via
8
- a set of files, or direct from one db server to another.
7
+ Transfer a database (or single tables) from one rdbms to another (eg mysql to
8
+ postgres). Either via a set of files, or direct from one db server to another.
9
9
 
10
10
  Has been used to dump > 100M dbs, and one 850G db.
11
11
  Should theoretically work for any rdbms supported by [Sequel](http://sequel.jeremyevans.net/).
12
12
 
13
- Dumps are compressed with bz2, using pbzip2. Fast *and* small :-D For example:
14
- mysqldump | bzip2 for a certain 850G db comes to 127G. With wyrm it
15
- comes to 134G.
13
+ Dumps are (usually) compressed with bz2, using pbzip2. Fast *and* small :-D
14
+ For example: mysqldump | bzip2 for a certain 850G db comes to 127G. With wyrm
15
+ it comes to 134G.
16
16
 
17
17
  Transfers tables and views only. Does not attempt to transfer
18
18
  stored procs, permissions, triggers etc.
@@ -26,13 +26,14 @@ Will use result set streaming if available.
26
26
  Wyrm because:
27
27
 
28
28
  - I like dragons
29
- - I can have a Wyrm::Hole to transfer data ;-)
29
+ - I can have a Wyrm::Hole to transfer data O-;-)
30
30
 
31
31
  ## Dependencies
32
32
 
33
33
  You must have a working
34
34
  [pbzip2](http://compression.ca/pbzip2/ "Will use all your cores")
35
- on your path.
35
+ on your path. If you really have to use something else,
36
+ reassign ```Wyrm::STREAM_DCMP``` and ```Wyrm::STREAM_COMP``` .
36
37
 
37
38
  ## Installation
38
39
 
@@ -75,25 +76,49 @@ On the destination host
75
76
 
76
77
  $ wyrm /tmp/lots_fs_space postgres://localhost/betta_dee_bee
77
78
 
79
+ #### View contents of a dump file as yaml
80
+
81
+ $ wyrm-view /tmp/lots_fs_space/some_table.dbp.bz2
82
+
78
83
  ### irb / pry
79
84
 
80
85
  For restoring. dump will be similar.
81
86
 
82
87
  ``` ruby
83
88
  require 'wyrm/restore_schema'
89
+
84
90
  rs = Restore.new 'postgres://postgres@localhost/your_db', '/mnt/disk/wyrm'
85
91
  rs.call
86
92
  ```
87
93
 
88
- Or for the lower-level stuff
94
+ Directly transferring one table:
89
95
 
90
96
  ``` ruby
91
97
  require 'sequel'
98
+ require 'wyrm/hole'
99
+
100
+ hole = Wyrm::Hole.new 'mysql2://localhost/beeg_data_bays', 'postgres://localhost/betta_dee_bee'
101
+
102
+ # transfer schema (no indexes), using Sequel::SchemaDumper extension, see
103
+ # Sequel::SchemaDumper#dump_schema_migration for options
104
+ table_schema = hole.src_db.dump_table_schema :the_stuff_you_want
105
+ Sequel.migration{ change{ eval table_schema } }.apply hole.dst_db, :up
106
+
107
+ hole.transfer_table :the_stuff_you_want
108
+
109
+ # it's just Sequel...
110
+ hold.dst_db[:the_stuff_you_want].where( some_thing: /a pattern/ ).limit(10).all
111
+ ```
112
+
113
+ Get to the dumped rows:
114
+
115
+ ``` ruby
116
+ require 'sequel' # for some demarshaling
92
117
  require 'wyrm/pump'
93
118
 
94
- db = Sequel.connect 'postgres://postgres@localhost/other_db'
95
- dbp = Wyrm::Pump.new db, :things
96
- dbp.io = IO.popen 'pbzip2 -d -c /mnt/disk/wyrm/things.dbp.bz2'
119
+ dbp = Wyrm::Pump.new io: IO.popen('pbzip2 -d -c /mnt/disk/wyrm/things.dbp.bz2')
120
+ # each_row also returns an Enumerator if no block is given, similar to much
121
+ # ruby core stuff. Although it's not rewindable.
97
122
  dbp.each_row do |row|
98
123
  puts row.inspect
99
124
  end
data/bin/wyrm CHANGED
@@ -3,7 +3,12 @@
3
3
  require 'uri'
4
4
 
5
5
  if ARGV.size != 2
6
+ require 'wyrm/version'
7
+
6
8
  puts <<EOF
9
+
10
+ wyrm-#{Wyrm::VERSION}
11
+
7
12
  Usage: #{$0} src_db|dirname dst_db|dirname
8
13
 
9
14
  dirname contains a set of wyrm files, or will soon.
@@ -12,6 +17,7 @@ sample db strings:
12
17
  postgres://localhost/lotsa_datsa
13
18
  mysql://root:pwned@localhost/lotsa_datsa
14
19
  mysql2://root:pwned@localhost/lotsa_fastsa_datsa
20
+
15
21
  EOF
16
22
  exit(1)
17
23
  end
@@ -25,7 +31,7 @@ end
25
31
  src, dst = ARGV.map{|arg| URI.parse(arg).extend(FsPath)}
26
32
 
27
33
  require 'wyrm/cli'
28
- Wyrm.sanity_check_pbzip2
34
+ Wyrm.sanity_check_dcmp
29
35
 
30
36
  include Wyrm
31
37
 
@@ -4,16 +4,17 @@ if ARGV.empty? || ARGV.first =~ /^-+(\?|h(elp)?)$/
4
4
  puts <<EOF
5
5
  Usage: #{$0} dbp_file.dbp[.bz2]
6
6
 
7
- Display contents of dbp file, optionally compressed with bz2.
7
+ Display contents of dbp file in yaml, optionally compressed with bz2.
8
8
  EOF
9
9
  exit(0)
10
10
  end
11
11
 
12
12
  require 'wyrm/cli'
13
- Wyrm.sanity_check_pbzip2
13
+ Wyrm.sanity_check_dcmp
14
14
 
15
15
  require 'pathname'
16
16
  require 'yaml'
17
+ require 'sequel' # needed for demarshalling some types
17
18
 
18
19
  out_block = lambda do |io|
19
20
  record_count = 1
@@ -27,7 +28,7 @@ end
27
28
  ARGV.map{|a| Pathname(a)}.each do |path|
28
29
  puts "# source: #{path}"
29
30
  if path.extname == '.bz2'
30
- IO.popen "pbzip2 -d -c #{path}", &out_block
31
+ IO.popen "#{Wyrm::STREAM_DCMP} #{path}", &out_block
31
32
  else
32
33
  path.open &out_block
33
34
  end
@@ -1,8 +1,11 @@
1
+ require 'wyrm/module'
2
+
1
3
  module Wyrm
2
- def self.sanity_check_pbzip2
3
- rv = `which pbzip2`
4
+ def self.sanity_check_dcmp
5
+ bzip_cmd = Wyrm::STREAM_DCMP.split(' ').first
6
+ rv = `which #{bzip_cmd}`
4
7
  unless $?.exitstatus == 0
5
- puts "\npbzip2 not installed or not in PATH"
8
+ puts "\n#{cmd} not installed or not in PATH"
6
9
  exit(1)
7
10
  end
8
11
  end
@@ -52,7 +52,7 @@ class Wyrm::Dump
52
52
  def write_through_bz2( pathname )
53
53
  fio = pathname.open('w')
54
54
  # open subprocess in read-write mode
55
- zio = IO.popen( "pbzip2 -z", 'r+' )
55
+ zio = IO.popen( STREAM_COMP, 'r+' )
56
56
  copier = Thread.new do
57
57
  begin
58
58
  IO.copy_stream zio, fio
@@ -1 +1,4 @@
1
- module Wyrm end
1
+ module Wyrm
2
+ STREAM_COMP = 'pbzip2 -z'
3
+ STREAM_DCMP = 'pbzip2 -d -c'
4
+ end
@@ -86,7 +86,7 @@ class Wyrm::Restore
86
86
  raise "Don't know what to do with #{table_name.inspect}"
87
87
  end
88
88
 
89
- IO.popen "pbzip2 -d -c #{table_file}", &block
89
+ IO.popen "#{STREAM_DCMP} #{table_file}", &block
90
90
  end
91
91
 
92
92
  def table_files
@@ -1,3 +1,3 @@
1
1
  module Wyrm
2
- VERSION = '0.4.0'
2
+ VERSION = '0.4.1'
3
3
  end
@@ -8,6 +8,6 @@ include Wyrm
8
8
 
9
9
  describe Wyrm do
10
10
  it 'has the right constants' do
11
- Wyrm.constants.sort.should == [:Dump, :Hole, :Logger, :Pump, :PumpMaker, :Restore, :SchemaTools, :VERSION].sort
11
+ Wyrm.constants.sort.should == [:Dump, :Hole, :Logger, :Pump, :PumpMaker, :Restore, :SchemaTools, :VERSION, :STREAM_COMP, :STREAM_DCMP].sort
12
12
  end
13
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wyrm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Anderson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-17 00:00:00.000000000 Z
11
+ date: 2016-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel