dbsync 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +7 -1
- data/README.md +92 -0
- data/dbsync.gemspec +2 -4
- data/lib/dbsync.rb +24 -3
- data/lib/dbsync/sync.rb +55 -26
- data/lib/dbsync/version.rb +1 -1
- data/lib/tasks/dbsync.rake +29 -10
- data/spec/local/.gitkeep +0 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/sync_spec.rb +39 -0
- metadata +29 -45
- data/README.markdown +0 -72
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4d8a3ddf36966a8c9aec5c43f62b383f6a01dac4
|
4
|
+
data.tar.gz: 04dea7b42bca9c6492be1153947ca10975bca739
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2a0119d2c7b4f67f5e7ec95ebcf29000a6692a7f8c0fd1523703da10efcb71b827c4d5debc347858a086e52a1261b5d5bdb372aae27aadd59a8bee9c9d9de7dc
|
7
|
+
data.tar.gz: 7481b11c17c29b718c6b4f7addc1ae1345e7e468a012a10b23c0ff693e8a53b815f788fef3eb83312bb93e684b5557ae8ccf86fce23215e6624ddb53f5e974d7
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
-
## 0.
|
1
|
+
## 0.3.0 (unreleased)
|
2
|
+
* Removed all Rails dependencies. Rails is now optional.
|
3
|
+
* Removed scp usage. Everything uses rsync now.
|
4
|
+
* Added Dbsync.file_config and Dbsync.db_config to manually set configuration.
|
5
|
+
* [DEPRECATED] local_dir, remote_dir, remote_host, filename options. Instead, combine them into just `local` and `remote` configurations (see README for more).
|
6
|
+
|
7
|
+
## 0.2.0 (2014-02-13)
|
2
8
|
* Internal refactoring.
|
3
9
|
* Updated gem dependencies.
|
data/README.md
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
# dbsync
|
2
|
+
|
3
|
+
A set of rake tasks to help you sync your production data with your local database for development. **Currently only supports MySQL.**
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Add to your gemfile for the groups that will need it:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
group :development, :staging do
|
11
|
+
gem 'dbsync'
|
12
|
+
end
|
13
|
+
```
|
14
|
+
|
15
|
+
Or just install it as a gem:
|
16
|
+
|
17
|
+
```
|
18
|
+
gem install dbsync
|
19
|
+
```
|
20
|
+
|
21
|
+
### For Rails
|
22
|
+
|
23
|
+
Add the following to your `config/environments/development.rb` file. Depending on your staging setup, it may also be useful to you to add some `dbsync` config to your `staging.rb` environment file. **`dbsync` will not run in production.**
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
config.dbsync = {
|
27
|
+
:remote => '66.123.4.567:~/dbsync/mydb.dump',
|
28
|
+
:local => '../dbsync/mydb.dump'
|
29
|
+
}
|
30
|
+
```
|
31
|
+
|
32
|
+
Dbsync will automatically use your Rails environment's database configuration.
|
33
|
+
|
34
|
+
### For non-Rails
|
35
|
+
|
36
|
+
You can also specify the dbsync configuration with `Dbsync.file_config` and `Dbsync.db_config`:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
Dbsync.file_config = {
|
40
|
+
:local => "../dbsync/dbsync.dump",
|
41
|
+
:remote => "dbuser@100.0.100.100:~dbuser/dbsync.dump"
|
42
|
+
}
|
43
|
+
|
44
|
+
Dbsync.db_config = {
|
45
|
+
:adapter => "mysql2", # Not actually used yet
|
46
|
+
:database => "yourdb",
|
47
|
+
:username => "youruser",
|
48
|
+
:password => "yourcoolpassword"
|
49
|
+
}
|
50
|
+
```
|
51
|
+
|
52
|
+
### The server
|
53
|
+
|
54
|
+
Now just make sure you have something on the remote server updating that dumpfile. I recommend a cronjob:
|
55
|
+
|
56
|
+
```
|
57
|
+
0 */12 * * * /usr/bin/mysqldump yourapp_production > /home/dbsync/yourapp_production_data.dump
|
58
|
+
```
|
59
|
+
|
60
|
+
If you are using the SSH form of rsync, you will need proper SSH access into the remote server.
|
61
|
+
|
62
|
+
### Rake
|
63
|
+
|
64
|
+
Run `rake -T dbsync` for all of the available tasks. The tasks are named after `git` commands mostly, so they should be pretty straight-forward for those who use `git`:
|
65
|
+
|
66
|
+
```
|
67
|
+
rake dbsync # Alias for dbsync:pull
|
68
|
+
rake dbsync:clone # Copy the remote dump file, reset the local database, and load in the dump file
|
69
|
+
rake dbsync:clone_dump # Copy the remote dump file to a local destination
|
70
|
+
rake dbsync:config # Show the dbsync configuration
|
71
|
+
rake dbsync:fetch # Update the local dump file from the remote source
|
72
|
+
rake dbsync:merge # Update the local database with the local dump file
|
73
|
+
rake dbsync:pull # Update the local dump file, and merge it into the local database
|
74
|
+
rake dbsync:reset # Drop and Create the database, then load the dump file
|
75
|
+
```
|
76
|
+
|
77
|
+
|
78
|
+
### Caveats
|
79
|
+
|
80
|
+
* The `merge` process doesn't clear out your database first. This is to improve performance. Therefore, any tables which you removed on the remote host won't be removed locally. To do a complete reset of your database, run `rake dbsync:reset`. This resets your database (`db:drop` and `db:create`), and then merges in the local file.
|
81
|
+
* Rails: the test database isn't automatically updated when syncing to your development database. After a `dbsync` and before you run tests, you'll need to run `rake db:test:prepare` to setup your database.
|
82
|
+
* Rails: your schema.rb isn't involed in `dbsync` at all. You need to manage it yourself.
|
83
|
+
|
84
|
+
|
85
|
+
### TODO
|
86
|
+
|
87
|
+
- Support postgres, sqlite, and anything else.
|
88
|
+
|
89
|
+
|
90
|
+
### Feedback/Support
|
91
|
+
|
92
|
+
Open an issue or send a pull request.
|
data/dbsync.gemspec
CHANGED
@@ -17,9 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
18
|
s.require_paths = ["lib", "lib/tasks"]
|
19
19
|
|
20
|
-
s.add_dependency "
|
21
|
-
s.add_dependency "railties", [">= 3.2.8", "< 5"]
|
22
|
-
s.add_dependency "cocaine", "~> 0.5.3"
|
20
|
+
s.add_dependency "cocaine", [">= 0.5.0", "< 0.6"]
|
23
21
|
|
24
|
-
s.add_development_dependency "rspec"
|
22
|
+
s.add_development_dependency "rspec", '~> 0'
|
25
23
|
end
|
data/lib/dbsync.rb
CHANGED
@@ -2,9 +2,30 @@ require "dbsync/version"
|
|
2
2
|
require 'dbsync/sync'
|
3
3
|
|
4
4
|
module Dbsync
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
if defined?(Rails)
|
6
|
+
class Railtie < Rails::Railtie
|
7
|
+
rake_tasks do
|
8
|
+
Dir[File.join(File.dirname(__FILE__),'tasks/*.rake')].each { |f| load f }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def file_config
|
16
|
+
@file_config
|
17
|
+
end
|
18
|
+
|
19
|
+
def file_config=(config)
|
20
|
+
@file_config = config
|
21
|
+
end
|
22
|
+
|
23
|
+
def db_config
|
24
|
+
@db_config
|
25
|
+
end
|
26
|
+
|
27
|
+
def db_config=(config)
|
28
|
+
@db_config = config
|
8
29
|
end
|
9
30
|
end
|
10
31
|
end
|
data/lib/dbsync/sync.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'cocaine'
|
2
|
+
require 'fileutils'
|
2
3
|
|
3
4
|
module Dbsync
|
4
5
|
class Sync
|
@@ -10,46 +11,68 @@ module Dbsync
|
|
10
11
|
|
11
12
|
|
12
13
|
def initialize(ssh_config, db_config, options={})
|
13
|
-
ssh_config = ssh_config
|
14
|
-
db_config = db_config
|
14
|
+
ssh_config = symbolize_keys(ssh_config)
|
15
|
+
db_config = symbolize_keys(db_config)
|
15
16
|
|
16
17
|
@verbose = !!options[:verbose]
|
17
18
|
|
18
|
-
@remote_host = ssh_config[:remote_host] || raise_missing("remote_host")
|
19
|
-
@remote_dir = ssh_config[:remote_dir] || raise_missing("remote_dir")
|
20
|
-
@local_dir = ssh_config[:local_dir] || raise_missing("local_dir")
|
21
|
-
@filename = ssh_config[:filename] || raise_missing("filename")
|
22
|
-
|
23
19
|
@db_username = db_config[:username]
|
24
20
|
@db_password = db_config[:password]
|
25
21
|
@db_host = db_config[:host]
|
26
22
|
@db_database = db_config[:database]
|
27
23
|
|
28
|
-
@
|
29
|
-
@
|
24
|
+
@remote = ssh_config[:remote]
|
25
|
+
@local = File.expand_path(ssh_config[:local]) if ssh_config[:local]
|
26
|
+
|
27
|
+
if !@remote
|
28
|
+
$stdout.puts "DEPRECATED: The remote_host, remote_dir, and filename " \
|
29
|
+
"options will be removed. " \
|
30
|
+
"Instead, combine remote_host, remote_dir, and filename into a " \
|
31
|
+
"single 'remote' configuration. Example: " \
|
32
|
+
"'{ remote: \"dbuser@100.0.1.100:~/dbuser/yourdb.dump\" }'"
|
33
|
+
|
34
|
+
remote_host = ssh_config[:remote_host]
|
35
|
+
remote_dir = ssh_config[:remote_dir]
|
36
|
+
filename = ssh_config[:filename]
|
37
|
+
@remote = "#{remote_host}:#{File.join(remote_dir, filename)}"
|
38
|
+
end
|
39
|
+
|
40
|
+
if !@local
|
41
|
+
$stdout.puts "DEPRECATED: The local_dir and filename " \
|
42
|
+
"options will be removed. " \
|
43
|
+
"Instead, combine local_dir and filename into a " \
|
44
|
+
"single 'local' configuration. Example: " \
|
45
|
+
"'{ local: \"../dbsync/yourdb.dump\" }'"
|
46
|
+
|
47
|
+
local_dir = ssh_config[:local_dir]
|
48
|
+
filename = ssh_config[:filename]
|
49
|
+
@local = File.expand_path(File.join(local_dir, filename))
|
50
|
+
end
|
30
51
|
end
|
31
52
|
|
32
53
|
|
33
54
|
# Update the local dump file from the remote source (using rsync).
|
34
55
|
def fetch
|
35
|
-
notify "Updating '#{@
|
56
|
+
notify "Updating '#{@local}' from '#{@remote}' via rsync..."
|
57
|
+
|
58
|
+
FileUtils.mkdir_p(File.dirname(@local))
|
36
59
|
|
37
60
|
line = Cocaine::CommandLine.new('rsync', '-v :remote :local')
|
38
61
|
line.run({
|
39
|
-
:remote => @
|
40
|
-
:local => @
|
62
|
+
:remote => @remote,
|
63
|
+
:local => @local
|
41
64
|
})
|
42
65
|
end
|
43
66
|
|
44
67
|
|
45
68
|
# Update the local database with the local dump file.
|
46
69
|
def merge
|
47
|
-
notify "Dumping data from '#{@
|
70
|
+
notify "Dumping data from '#{@local}' into '#{@db_database}'..."
|
48
71
|
|
49
72
|
options = ""
|
50
|
-
options += "-u :username " if @db_username
|
51
|
-
options += "-p:password " if @db_password
|
52
|
-
options += "-h :host " if @db_host
|
73
|
+
options += "-u :username " if @db_username
|
74
|
+
options += "-p:password " if @db_password
|
75
|
+
options += "-h :host " if @db_host
|
53
76
|
|
54
77
|
line = Cocaine::CommandLine.new('mysql', "#{options} :database < :local")
|
55
78
|
line.run({
|
@@ -57,7 +80,7 @@ module Dbsync
|
|
57
80
|
:password => @db_password,
|
58
81
|
:host => @db_host,
|
59
82
|
:database => @db_database,
|
60
|
-
:local => @
|
83
|
+
:local => @local
|
61
84
|
})
|
62
85
|
end
|
63
86
|
|
@@ -70,21 +93,27 @@ module Dbsync
|
|
70
93
|
|
71
94
|
|
72
95
|
# Copy the remote dump file to a local destination.
|
73
|
-
#
|
74
|
-
#
|
96
|
+
# Instead of requiring two different tools (rsync and scp) for this
|
97
|
+
# library, instead we'll just remove the local file if it exists
|
98
|
+
# then run rsync, which is essentially a full copy.
|
75
99
|
def clone_dump
|
76
|
-
notify "Copying '#{@
|
77
|
-
|
78
|
-
|
79
|
-
line.run({
|
80
|
-
:remote => @remote_file,
|
81
|
-
:local_dir => @local_dir
|
82
|
-
})
|
100
|
+
notify "Copying '#{@remote}' into '#{@local}' via rsync..."
|
101
|
+
FileUtils.rm_f(@local)
|
102
|
+
fetch
|
83
103
|
end
|
84
104
|
|
85
105
|
|
86
106
|
private
|
87
107
|
|
108
|
+
def symbolize_keys(hash)
|
109
|
+
return hash unless hash.keys.any? { |k| k.is_a?(String) }
|
110
|
+
|
111
|
+
result = {}
|
112
|
+
hash.each_key { |k| result[k.to_sym] = hash[k] }
|
113
|
+
result
|
114
|
+
end
|
115
|
+
|
116
|
+
|
88
117
|
def raise_missing(config="")
|
89
118
|
raise "Missing Configuration: '#{config}'. " \
|
90
119
|
"See README for required config."
|
data/lib/dbsync/version.rb
CHANGED
data/lib/tasks/dbsync.rake
CHANGED
@@ -5,20 +5,23 @@ task :dbsync do
|
|
5
5
|
Rake::Task['dbsync:pull'].invoke
|
6
6
|
end
|
7
7
|
|
8
|
+
if !defined?(Rails)
|
9
|
+
# Dummy task
|
10
|
+
task :environment
|
11
|
+
end
|
12
|
+
|
8
13
|
namespace :dbsync do
|
9
14
|
task :setup => :environment do
|
10
|
-
|
15
|
+
if defined?(Rails)
|
16
|
+
Dbsync::Sync.notify "Rails Environment: #{Rails.env}"
|
11
17
|
|
12
|
-
|
13
|
-
|
14
|
-
|
18
|
+
if Rails.env == 'production'
|
19
|
+
raise "These tasks are destructive and shouldn't " \
|
20
|
+
"be used in the production environment."
|
21
|
+
end
|
15
22
|
end
|
16
23
|
|
17
|
-
@dbsync = Dbsync::Sync.new(
|
18
|
-
Rails.application.config.dbsync,
|
19
|
-
ActiveRecord::Base.configurations[Rails.env],
|
20
|
-
verbose: true
|
21
|
-
)
|
24
|
+
@dbsync = Dbsync::Sync.new(file_config, db_config, verbose: true)
|
22
25
|
end
|
23
26
|
|
24
27
|
|
@@ -26,7 +29,7 @@ namespace :dbsync do
|
|
26
29
|
task :config => :setup do
|
27
30
|
# We don't use Sync.notify here because we don't want or need
|
28
31
|
# the extra output that comes with it.
|
29
|
-
$stdout.puts
|
32
|
+
$stdout.puts file_config.to_yaml
|
30
33
|
end
|
31
34
|
|
32
35
|
|
@@ -69,3 +72,19 @@ namespace :dbsync do
|
|
69
72
|
@dbsync.merge
|
70
73
|
end
|
71
74
|
end
|
75
|
+
|
76
|
+
|
77
|
+
# If Dbsync.config was explicitly set, use it.
|
78
|
+
# If Rails is defined, use the dbsync configuration there.
|
79
|
+
# Otherwise, raise an error.
|
80
|
+
def db_config
|
81
|
+
return Dbsync.db_config if Dbsync.db_config
|
82
|
+
return ActiveRecord::Base.configurations[Rails.env] if defined?(Rails)
|
83
|
+
raise "No database configuration found."
|
84
|
+
end
|
85
|
+
|
86
|
+
def file_config
|
87
|
+
return Dbsync.file_config if Dbsync.file_config
|
88
|
+
return Rails.application.config.dbsync if defined?(Rails)
|
89
|
+
raise "No remote configuration found."
|
90
|
+
end
|
data/spec/local/.gitkeep
ADDED
File without changes
|
data/spec/spec_helper.rb
CHANGED
data/spec/sync_spec.rb
CHANGED
@@ -1,10 +1,23 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Dbsync::Sync do
|
4
|
+
let(:local_path) { File.expand_path("../local/dbsync.dump", __FILE__) }
|
5
|
+
let(:remote_path) { File.expand_path("../remote/dbsync.dump", __FILE__) }
|
6
|
+
|
4
7
|
let(:ssh_config) do
|
8
|
+
{
|
9
|
+
:local => File.expand_path("../local/dbsync.dump", __FILE__),
|
10
|
+
:remote => File.expand_path("../remote/dbsync.dump", __FILE__)
|
11
|
+
}
|
5
12
|
end
|
6
13
|
|
7
14
|
let(:db_config) do
|
15
|
+
{
|
16
|
+
:adapter => "mysql2",
|
17
|
+
:database => "cool_db",
|
18
|
+
:username => "root",
|
19
|
+
:password => nil
|
20
|
+
}
|
8
21
|
end
|
9
22
|
|
10
23
|
|
@@ -12,12 +25,38 @@ describe Dbsync::Sync do
|
|
12
25
|
end
|
13
26
|
|
14
27
|
describe '#fetch' do
|
28
|
+
it "creates the directory if it's missing" do
|
29
|
+
ssh_config[:local] = File.expand_path("../local_missing/dbsync.dump", __FILE__)
|
30
|
+
sync = Dbsync::Sync.new(ssh_config, db_config)
|
31
|
+
|
32
|
+
sync.fetch
|
33
|
+
|
34
|
+
File.directory?(File.expand_path("../local_missing", __FILE__)).should be_true
|
35
|
+
FileUtils.rm_rf(File.expand_path("../local_missing", __FILE__))
|
36
|
+
end
|
37
|
+
|
38
|
+
it "copies the remote file the the local file" do
|
39
|
+
sync = Dbsync::Sync.new(ssh_config, db_config)
|
40
|
+
sync.fetch
|
41
|
+
|
42
|
+
File.read(local_path).should eq File.read(remote_path)
|
43
|
+
end
|
15
44
|
end
|
16
45
|
|
17
46
|
describe '#merge' do
|
18
47
|
end
|
19
48
|
|
20
49
|
describe '#clone_dump' do
|
50
|
+
it "removes the local file and rsyncs a fresh one" do
|
51
|
+
# Put a dummy local file in place to make sure it gets removed
|
52
|
+
File.open(local_path, "w") { |f| f.write "Hello." }
|
53
|
+
File.read(local_path).should eq "Hello."
|
54
|
+
|
55
|
+
sync = Dbsync::Sync.new(ssh_config, db_config)
|
56
|
+
sync.clone_dump
|
57
|
+
|
58
|
+
File.read(local_path).should eq File.read(remote_path)
|
59
|
+
end
|
21
60
|
end
|
22
61
|
|
23
62
|
describe '#pull' do
|
metadata
CHANGED
@@ -1,66 +1,49 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dbsync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Bryan Ricker
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
11
|
+
date: 2014-04-15 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement:
|
17
|
-
none: false
|
14
|
+
name: cocaine
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
22
|
-
- - <
|
19
|
+
version: 0.5.0
|
20
|
+
- - "<"
|
23
21
|
- !ruby/object:Gem::Version
|
24
|
-
version: '
|
22
|
+
version: '0.6'
|
25
23
|
type: :runtime
|
26
24
|
prerelease: false
|
27
|
-
version_requirements:
|
28
|
-
- !ruby/object:Gem::Dependency
|
29
|
-
name: railties
|
30
|
-
requirement: &70160586945980 !ruby/object:Gem::Requirement
|
31
|
-
none: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
32
26
|
requirements:
|
33
|
-
- -
|
27
|
+
- - ">="
|
34
28
|
- !ruby/object:Gem::Version
|
35
|
-
version:
|
36
|
-
- - <
|
29
|
+
version: 0.5.0
|
30
|
+
- - "<"
|
37
31
|
- !ruby/object:Gem::Version
|
38
|
-
version: '
|
39
|
-
type: :runtime
|
40
|
-
prerelease: false
|
41
|
-
version_requirements: *70160586945980
|
42
|
-
- !ruby/object:Gem::Dependency
|
43
|
-
name: cocaine
|
44
|
-
requirement: &70160586961540 !ruby/object:Gem::Requirement
|
45
|
-
none: false
|
46
|
-
requirements:
|
47
|
-
- - ~>
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version: 0.5.3
|
50
|
-
type: :runtime
|
51
|
-
prerelease: false
|
52
|
-
version_requirements: *70160586961540
|
32
|
+
version: '0.6'
|
53
33
|
- !ruby/object:Gem::Dependency
|
54
34
|
name: rspec
|
55
|
-
requirement:
|
56
|
-
none: false
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
57
36
|
requirements:
|
58
|
-
- -
|
37
|
+
- - "~>"
|
59
38
|
- !ruby/object:Gem::Version
|
60
39
|
version: '0'
|
61
40
|
type: :development
|
62
41
|
prerelease: false
|
63
|
-
version_requirements:
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
64
47
|
description: A set of rake tasks to help you sync your remote production data with
|
65
48
|
your local database for development.
|
66
49
|
email:
|
@@ -69,45 +52,46 @@ executables: []
|
|
69
52
|
extensions: []
|
70
53
|
extra_rdoc_files: []
|
71
54
|
files:
|
72
|
-
- .gitignore
|
55
|
+
- ".gitignore"
|
73
56
|
- CHANGELOG.md
|
74
57
|
- Gemfile
|
75
58
|
- MIT-LICENSE
|
76
|
-
- README.
|
59
|
+
- README.md
|
77
60
|
- Rakefile
|
78
61
|
- dbsync.gemspec
|
79
62
|
- lib/dbsync.rb
|
80
63
|
- lib/dbsync/sync.rb
|
81
64
|
- lib/dbsync/version.rb
|
82
65
|
- lib/tasks/dbsync.rake
|
66
|
+
- spec/local/.gitkeep
|
83
67
|
- spec/spec_helper.rb
|
84
68
|
- spec/sync_spec.rb
|
85
69
|
homepage: https://github.com/bricker/dbsync
|
86
70
|
licenses:
|
87
71
|
- MIT
|
72
|
+
metadata: {}
|
88
73
|
post_install_message:
|
89
74
|
rdoc_options: []
|
90
75
|
require_paths:
|
91
76
|
- lib
|
92
77
|
- lib/tasks
|
93
78
|
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
-
none: false
|
95
79
|
requirements:
|
96
|
-
- -
|
80
|
+
- - ">="
|
97
81
|
- !ruby/object:Gem::Version
|
98
82
|
version: '0'
|
99
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
-
none: false
|
101
84
|
requirements:
|
102
|
-
- -
|
85
|
+
- - ">="
|
103
86
|
- !ruby/object:Gem::Version
|
104
87
|
version: '0'
|
105
88
|
requirements: []
|
106
89
|
rubyforge_project:
|
107
|
-
rubygems_version:
|
90
|
+
rubygems_version: 2.2.2
|
108
91
|
signing_key:
|
109
|
-
specification_version:
|
92
|
+
specification_version: 4
|
110
93
|
summary: Easy syncing from remote to development database in Rails.
|
111
94
|
test_files:
|
95
|
+
- spec/local/.gitkeep
|
112
96
|
- spec/spec_helper.rb
|
113
97
|
- spec/sync_spec.rb
|
data/README.markdown
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
# dbsync
|
2
|
-
|
3
|
-
A set of rake tasks to help you sync your production
|
4
|
-
data with your local database for development.
|
5
|
-
|
6
|
-
Currently only supports MySQL. The Rake tasks are written for Rails-only,
|
7
|
-
but the Sync class can be used with ruby framework, as long as you pass in the
|
8
|
-
correct database configuration.
|
9
|
-
|
10
|
-
Support for more things will happen if anybody needs it.
|
11
|
-
|
12
|
-
|
13
|
-
## Usage
|
14
|
-
|
15
|
-
Add to your gemfile for the groups that will need it:
|
16
|
-
|
17
|
-
```ruby
|
18
|
-
group :development, :staging do
|
19
|
-
gem 'dbsync'
|
20
|
-
end
|
21
|
-
```
|
22
|
-
|
23
|
-
Add the following to your `config/environments/development.rb`
|
24
|
-
file. Depending on your staging setup, it may also be useful
|
25
|
-
to you to add some `dbsync` config to your `staging.rb`
|
26
|
-
environment file. **Note** `dbsync` will not run in production.
|
27
|
-
|
28
|
-
```ruby
|
29
|
-
config.dbsync = {
|
30
|
-
:filename => "yourapp_production_data.dump", # The name of the remote dumpfile.
|
31
|
-
:local_dir => "#{Rails.root}/../dbsync", # The local directory to store the dump file.
|
32
|
-
:remote_host => "66.123.4.567", # Remote server where the dumpfile is located.
|
33
|
-
:remote_dir => "~dbsync" # The directory on the remote server where the dumpfile is.
|
34
|
-
}
|
35
|
-
```
|
36
|
-
|
37
|
-
Now just make sure you have something on the remote
|
38
|
-
server updating that dumpfile. I recommend a cronjob:
|
39
|
-
|
40
|
-
0 */12 * * * /usr/bin/mysqldump yourapp_production > /home/dbsync/yourapp_production_data.dump
|
41
|
-
|
42
|
-
|
43
|
-
You will need proper SSH access into the remote server,
|
44
|
-
as the tasks use `rsync` and `scp` directly.
|
45
|
-
|
46
|
-
Run `rake -T dbsync` for all of the available tasks. The
|
47
|
-
tasks are named after `git` commands mostly, so they
|
48
|
-
should be pretty straight-forward for those who use `git`:
|
49
|
-
|
50
|
-
```
|
51
|
-
rake dbsync # Alias for dbsync:pull
|
52
|
-
rake dbsync:clone # Copy the remote dump file, reset the local database, and load in the dump file
|
53
|
-
rake dbsync:clone_dump # Copy the remote dump file to a local destination
|
54
|
-
rake dbsync:config # Show the dbsync configuration
|
55
|
-
rake dbsync:fetch # Update the local dump file from the remote source
|
56
|
-
rake dbsync:merge # Update the local database with the local dump file
|
57
|
-
rake dbsync:pull # Update the local dump file, and merge it into the local database
|
58
|
-
rake dbsync:reset # Drop and Create the database, then load the dump file
|
59
|
-
```
|
60
|
-
|
61
|
-
### TODO
|
62
|
-
|
63
|
-
- Support postgres, sqlite, and anything else.
|
64
|
-
|
65
|
-
|
66
|
-
### Copyright
|
67
|
-
|
68
|
-
Copyright (c) 2012 Bryan Ricker/SCPR.
|
69
|
-
|
70
|
-
### Licence
|
71
|
-
|
72
|
-
See MIT-LICENSE for more.
|