rbarman 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -21,7 +21,7 @@ Or install it yourself as:
21
21
 
22
22
  ## Usage
23
23
 
24
- Just a few examples..
24
+ Just a few examples. Please read the [documentation](https://rubygems.org/gems/rbarman) for more details.
25
25
 
26
26
  ### Get all your backups!
27
27
 
@@ -104,7 +104,7 @@ p b.id
104
104
 
105
105
  ### Delete a backup
106
106
 
107
- This tells pgbarman to delete the specified backup
107
+ This instructs barman to delete the specified backup
108
108
 
109
109
  <pre>
110
110
  backup = RBarman::Backup.by_id('server', '20130225T192654', { :with_wal_files => false })
@@ -115,10 +115,14 @@ p backup.deleted
115
115
  => true
116
116
  </pre>
117
117
 
118
- ### Not yet implemented
118
+ ### Recover a backup
119
119
 
120
- * restore backups
120
+ Recovers newest/latest backup to the specified path on the remote host
121
121
 
122
+ <pre>
123
+ RBarman::Backups.all('testdb').latest.recover('/var/lib/postgresql/9.2/main',
124
+ { :remote_ssh_cmd => 'ssh postgres@10.20.20.2' })
125
+ </pre>
122
126
 
123
127
  ## Contributing
124
128
 
@@ -133,5 +137,5 @@ p backup.deleted
133
137
 
134
138
  Written by [Holger Amann](http://github.com/hamann), sponsored by [Sauspiel GmbH](https://www.sauspiel.de)
135
139
 
136
- Release under the MIT License: http://www.opensource.org/licenses/mit-license.php
140
+ Release under the [MIT License](http://www.opensource.org/licenses/mit-license.php)
137
141
 
@@ -192,6 +192,23 @@ module RBarman
192
192
  @deleted = true
193
193
  end
194
194
 
195
+ # Instructs the underlying (barman) command to recover this backup
196
+ # @param [String] path the path to which the backup should be restored
197
+ # @param [Hash] opts options passed as arguments to barman recover cmd
198
+ # @option opts [String] :remote_ssh_cmd the ssh command to be used for remote recovery
199
+ # @option opts [String, Time] :target_time the timestamp as recovery target
200
+ # @option opts [String] :target_xid the transaction ID as recovery target
201
+ # @option opts [Boolean] :exclusive whether to stop immediately before or after the recovery target
202
+ # @return [void]
203
+ # @note when :remote_ssh_cmd is passed in options, 'path' is the path on the remote host, otherwise local
204
+ # @since 0.0.3
205
+ # @example
206
+ # backup.recover('/var/lib/postgresql/9.2/main', { :remote_ssh_cmd => 'ssh postgres@10.20.20.2' })
207
+ def recover(path, opts = {})
208
+ cmd = CliCommand.new
209
+ cmd.recover(@server, @id, path, opts)
210
+ end
211
+
195
212
  # Instructs the underlying (barman) command to create a new backup.
196
213
  # @param [String] server server name for which a backup should be created
197
214
  # @return [Backup] a new backup object with wal files
@@ -56,7 +56,6 @@ module RBarman
56
56
 
57
57
  # Instructs barman to get information about backups
58
58
  # @param [String] server server name
59
- # @param [String] backup_id when given, only information about this backup id will be retrieved
60
59
  # @param [Hash] opts options for creating {Backups}
61
60
  # @option opts [Boolean] :with_wal_files whether to include {WalFiles} in each {Backup}
62
61
  # @option opts [String] :backup_id retrieve just one {Backup} specified by this backup id
@@ -65,7 +64,7 @@ module RBarman
65
64
  list = run_barman_command("list-backup #{server}")
66
65
  list = list.grep(/#{opts[:backup_id]}/) if !opts[:backup_id].nil?
67
66
 
68
- backups = parse_backup_list(list)
67
+ backups = Backups.new(parse_backup_list(list))
69
68
  backups.each do |backup|
70
69
  parse_backup_info_file(backup)
71
70
  if opts[:with_wal_files]
@@ -303,6 +302,42 @@ module RBarman
303
302
  run_barman_command("backup #{server}")
304
303
  end
305
304
 
305
+ # Instructs barman to recover a backup
306
+ # @param [String] server the server which includes the backup
307
+ # @param [String] backup_id the id of the backup
308
+ # @param [String] path the path to which the backup should be restored
309
+ # @param [Hash] opts options passed as arguments to barman recover cmd
310
+ # @option opts [String] :remote_ssh_cmd the ssh command to be used for remote recovery
311
+ # @option opts [String, Time] :target_time the timestamp as recovery target
312
+ # @option opts [String] :target_xid the transaction ID as recovery target
313
+ # @option opts [Boolean] :exclusive whether to stop immediately before or after the recovery target
314
+ # @note when :remote_ssh_cmd is passed in options, 'path' is the path on the remote host, otherwise local
315
+ # @return [void]
316
+ # @since 0.0.3
317
+ # @example
318
+ # clicommand.recover('test2', '20130218T080002', '/var/lib/postgresql/9.2/main', { :remote_ssh_cmd => 'ssh postgres@10.20.20.2' })
319
+ def recover(server, backup_id, path, opts={})
320
+ args = create_recovery_cmd_args(opts)
321
+ run_barman_command("recover #{args} #{server} #{backup_id} #{path}")
322
+ end
323
+
324
+ # Creates an argument string for barman recovery command based on opts Hash
325
+ # @param [Hash] opts options for creating the arguments
326
+ # @option opts [String] :remote_ssh_cmd the ssh command to be used for remote recovery
327
+ # @option opts [String, Time] :target_time the timestamp as recovery target
328
+ # @option opts [String] :target_xid the transaction ID as recovery target
329
+ # @option opts [Boolean] :exclusive whether to stop immediately before or immediately after the recovery target
330
+ # @return [String] the arguments
331
+ # @since 0.0.3
332
+ def create_recovery_cmd_args(opts={})
333
+ args = Array.new
334
+ args << "--remote-ssh-command='#{opts[:remote_ssh_cmd]}'" if opts[:remote_ssh_cmd]
335
+ args << "--target-time '#{opts[:target_time].to_s}'" if opts[:target_time]
336
+ args << "--target-xid #{opts[:target_xid]}" if opts[:target_xid]
337
+ args << "--exclusive" if opts[:exclusive]
338
+ return args.join(" ")
339
+ end
340
+
306
341
  private
307
342
  def run_barman_command(args)
308
343
  sh = Mixlib::ShellOut.new("#{@binary} #{args}")
@@ -1,3 +1,3 @@
1
1
  module RBarman
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbarman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-12 00:00:00.000000000 Z
12
+ date: 2013-03-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler