lib/shelly/cli/backup.rb in shelly-0.2.24 vs lib/shelly/cli/backup.rb in shelly-0.2.25
- old
+ new
@@ -7,11 +7,11 @@
module CLI
class Backup < Command
namespace :backup
include Helpers
- before_hook :logged_in?, :only => [:list, :get, :create, :restore]
+ before_hook :logged_in?, :only => [:list, :get, :create, :restore, :import]
class_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
method_option :all, :type => :boolean, :aliases => "-a",
:desc => "Show all backups"
@@ -83,11 +83,11 @@
desc "restore FILENAME", "Restore database to state from given backup"
def restore(filename)
app = multiple_clouds(options[:cloud], "backup restore FILENAME")
backup = app.database_backup(filename)
- say "You are about restore database #{backup.kind} for cloud #{backup.code_name} to state from #{backup.filename}"
+ say "You are about restore #{backup.kind} database for cloud #{backup.code_name} to state from #{backup.filename}"
say_new_line
ask_to_restore_database
app.restore_backup(filename)
say_new_line
say "Restore has been scheduled. Wait a few minutes till database is restored.", :green
@@ -95,9 +95,40 @@
raise unless e.resource == :backup
say_error "Backup not found", :with_exit => false
say "You can list available backups with `shelly backup list` command"
rescue Client::ConflictException => e
say_error e[:message]
+ end
+
+ desc "import KIND FILENAME", "Import database from dump file"
+ long_desc %{
+ Import database from local dump file to your cloud
+ KIND - Database kind. Possible values are: postgresql or mongodb
+ FILENAME - Database dump file or directory (mongodb), it has to be in current working directory.
+ }
+ def import(kind, filename)
+ app = multiple_clouds(options[:cloud], "backup import KIND FILENAME")
+ unless ::File.exist?(filename)
+ say_error "File #{filename} doesn't exist"
+ end
+ say "You are about import #{kind} database for cloud #{app} to state from file #{filename}"
+ ask_to_import_database
+ archive = compress(filename)
+ say "Uploading #{archive}", :green
+ app.upload(archive)
+ say "Uploading done", :green
+ say "Importing database", :green
+ app.import_database(kind, archive)
+ say "Database imported successfully", :green
+ end
+
+ no_tasks do
+ def compress(filename)
+ archive_name = "#{::File.basename(filename)}.tar"
+ say "Compressing #{filename} into #{archive_name}", :green
+ system("tar -cf #{archive_name} #{filename}")
+ archive_name
+ end
end
end
end
end