Class: BigBackup::Base
- Inherits:
-
Object
- Object
- BigBackup::Base
- Defined in:
- lib/big_backup/base.rb
Direct Known Subclasses
Instance Method Summary collapse
- #archive_databases ⇒ Object
- #archive_directories ⇒ Object
- #backup_config ⇒ Object
- #backup_databases ⇒ Object
- #error_message(message) ⇒ Object
- #exec_cmd(line) ⇒ Object
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #ok_message(message) ⇒ Object
- #start ⇒ Object
- #start_message(message) ⇒ Object
- #upload_databases ⇒ Object
- #upload_directories ⇒ Object
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
4 5 6 |
# File 'lib/big_backup/base.rb', line 4 def initialize @current_time = Time.now.strftime("%Y.%m.%d") end |
Instance Method Details
#archive_databases ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/big_backup/base.rb', line 48 def archive_databases puts "\nArchive Backups".bright.color(:cyan) self.backup_config['databases'].each do |type, config| cmd_line = BigBackup::Archive.new(config).build_cmd(@current_time) + " > /dev/null 2>&1" unless cmd_line.blank? (cmd_line) exec_cmd(cmd_line) end end end |
#archive_directories ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/big_backup/base.rb', line 74 def archive_directories puts "\nCreate directories backups".bright.color(:cyan) cmd_line = BigBackup::Archive.new(self.backup_config['directories']).build_cmd + " > /dev/null 2>&1" unless cmd_line.blank? (cmd_line) exec_cmd(cmd_line) end end |
#backup_config ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/big_backup/base.rb', line 29 def backup_config if File.exists?(BigBackup.config_path) @backup_config ||= YAML.load_file(BigBackup.config_path) else @backup_config ||= YAML.load_file("#{File.dirname(__FILE__)}/../../config/bigbackup.yml") end end |
#backup_databases ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/big_backup/base.rb', line 37 def backup_databases puts "\nCreate Backups".bright.color(:cyan) self.backup_config['databases'].each do |type, config| cmd_line = BigBackup::Database::Base.build(type, config).build_cmd(@current_time) unless cmd_line.blank? (cmd_line) exec_cmd(cmd_line) end end end |
#error_message(message) ⇒ Object
16 17 18 |
# File 'lib/big_backup/base.rb', line 16 def () puts "ERROR".color(:red).bright+" -> #{}" end |
#exec_cmd(line) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/big_backup/base.rb', line 20 def exec_cmd(line) system(line) if $?.exitstatus > 0 (line) else (line) end end |
#ok_message(message) ⇒ Object
12 13 14 |
# File 'lib/big_backup/base.rb', line 12 def () puts "OK".color(:green).bright+" -> #{}" end |
#start ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/big_backup/base.rb', line 96 def start FileUtils.rm_rf "/tmp/bigbackup" Dir.mkdir "/tmp/bigbackup" if File.directory?("/tmp/bigbackup") puts "\nStart BigBackup \n".color(:green).bright if self.backup_config.include?('databases') self.backup_databases self.archive_databases self.upload_databases end if self.backup_config.include?('directories') self.archive_directories self.upload_directories end puts "\nStop BigBackup \n".color(:green).bright end end |
#start_message(message) ⇒ Object
8 9 10 |
# File 'lib/big_backup/base.rb', line 8 def () puts "\nStart".bright+" -> #{}" end |
#upload_databases ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/big_backup/base.rb', line 59 def upload_databases if self.backup_config.include?('backup_server') puts "\nUpload Backups".bright.color(:cyan) self.backup_config['databases'].each do |type, config| ("upload #{type} backups") begin BigBackup::Uploader::Base.build(:ftp, config).upload(type, @current_time) ("database backups uploaded") rescue Errno::ECONNREFUSED ("Can't connect to FTP Server") end end end end |
#upload_directories ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/big_backup/base.rb', line 83 def upload_directories if self.backup_config.include?('backup_server') puts "\nUpload directories Backups".bright.color(:cyan) ("upload directorie backups") begin BigBackup::Uploader::Base.build(:ftp, self.backup_config['directories']).upload("directories_backup", @current_time) ("directories uploaded") rescue Errno::ECONNREFUSED ("Can't connect to FTP Server") end end end |