From c82f7bb6dcfc819f514e37eefcdc2b996931f102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Wed, 12 Feb 2014 20:31:17 -0800 Subject: [PATCH] Backup model --- app/models/backup.rb | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 app/models/backup.rb diff --git a/app/models/backup.rb b/app/models/backup.rb new file mode 100644 index 000000000..88d4d89fe --- /dev/null +++ b/app/models/backup.rb @@ -0,0 +1,37 @@ +class Backup + include UrlHelper + include ActiveModel::SerializerSupport + + attr_reader :filename, :size, :path, :link + + def initialize(filename) + @filename = filename + @path = File.join(Backup.base_directory, filename) + @link = schemaless "#{Discourse.base_url}/admin/backups/#{filename}" + @size = File.size(@path) + end + + def self.all + backups = Dir.glob(File.join(Backup.base_directory, "*.tar.gz")) + backups.sort.reverse.map { |backup| Backup.new(File.basename(backup)) } + end + + def self.[](filename) + path = File.join(Backup.base_directory, filename) + if File.exists?(path) + Backup.new(filename) + else + nil + end + end + + def self.remove(filename) + path = File.join(Backup.base_directory, filename) + File.delete(path) if File.exists?(path) + end + + def self.base_directory + @base_directory ||= File.join(Rails.root, "public", "backups", RailsMultisite::ConnectionManagement.current_db) + end + +end