rubypond-s3backup-manager 0.0.4 → 0.0.5

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.
Files changed (4) hide show
  1. data/bin/s3backup +76 -0
  2. data/bin/s3backup_monitor +0 -0
  3. data/bin/s3restore +85 -0
  4. metadata +5 -3
data/bin/s3backup ADDED
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require 'rubygems'
4
+ require 's3backup-manager'
5
+
6
+ options = {}
7
+ optparse = OptionParser.new do|opts|
8
+ opts.banner = "Usage: s3backup.rb [options] file1 file2 ..."
9
+
10
+ opts.on('-l', '--list', 'List all available buckets') do
11
+ options[:list] = true
12
+ end
13
+
14
+ opts.on('--create BUCKET', String, 'Create a new bucket') do |bucket_name|
15
+ S3BackupManager::Bucket.create!(bucket_name)
16
+ exit
17
+ end
18
+
19
+
20
+ options[:type] = "file"
21
+ opts.on('--type TYPE', String, 'Type of backup. Valid options are "file" and "database". Defaults to "file"' ) do |t|
22
+ unless ["file","database"].include?(t)
23
+ puts 'Only "file" and "database" are valid values for --type'
24
+ exit(1)
25
+ end
26
+ options[:type] = t.downcase
27
+ end
28
+
29
+ options[:adapter] = "postgres"
30
+ opts.on('--adapter ADAPTER', 'Type of database to backup. To be used with "--type database"' ) do |a|
31
+ unless ["mysql","postgres"].include?(a)
32
+ puts 'Only "mysql" and "postgres" are valid values for --adapter'
33
+ exit(1)
34
+ end
35
+ options[:adapter] = a
36
+ end
37
+
38
+ opts.on('--username USER', 'User to connect to the database as' ) do |u|
39
+ options[:username] = u
40
+ end
41
+
42
+
43
+ options[:bucket] = nil
44
+ opts.on('--bucket BUCKET', 'AmazonS3 bucket you wish to store the backup in' ) do |b|
45
+ options[:bucket] = b
46
+ end
47
+
48
+ opts.on('-h', '--help', 'Display this screen') do
49
+ puts opts
50
+ exit
51
+ end
52
+ end
53
+ optparse.parse!
54
+
55
+ if options[:list] && !options[:type_provided]
56
+ S3BackupManager::Bucket.find_all.each do |bucket|
57
+ puts bucket
58
+ end
59
+ exit
60
+ end
61
+
62
+ def setup_backup_adapter(options)
63
+ if options[:bucket]
64
+ eval("S3BackupManager::#{options[:type].capitalize}Backup").new(options)
65
+ else
66
+ puts "You need to specify a valid bucket for retrieval"
67
+ exit(1)
68
+ end
69
+ end
70
+
71
+ backup_adapter = setup_backup_adapter(options)
72
+
73
+ ARGV.each do |f|
74
+ puts "Backing up #{f}..."
75
+ backup_adapter.backup(f)
76
+ end
File without changes
data/bin/s3restore ADDED
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require 'rubygems'
4
+ require "#{File.dirname(__FILE__)}/../lib/s3backup-manager"
5
+
6
+ options = {}
7
+ optparse = OptionParser.new do|opts|
8
+ opts.banner = "Usage: s3restore.rb [options] backup_file destination"
9
+
10
+ options[:adapter] = "postgres"
11
+ opts.on('--adapter ADAPTER', 'Type of database to backup. To be used with "--type database"' ) do |a|
12
+ unless ["mysql","postgres"].include?(a)
13
+ puts 'Only "mysql" and "postgres" are valid values for --adapter'
14
+ exit(1)
15
+ end
16
+ options[:adapter] = a
17
+ end
18
+
19
+ opts.on('--bucket BUCKET', 'AmazonS3 bucket you wish to store the backup in' ) do |b|
20
+ options[:bucket] = b
21
+ end
22
+
23
+ opts.on('--timestamp TIMESTAMP', 'Timestamp of file/database you want to restore' ) do |t|
24
+ options[:timestamp] = t
25
+ end
26
+
27
+ options[:type] = "file"
28
+ opts.on('--type TYPE', String, 'Type of backup. Valid options are "file" and "database". Defaults to "file"' ) do |t|
29
+ unless ["file","database"].include?(t.downcase)
30
+ puts 'Only "file" and "database" are valid values for --type'
31
+ exit(1)
32
+ end
33
+ options[:type] = t.downcase
34
+ options[:type_provided] = true
35
+ end
36
+
37
+ opts.on('-h', '--help', 'Display this screen') do
38
+ puts opts
39
+ exit
40
+ end
41
+
42
+ opts.on('-l', '--list', 'List all available buckets, or backed up files/databases if provided with --type') do
43
+ options[:list] = true
44
+ end
45
+
46
+ end
47
+ optparse.parse!
48
+
49
+ if options[:list] && !options[:type_provided]
50
+ S3BackupManager::Bucket.find_all.each do |bucket|
51
+ puts bucket
52
+ end
53
+ exit
54
+ end
55
+
56
+ def setup_backup_adapter(options)
57
+ if options[:bucket]
58
+ eval("S3BackupManager::#{options[:type].capitalize}Backup").new(options)
59
+ else
60
+ puts "You need to specify a valid bucket for retrieval"
61
+ exit(1)
62
+ end
63
+ end
64
+
65
+ backup_adapter = setup_backup_adapter(options)
66
+
67
+ if options[:list] && options[:bucket]
68
+ backup_adapter.files.each do |file|
69
+ puts "#{file.key.sub(%r{^filesystem/},"")} (%0.2f KB)" % (file.size.to_f/1024)
70
+ end
71
+ exit
72
+ end
73
+
74
+ source = ARGV[0]
75
+ destination = ARGV[1]
76
+ puts "Restoring #{source}..."
77
+ if options[:type] == "database"
78
+ backup_adapter.restore(source, options[:timestamp])
79
+ else
80
+ if ARGV.size != 2
81
+ puts "Please specify the source and destination files"
82
+ exit(1)
83
+ end
84
+ backup_adapter.restore(source, options[:timestamp], destination)
85
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubypond-s3backup-manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Glenn Gillen
@@ -34,8 +34,10 @@ dependencies:
34
34
  version:
35
35
  description: A series of scripts and a rack application for backing up databases and filesystems into tarballs, encrypting, and then storing off-site on AmazonS3
36
36
  email: glenn@rubypond.com
37
- executables: []
38
-
37
+ executables:
38
+ - s3backup
39
+ - s3backup_monitor
40
+ - s3restore
39
41
  extensions: []
40
42
 
41
43
  extra_rdoc_files: []