dbmgr 0.1.2 → 0.1.3
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 +4 -4
- data/README.md +61 -10
- data/dbmgr.gemspec +1 -0
- data/lib/dbmgr/cli/mysql.rb +19 -15
- data/lib/dbmgr/version.rb +1 -1
- metadata +16 -3
- data/dbmgr.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93d8ee795896f8c51a88fd038bd689a828beca6a
|
4
|
+
data.tar.gz: e205d42fe6ca7fee844b3d1b49cb29e382a3ec33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 686aac888b556537252078f0b986026860851107365e54bbf3bb9b3c515c83535e1aea835ef8d8afe3d7eb87a24bd4b91493fc5eaff941ad9ccb492d7462f33d
|
7
|
+
data.tar.gz: 935866afca624476219810cce0e992c184327cee5ba58250937e2df81d151f6f9a025146f98075028b9077bbe2133ed2e7fb84b55767ccfc1864d4c29ec5b9ce
|
data/README.md
CHANGED
@@ -1,30 +1,81 @@
|
|
1
1
|
# Dbmgr
|
2
2
|
|
3
|
-
`dbmgr` is a command line tool for backing up and restoring
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
- Sharing databases between developers on our team
|
3
|
+
`dbmgr` is a command line tool for backing up and restoring databases. It's a useful
|
4
|
+
tool for:
|
5
|
+
- Sharing databases between developers
|
6
|
+
- Provisioning new Vagrant vms and Docker images
|
8
7
|
- Provisioning new developers with a working database
|
9
8
|
|
10
9
|
## Installation
|
11
10
|
|
11
|
+
```
|
12
|
+
$ brew install callahanrts/dbmgr/dbmgr
|
13
|
+
```
|
14
|
+
or
|
12
15
|
```
|
13
16
|
$ gem install dbmgr
|
14
17
|
```
|
15
18
|
|
16
19
|
## Usage
|
17
20
|
|
18
|
-
####
|
19
|
-
##### Help
|
21
|
+
#### Help
|
20
22
|
```
|
21
|
-
dbmgr
|
23
|
+
$ dbmgr help
|
22
24
|
```
|
25
|
+
|
26
|
+
#### Backup
|
23
27
|
```
|
24
|
-
|
28
|
+
$ dmgr mysql backup --options
|
25
29
|
```
|
26
30
|
|
27
31
|
#### Restore
|
28
32
|
```
|
29
|
-
dbmgr mysql restore --options
|
33
|
+
$ dbmgr mysql restore --options
|
34
|
+
```
|
35
|
+
|
36
|
+
#### Config
|
37
|
+
Options can either be passed in each command or they can be set as defaults in the `~/.dbmgr`
|
38
|
+
config file.
|
39
|
+
```ruby
|
40
|
+
# ~/.dbmgr
|
41
|
+
|
42
|
+
:dbmgr:
|
43
|
+
:path: "~/.db_backups"
|
44
|
+
|
45
|
+
:mysql:
|
46
|
+
:port: 3306
|
47
|
+
:host: 'localhost'
|
48
|
+
:user: "root"
|
49
|
+
```
|
50
|
+
|
51
|
+
## Examples
|
52
|
+
#### Back up a MySQL database
|
53
|
+
|
54
|
+
```bash
|
55
|
+
# Back up database from local MySQL server
|
56
|
+
$ dbmgr mysql backup database_name
|
57
|
+
|
58
|
+
# Back up database from a remote MySQL server
|
59
|
+
$ dbmgr mysql backup database_name -P 3307 -h 192.168.33.10 -u root
|
60
|
+
|
61
|
+
# Back up database and store in a specific location
|
62
|
+
$ dbmgr mysql backup database_name -p ~/Downloads
|
63
|
+
|
64
|
+
# Back up database as a named backup
|
65
|
+
$ dbmgr mysql backup database_name -f my_backup.sql
|
66
|
+
```
|
67
|
+
|
68
|
+
#### Restore a MySQL database
|
69
|
+
```bash
|
70
|
+
# Restore local database from the latest backup in the default location
|
71
|
+
$ dbmgr mysql restore database_name
|
72
|
+
|
73
|
+
# Restore remote database with the latest backup
|
74
|
+
$ dbmgr mysql restore database_name -P 3307 -h 192.168.33.10 -u root
|
75
|
+
|
76
|
+
# Restore local database from the latest backup in a specific location
|
77
|
+
$ dbmgr mysql restore database_name -p ~/Downloads
|
78
|
+
|
79
|
+
# Restore database from a named backup
|
80
|
+
$ dbmgr mysql restore database_name -f my_backup.sql
|
30
81
|
```
|
data/dbmgr.gemspec
CHANGED
data/lib/dbmgr/cli/mysql.rb
CHANGED
@@ -20,21 +20,21 @@ module Dbmgr::CLI
|
|
20
20
|
banner: "#{ENV["HOME"]}/.db_backups",
|
21
21
|
desc: "Directory of database backups"
|
22
22
|
|
23
|
-
method_option :
|
23
|
+
method_option :port,
|
24
24
|
aliases: ["P"],
|
25
25
|
type: :numeric,
|
26
26
|
default: 3306,
|
27
27
|
banner: "3306",
|
28
28
|
desc: "MySQL database port"
|
29
29
|
|
30
|
-
method_option :
|
30
|
+
method_option :host,
|
31
31
|
aliases: ["h"],
|
32
32
|
type: :string,
|
33
33
|
default: "localhost",
|
34
34
|
banner: "localhost",
|
35
35
|
desc: "MySQL database host"
|
36
36
|
|
37
|
-
method_option :
|
37
|
+
method_option :user,
|
38
38
|
aliases: ["u"],
|
39
39
|
type: :string,
|
40
40
|
default: "root",
|
@@ -42,14 +42,14 @@ module Dbmgr::CLI
|
|
42
42
|
desc: "MySQL database user"
|
43
43
|
|
44
44
|
def backup db_name
|
45
|
-
puts "Backing up '#{db_name}' to '#{options[:path]}'..."
|
46
45
|
file = options[:filename] || "#{db_name}_#{Time.now.to_i}.sql"
|
46
|
+
puts "Backing up '#{db_name}' (#{options[:path]}/#{file})..."
|
47
47
|
|
48
48
|
# Create the backups directory if it doesn't exist already
|
49
49
|
system "mkdir -p #{options[:path]}"
|
50
50
|
|
51
51
|
# Create a mysql backup from the user supplied options
|
52
|
-
system "mysqldump -u#{options[:
|
52
|
+
system "mysqldump -u#{options[:user]} -h #{options[:host]} -P #{options[:port]} #{db_name} > #{options[:path]}/#{file}"
|
53
53
|
end
|
54
54
|
|
55
55
|
|
@@ -70,21 +70,21 @@ module Dbmgr::CLI
|
|
70
70
|
banner: "#{ENV["HOME"]}/.db_backups",
|
71
71
|
desc: "Directory of database backups"
|
72
72
|
|
73
|
-
method_option :
|
73
|
+
method_option :port,
|
74
74
|
aliases: ["P"],
|
75
75
|
type: :numeric,
|
76
76
|
default: 3306,
|
77
77
|
banner: "3306",
|
78
78
|
desc: "MySQL database port"
|
79
79
|
|
80
|
-
method_option :
|
80
|
+
method_option :host,
|
81
81
|
aliases: ["h"],
|
82
82
|
type: :string,
|
83
83
|
default: "localhost",
|
84
84
|
banner: "localhost",
|
85
85
|
desc: "MySQL database host"
|
86
86
|
|
87
|
-
method_option :
|
87
|
+
method_option :user,
|
88
88
|
aliases: ["u"],
|
89
89
|
type: :string,
|
90
90
|
default: "root",
|
@@ -95,24 +95,28 @@ module Dbmgr::CLI
|
|
95
95
|
puts "Create database if it doesn't exist..."
|
96
96
|
|
97
97
|
# Create the database to restore if it doesn't exist already
|
98
|
-
system "mysql -u#{options[:
|
98
|
+
system "mysql -u#{options[:user]} -h #{options[:host]} -P #{options[:port]} -e \"CREATE DATABASE IF NOT EXISTS #{db_name}\""
|
99
99
|
|
100
100
|
# Grab the backup file or the latest backup from the backups directory
|
101
101
|
backup = options[:backup] || Dir.glob("#{options[:path]}/#{db_name}_*.sql").last
|
102
|
-
raise "Restore failed: backup not found" unless File.file?(backup)
|
102
|
+
raise "Restore failed: backup not found" unless File.file?(backup.to_s)
|
103
103
|
|
104
104
|
# Restore the database from a backup
|
105
|
-
system("mysql -u#{options[:
|
105
|
+
system("mysql -u#{options[:user]} #{db_name} -h #{options[:host]} -P #{options[:port]} < #{backup}")
|
106
106
|
end
|
107
107
|
|
108
108
|
private
|
109
109
|
|
110
110
|
def options
|
111
111
|
original = super
|
112
|
-
return original unless File.file?("#{
|
113
|
-
config = YAML::load_file("#{
|
114
|
-
config[:dbmgr][:path].gsub!("~/", "#{
|
115
|
-
Thor::CoreExt::HashWithIndifferentAccess.new([
|
112
|
+
return original unless File.file?("#{home}/.dbmgr")
|
113
|
+
config = YAML::load_file("#{home}/.dbmgr") || {dbmgr: {}, mysql: {}}
|
114
|
+
config[:dbmgr][:path].gsub!("~/", "#{home}/") if !config[:dbmgr].nil? && config[:dbmgr].has_key?(:path) # Expand ~/ manually
|
115
|
+
Thor::CoreExt::HashWithIndifferentAccess.new([config[:dbmgr], config[:mysql], original].reduce &:merge)
|
116
|
+
end
|
117
|
+
|
118
|
+
def home
|
119
|
+
ENV["HOME"]
|
116
120
|
end
|
117
121
|
|
118
122
|
end
|
data/lib/dbmgr/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dbmgr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cody
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ~>
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.4.5
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: mocha
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.2.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.2.1
|
83
97
|
description: Create database backups to share with others across your dev team. Other
|
84
98
|
developers can restore from backups you've created.
|
85
99
|
email:
|
@@ -101,7 +115,6 @@ files:
|
|
101
115
|
- bin/dbmgr-dev
|
102
116
|
- bin/setup
|
103
117
|
- dbmgr.gemspec
|
104
|
-
- dbmgr.rb
|
105
118
|
- examples/.dbmgr
|
106
119
|
- lib/dbmgr.rb
|
107
120
|
- lib/dbmgr/cli.rb
|
data/dbmgr.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
|
2
|
-
class Dbmgr < Formula
|
3
|
-
|
4
|
-
desc "Backup and restore development databases"
|
5
|
-
homepage "https://github.com/callahanrts/dbmgr"
|
6
|
-
url "https://github.com/callahanrts/dbmgr/archive/v0.1.2.tar.gz"
|
7
|
-
|
8
|
-
head "https://github.com/callahanrts/dbmgr.git"
|
9
|
-
bottle :unneeded
|
10
|
-
|
11
|
-
def install
|
12
|
-
lib.install Dir["lib/*"]
|
13
|
-
bin.install "bin/dbmgr"
|
14
|
-
end
|
15
|
-
|
16
|
-
test do
|
17
|
-
system "#{bin}/dbmgr", "help"
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|