bin/encbs in encbs-0.1.1 vs bin/encbs in encbs-0.1.2
- old
+ new
@@ -14,15 +14,16 @@
require 'fog'
require 'progressbar'
end
require 'backup'
+require 'encbsconfig'
opts = Slop.parse :help => true do
on :a, :add, "Add path to backup", true
on :b, :bucket, "Set Amazon S3 bucket to backup", true
- on :c, :config, "Use config file to upload backup", true #TODO
+ on :c, :config, "Use config file to upload backup", true
on :colorize, "Colorize print to console"
on :d, :date, "Date for backup restore (default: last)", true
on :g, :generate, "Generate RSA keys (option: 4096, 2048)", true
on :h, :hostname, "Set hostname (default: system)", true
on :i, :increment, "Use increment mode for backup (default: false)"
@@ -32,25 +33,31 @@
on :list, "List of jars"
on :r, :rescue, "Return data from backup (option: jar, path or filter)", true
on :s, :secret, "Set API secret to access Amazon S3", true
on :t, :to, "Path to recovery (default: /)", true
on :token, "RSA Key to encrypt/decrypt backup data", true
- on :threads, "Set count of thread (default: 1)", true
on :v, :verbose, "Verbose mode"
banner "Usage:\n $ encbs [options]\n\nOptions:"
end
-if ARGV.empty?
- puts opts.help
+@config = EncbsConfig.new
- exit
+if ARGV.empty?
+ if File.exists?("#{Dir.getwd}/Encbsfile")
+ @config.load "#{Dir.getwd}/Encbsfile"
+ else
+ puts opts.help
+ exit
+ end
end
-$PRINT_VERBOSE = opts.verbose?
-$COLORIZE = opts.colorize?
+@config.load opts[:config] if opts.config?
+$PRINT_VERBOSE = @config.verbose || opts.verbose?
+$COLORIZE = @config.colorize || opts.colorize?
+
if opts.generate?
bits = opts[:generate].to_i
puts_fail "Unsupport #{bits} bits" unless bits == 4096 or bits == 2048
puts "Generate #{bits} bits RSA keys"
Crypto::create_keys(
@@ -66,22 +73,24 @@
if opts.local?
try_create_dir opts[:local]
@backup = Backup::Instance.new opts[:local]
else
[:key, :secret, :bucket].each do |arg|
- puts_fail "Argument '--#{arg}' should not be empty" if opts[arg].nil?
+ if opts[arg].nil? and @config.send(arg).nil?
+ puts_fail "Argument '--#{arg}' should not be empty"
+ end
end
@backup = Backup::Instance.new(
"backups",
true,
- :bucket => opts[:bucket],
- :key => opts[:key],
- :secret => opts[:secret]
+ :bucket => @config.bucket || opts[:bucket],
+ :key => @config.key || opts[:key],
+ :secret => @config.secret || opts[:secret]
)
end
-@backup.hostname = opts[:hostname] if opts.hostname?
+@backup.hostname = @config.hostname || (opts[:hostname] if opts.hostname?)
if opts.list?
jars_list = @backup.jars
unless jars_list.empty?
@@ -94,12 +103,18 @@
end
exit
end
-@backup.key = opts[:token] if opts.token?
+if @config.token || opts.token?
+ key = @config.token || opts[:token]
+ puts_fail "Key #{key.dark_green} not found" unless File.exists? key
+
+ @backup.key = key
+end
+
if opts.date?
date = opts[:date].split("-")
unless date.length == 1
@start_date = Backup::Timestamp.parse_timestamp date[0]
@@ -190,11 +205,11 @@
puts "Done!".green
exit
end
-if opts.add?
- paths = opts[:add].split(" ")
+if @config.paths || opts.add?
+ paths = @config.paths.split(" ") || opts[:add].split(" ")
paths = paths.map do |path|
path = File.expand_path path
puts_fail "Path \"#{path}\" not exists." unless File.exists? path