Guest User

Untitled

a guest
Jul 19th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. module Backup
  2. module Adapters
  3. class Base
  4.  
  5. attr_accessor :procedure, :timestamp, :options, :tmp_path, :encrypt_with_password, :keep_backups, :trigger
  6.  
  7. # IMPORTANT
  8. # final_file must have the value of the final filename result
  9. # so if a file gets compressed, then the file could look like this:
  10. # myfile.gz
  11. #
  12. # and if a file afterwards gets encrypted, the file will look like:
  13. # myfile.gz.enc
  14. #
  15. # It is important that, whatever the final filename of the file will be, that :final_file will contain it.
  16. attr_accessor :final_file
  17.  
  18. def initialize(trigger, procedure)
  19. self.trigger = trigger
  20. self.procedure = procedure
  21. self.timestamp = Time.now.strftime("%Y%m%d%H%M%S")
  22. self.tmp_path = File.join(RAILS_ROOT.gsub(' ', '\ '), 'tmp', 'backup', trigger)
  23. self.encrypt_with_password = procedure.attributes['encrypt_with_password']
  24. self.keep_backups = procedure.attributes['keep_backups']
  25. create_tmp_folder
  26. end
  27.  
  28. # Creates the temporary folder for the specified adapter
  29. def create_tmp_folder
  30. %x{ mkdir -p #{tmp_path} }
  31. end
  32.  
  33. # Removes the files inside the temporary folder
  34. def remove_tmp_files
  35. %x{ rm #{File.join(tmp_path, '*')} }
  36. end
  37.  
  38. # Initializes the storing process depending on the store settings
  39. # Options:
  40. # Amazon (S3)
  41. # Remote Server (SCP)
  42. # Remote Server (FTP)
  43. # Remote Server (SFTP)
  44. def store
  45. case procedure.storage_name.to_sym
  46. when :s3 then Backup::Storage::S3.new(self)
  47. when :scp then Backup::Storage::SCP.new(self)
  48. when :ftp then Backup::Storage::FTP.new(self)
  49. when :sftp then Backup::Storage::SFTP.new(self)
  50. end
  51. end
  52.  
  53. # Records data on every individual file to the database
  54. def record
  55. case procedure.storage_name.to_sym
  56. when :s3
  57. record = Backup::Record::S3.new
  58. record.load_adapter(self)
  59. record.save
  60. when :scp
  61. record = Backup::Record::SCP.new
  62. record.load_adapter(self)
  63. record.save
  64. when :ftp
  65. record = Backup::Record::FTP.new
  66. record.load_adapter(self)
  67. record.save
  68. when :sftp
  69. record = Backup::Record::SFTP.new
  70. record.load_adapter(self)
  71. record.save
  72. end
  73. end
  74.  
  75. end
  76. end
  77. end
Add Comment
Please, Sign In to add comment