Class: LitestreamRails::RestorationsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/litestream_rails/restorations_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /restorations



4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/controllers/litestream_rails/restorations_controller.rb', line 4

def create
  database = params[:database].remove("[ROOT]/")
  dir, file = File.split(database)
  ext = File.extname(file)
  base = File.basename(file, ext)
  now = Time.now.utc.strftime("%Y%m%d%H%M%S")
  backup = File.join(dir, "#{base}-#{now}#{ext}")

  Litestream::Commands.restore(database, async: false, **{"-o" => backup})

  redirect_to root_path, notice: "Restored to <code>#{backup}</code>."
end