Class: Siba::Destination::Dir::DestDir
- Inherits:
-
Object
- Object
- Siba::Destination::Dir::DestDir
- Includes:
- FilePlug, LoggerPlug
- Defined in:
- lib/siba/plugins/destination/dir/dest_dir.rb
Instance Attribute Summary collapse
-
#dir ⇒ Object
Returns the value of attribute dir.
Instance Method Summary collapse
- #copy_backup_to_dest(path_to_backup) ⇒ Object
-
#get_backups_list(backup_name) ⇒ Object
Returns an array of two-element arrays: [file_name, mtime].
-
#initialize(dir) ⇒ DestDir
constructor
A new instance of DestDir.
- #restore_backup_to_dir(backup_name, to_dir) ⇒ Object
- #test_dir_access ⇒ Object
Methods included from LoggerPlug
close, create, logger, #logger, opened?
Methods included from FilePlug
#siba_file, siba_file, siba_file=
Constructor Details
#initialize(dir) ⇒ DestDir
Returns a new instance of DestDir.
10 11 12 13 |
# File 'lib/siba/plugins/destination/dir/dest_dir.rb', line 10 def initialize(dir) @dir = siba_file. dir test_dir_access end |
Instance Attribute Details
#dir ⇒ Object
Returns the value of attribute dir.
8 9 10 |
# File 'lib/siba/plugins/destination/dir/dest_dir.rb', line 8 def dir @dir end |
Instance Method Details
#copy_backup_to_dest(path_to_backup) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/siba/plugins/destination/dir/dest_dir.rb', line 15 def copy_backup_to_dest(path_to_backup) siba_file.run_this "copy backup to dest" do logger.info "Copying backup to destination directory: #{dir}" unless siba_file.file_file? path_to_backup raise Siba::Error, "Backup file '#{path_to_backup}' does not exist" end unless siba_file.file_directory? dir raise Siba::Error, "Destination directory '#{dir}' does not exist" end siba_file.file_utils_cp(path_to_backup, dir) end end |
#get_backups_list(backup_name) ⇒ Object
Returns an array of two-element arrays: [file_name, mtime]
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/siba/plugins/destination/dir/dest_dir.rb', line 65 def get_backups_list(backup_name) siba_file.run_this do Siba::FileHelper.entries(dir).select do |f| f =~ /^#{backup_name}/ end.map do |f| mtime = siba_file.file_mtime File.join dir, f [f, mtime] end end end |
#restore_backup_to_dir(backup_name, to_dir) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/siba/plugins/destination/dir/dest_dir.rb', line 28 def restore_backup_to_dir(backup_name, to_dir) siba_file.run_this do logger.info "Copying backup from destination directory: #{dir}" path_to_backup = File.join dir, backup_name unless siba_file.file_file? path_to_backup raise Siba::Error, "Can not find backup #{path_to_backup}" end siba_file.file_utils_cp path_to_backup, to_dir end end |
#test_dir_access ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/siba/plugins/destination/dir/dest_dir.rb', line 40 def test_dir_access siba_file.run_this "test dir access" do # create dest dir begin siba_file.file_utils_mkpath dir unless siba_file.file_directory? dir rescue Exception logger.error "Failed to create destination dir '#{dir}'." raise end # copy a test file to dest dir begin test_file = Siba::TestFiles.prepare_test_file "destination_dir", dir raise "Can not find the test file." unless siba_file.file_file? test_file siba_file.file_utils_remove_entry_secure test_file rescue Exception logger.error "Could not write to destination dir '#{dir}'" raise end logger.debug "Access to destination directory is verified" end end |