eventhub-command 0.3.7 → 0.3.8

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: e905d03ba5f13b0dc2c8b458f08619bd359b52fb
4
- data.tar.gz: f1b06b1b645d511aa791253f648ab68c5f1ffa2b
3
+ metadata.gz: d4da56a2bac456ac5244f676a92ebd2992b12f22
4
+ data.tar.gz: 01139ef38f51ba64c180567cc9dd9bb495578e4f
5
5
  SHA512:
6
- metadata.gz: dc69822118ed75ea670985a295b6803245763652f89112bfb02f267a5ffdb7ff9bfc176a3e91585356414ece6dc833e7de15f68d5e6e49521014780e363177c4
7
- data.tar.gz: cde30ea67d3c8202850d6f1b9cc17324a19366429597b7dc1b0a1241c55b5e8bfc492d95332ad386783b6a28475464a5692d375454cb8de3914d00bc0a8bb607
6
+ metadata.gz: c417a4b3abf4add944c5830a24f43155c5be174832f56a582b3a4c402d0ada35b2d30963a805782622b04d3092334308309171d6fc5b366bce057affabdfb461
7
+ data.tar.gz: 0aefa86aca74759c02eb2d5a151524ef94b012733d2c8e35fcd2048dc6aa25b10e6e2ef599fd223dc5d64d1da9174bca574bd195f528de0e9e4c16403ddf444e
data/README.md CHANGED
@@ -87,3 +87,5 @@ Those config files will be used uppon next deployment.
87
87
  * package_ruby: package ruby processors to zip files and copy to release directory on local machines. Those packages
88
88
  will be used upon next "deploy_via scp" or if you commit them to SVN then upon next "deploy_via svn"
89
89
  * generate_processor: generate a processor from a basic template
90
+
91
+
@@ -0,0 +1,61 @@
1
+ desc 'dump and restore db. Attention: those commands run on the local machine, not remote.'
2
+ command :db do |command|
3
+
4
+ command.switch([:v, :verbose], :desc => 'Show additional output.')
5
+ command.flag([:user], default_value: 'event_hub_console', desc: 'DB User')
6
+ command.flag([:db], default_value: 'event_hub_console', desc: 'DB name')
7
+ command.flag([:file], desc: "Output Filename, last backup will be taken as default")
8
+
9
+ command.command :dump do |c|
10
+ c.action do |global_options, options, args|
11
+ base = Eh::Settings.current.db_backups_dir
12
+ stamp = Time.now.strftime('%Y%m%d%H%M%S')
13
+ target = options[:file] || "#{stamp}-console-dump.sql"
14
+
15
+ cmd = "mkdir -p #{base} && cd #{base} && pg_dump -U#{options[:user]} #{options[:db]} -f#{target}"
16
+ if options[:verbose]
17
+ puts "will execute '#{cmd}'"
18
+ end
19
+ system cmd
20
+ end
21
+ end
22
+
23
+ command.command :restore do |c|
24
+ c.action do |global_options, options, args|
25
+ source = options[:file] || begin
26
+ base = Eh::Settings.current.db_backups_dir
27
+ pattern = File.join(base, '*')
28
+ files = Dir.glob(pattern).sort
29
+ files.last
30
+ end
31
+ if source.nil?
32
+ raise ArgumentError.new("No source file found in #{base} and none passed via --file")
33
+ end
34
+ cmd = "psql -U#{options[:user]} -d#{options[:db]} -f#{source}"
35
+ if options[:verbose]
36
+ puts "will execute '#{cmd}'"
37
+ end
38
+ system cmd
39
+ end
40
+ end
41
+
42
+ command.command :cleanup_dumps do |c|
43
+ c.flag([:keep], type: Integer, desc: "How many dumps to keep", default_value: 5)
44
+ c.action do |global_options, options, args|
45
+ keep = options[:keep]
46
+ base = Eh::Settings.current.db_backups_dir
47
+ pattern = File.join(base, '*')
48
+ files = Dir.glob(pattern).sort.reverse # keep most recent
49
+ to_delete = files[keep..-1] || []
50
+
51
+ to_delete.each do |file|
52
+ if options[:verbose]
53
+ puts "will delete #{file}"
54
+ end
55
+ system "rm #{file}"
56
+ end
57
+ puts "deleted #{to_delete.size} file(s)"
58
+ end
59
+ end
60
+
61
+ end
data/lib/eh/settings.rb CHANGED
@@ -126,6 +126,6 @@ class Eh::Settings
126
126
  end
127
127
 
128
128
  def db_backups_dir
129
- '/tmp/foo'
129
+ File.expand_path('~/backups')
130
130
  end
131
131
  end
data/lib/eh/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eh
2
- VERSION = '0.3.7'
2
+ VERSION = '0.3.8'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eventhub-command
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pascal Betz
@@ -153,6 +153,7 @@ files:
153
153
  - lib/deployer/stage.rb
154
154
  - lib/eh-commands.rb
155
155
  - lib/eh.rb
156
+ - lib/eh/commands/db.rb
156
157
  - lib/eh/commands/deploy_config.rb
157
158
  - lib/eh/commands/deploy_console.rb
158
159
  - lib/eh/commands/deploy_mule.rb