Module: BackupParadise

Defined in:
lib/backup_paradise/tab/tab.rb,
lib/backup_paradise/base/tab.rb,
lib/backup_paradise/base/base.rb,
lib/backup_paradise/base/colours.rb,
lib/backup_paradise/actions/backup.rb,
lib/backup_paradise/base/namespace.rb,
lib/backup_paradise/colours/colours.rb,
lib/backup_paradise/project/project.rb,
lib/backup_paradise/version/version.rb,
lib/backup_paradise/windows/windows.rb,
lib/backup_paradise/toplevel_methods/e.rb,
lib/backup_paradise/constants/constants.rb,
lib/backup_paradise/gui/gtk2/OLD_backup.rb,
lib/backup_paradise/toplevel_methods/help.rb,
lib/backup_paradise/toplevel_methods/misc.rb,
lib/backup_paradise/toplevel_methods/opnn.rb,
lib/backup_paradise/toplevel_methods/cliner.rb,
lib/backup_paradise/toplevel_methods/config.rb,
lib/backup_paradise/toplevel_methods/esystem.rb,
lib/backup_paradise/toplevel_methods/mountpoint.rb,
lib/backup_paradise/utility_scripts/backup/backup.rb,
lib/backup_paradise/toplevel_methods/create_and_remove.rb,
lib/backup_paradise/toplevel_methods/files_and_directories.rb,
lib/backup_paradise/gui/libui/backup_for_ingrid/backup_for_ingrid.rb,
lib/backup_paradise/gui/universal_widgets/simple_backup_widget/simple_backup_widget.rb

Overview

#

BackupParadise::GUI::LibUI::BackupForIngrid

#

require ‘backup_paradise/gui/libui/backup_for_ingrid/backup_for_ingrid.rb’ BackupParadise::GUI::LibUI::BackupForIngrid.new

#

Defined Under Namespace

Modules: Actions, GUI, Gtk, Tab, Windows Classes: Backup, Base

Constant Summary collapse

PROJECT_BASE_DIRECTORY =
#

PROJECT_BASE_DIRECTORY

#
File.absolute_path("#{__dir__}/..")+'/'
VERSION =
#

VERSION

#
'1.3.5'
LAST_UPDATE =
#

LAST_UPDATE

#
'20.01.2024'
NAMESPACE =
#

NAMESPACE

#
inspect
N =
#

N

#
"\n"
AUTOGENERATED_DIRECTORY =
#

AUTOGENERATED_DIRECTORY

#
'/AUTOGENERATED/'
USB1 =
#

USB1

#
'/dev/sda1'
USB2 =
#

USB2

#
'/dev/sdb1'
USB3 =
#

USB3

#
'/dev/sdc1'
USB4 =
#

USB4

#
'/dev/sdd1'
USB5 =
#

USB5

#
'/dev/sde1'
USB6 =
#

USB6

#
'/dev/sdf1'
USB7 =
#

USB7

#
'/dev/sdg1'
USB8 =
#

USB8

#
'/dev/sdh1'
DEFAULT_MODE =
#

DEFAULT_MODE

Which mode we will use for newly-created directories and files.

#
0755
HOME_DIRECTORY_OF_THE_USER_X =
#

HOME_DIRECTORY_OF_THE_USER_X

#
'/home/x/'
STUDIUM_DIRECTORY =

else hardcode it.

"#{HOME_DIRECTORY_OF_THE_USER_X}studium/"
STUDIUM_DIR =

STUDIUM_DIR

STUDIUM_DIRECTORY
DATA_DIR =
"#{HOME_DIRECTORY_OF_THE_USER_X}DATA/"
DATA_DIRECTORY =

DATA_DIRECTORY

DATA_DIR
AUDIO_DIR =
"#{HOME_DIRECTORY_OF_THE_USER_X}songs/"
AUDIO_DIRECTORY =

AUDIO_DIRECTORY

AUDIO_DIR
DIRECTORY_CONTAINING_ALL_SONGS =
#

DIRECTORY_CONTAINING_ALL_SONGS

#
"#{HOME_DIRECTORY_OF_THE_USER_X}songs/"
VIDEO_DIRECTORY =
#

VIDEO_DIRECTORY

#
"#{HOME_DIRECTORY_OF_THE_USER_X}video/"
SOURCE_DIRECTORY =
"#{HOME_DIRECTORY_OF_THE_USER_X}src/"
SRC_DIR =

SRC_DIR

SOURCE_DIRECTORY
PROGRAMS_DIRECTORY =
'/home/Programs/'
PROGRAMS_DIR =

PROGRAMS_DIR

PROGRAMS_DIRECTORY
SYSTEM_SETTINGS_DIRECTORY =
#

SYSTEM_SETTINGS_DIRECTORY

#
ENV['SYS_SETTINGS'].to_s.dup
SYS_SETTINGS =

SYS_SETTINGS

SYSTEM_SETTINGS_DIRECTORY
DEPOT_DIRECTORY =
'/Depot/Temp/'
BOOKS_DIRECTORY =
"#{HOME_DIRECTORY_OF_THE_USER_X}books/"
CONFIG =

This will be a Hash.

{}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.are_we_on_linux?Boolean

#

BackupParadise.are_we_on_linux?

#

Returns:

  • (Boolean)


58
59
60
# File 'lib/backup_paradise/toplevel_methods/misc.rb', line 58

def self.are_we_on_linux?
  RbConfig::CONFIG['host_os'].include? 'linux'
end

.are_we_on_windows?Boolean

#

BackupParadise.are_we_on_windows?

Query whether the underlying operating system is windows or whether it is not.

#

Returns:

  • (Boolean)


51
52
53
# File 'lib/backup_paradise/toplevel_methods/misc.rb', line 51

def self.are_we_on_windows?
  Gem.win_platform?
end

.backup_these_directories?Boolean

#

BackupParadise.backup_these_directories?

#

Returns:

  • (Boolean)


78
79
80
81
82
83
84
# File 'lib/backup_paradise/toplevel_methods/config.rb', line 78

def self.backup_these_directories?
  if CONFIG.has_key?('backup_these_directories')
    return CONFIG['backup_these_directories']
  else
    return []
  end
end

.change_directory(i) ⇒ Object

#

BackupParadise.change_directory (cd tag, chdir tag)

This should no longer be required.

#


147
148
149
# File 'lib/backup_paradise/toplevel_methods/files_and_directories.rb', line 147

def self.change_directory(i)
  Dir.chdir(i) if i and File.directory?(i)
end

.clinerObject

#

BackupParadise.cliner

#


12
13
14
# File 'lib/backup_paradise/toplevel_methods/cliner.rb', line 12

def self.cliner
  puts '=' * 80
end

.config?Boolean

#

BackupParadise.config?

Toplevel query method over the config-hash.

#

Returns:

  • (Boolean)


31
32
33
# File 'lib/backup_paradise/toplevel_methods/config.rb', line 31

def self.config?
  CONFIG
end

.copy_file(file, where_to) ⇒ Object

#

BackupParadise.copy_file

Copy a file with this method consistently.

#


156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/backup_paradise/toplevel_methods/files_and_directories.rb', line 156

def self.copy_file(file, where_to)
  begin
    FileUtils.cp(file, where_to)
  rescue Errno::ENOSPC # Not enough space on target device.
    opnn; e 'We must exit now - there is not enough space left on the '
    opnn; e 'target hdd.'
  rescue Errno::EINVAL # Invalid argument @ rb_sysopen
    opnn; e 'The file can not be copied, possibly because it '\
            'contains a german umlaut.'
    opnn; e 'We will however continue nonetheless.'
  rescue Errno::EISDIR
    opnn; e 'We currently do not copy directories, only files.'
  rescue Errno::EILSEQ => error
    opnn; e "It seems that we have an invalid or incomplete multibyte "\
            "or wide-character at file `#{sfile(file.to_s)}`."
    opnn; e 'We thus can not copy this file.'
    pp error
  rescue Exception => error # In lucky days, we will never reach this here.
    pp error
    opnn; e 'The above error should be intercepted - please add it,'
    opnn; e 'then press the ENTER key in order to continue.'
    $stdin.gets.chomp # We will remove this line here eventually.
  end
end

.copy_recursively(this_directory, backup_to_this_target, be_verbose = :be_verbose) ⇒ Object

#

BackupParadise.copy_recursively

This method can be used to copy the source to the target in a recursive manner.

The third argument to this method, called ‘be_verbose`, will feedback what is done, to the user, if it has a value of true. Symbols such as :be_verbose can be used as an “alias” to true. If it is set to false, or :be_silent, then no output will be issued to the user.

#


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/backup_paradise/toplevel_methods/files_and_directories.rb', line 29

def self.copy_recursively(
    this_directory,        # from (also called source)
    backup_to_this_target, # to   (also called target)
    be_verbose = :be_verbose
  )
  this_directory = this_directory.dup if this_directory.frozen?
  if this_directory.include? '*'
    require 'convert_global_env'
    this_directory = ConvertGlobalEnv[this_directory].dup
  end
  this_directory        = rds(this_directory)
  backup_to_this_target = rds(backup_to_this_target)
  use_system_cp = use_system_cp?
  case be_verbose
  when :be_verbose
    be_verbose = true
  end
  begin
    raw_file_check = this_directory.dup.delete('*') # No '*' here.
    if File.directory?(raw_file_check)
      if use_system_cp
        # ================================================================= #
        # In that case we will simply use system cp.
        # ================================================================= #
        esystem "cp --recursive --verbose #{this_directory} #{backup_to_this_target}" 
      else
        FileUtils.cp_r(
          this_directory,
          backup_to_this_target,
          verbose: be_verbose
        )
      end
    else
      e 'No directory exists at the path '+sdir(this_directory)+'.'
    end
  rescue Exception => error
    opnn; e 'An error occurred in the method '+
            __method__.to_s+'(): '+error.class.to_s
    pp error
  end
end

.create_directory(i, mode = DEFAULT_MODE) ⇒ Object

#

BackupParadise.create_directory

Dir.mkdir would be an alternative. We require DEFAULT_MODE to be set before we can use this method here - hence why we require the file constants.rb.

#


104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/backup_paradise/toplevel_methods/files_and_directories.rb', line 104

def self.create_directory(
    i, mode = DEFAULT_MODE
  )
  mode = DEFAULT_MODE if mode.nil?
  if i.count('/') > 1
    # ===================================================================== #
    # We delegate towards FileUtils.mkdir_p() next, but we have to be
    # careful - there may be no space left on the external device, so
    # we have to rescue this situation.
    # ===================================================================== #
    begin
      FileUtils.mkdir_p(i) unless Dir.exist? i
      return true
    rescue Errno::ENOSPC => error
      opnn; e 'It appears to be the case that there is no space left on'
      opnn; e 'the target device.'
      pp error # And show the exact error as well.
    end
  else
    unless File.directory? i
      Dir.mkdir(i, mode)
      return true # Return true just in case we ever need this information.
    end
  end
  false
end

.e(i = '') ⇒ Object

#

BackupParadise.e

#


12
13
14
# File 'lib/backup_paradise/toplevel_methods/e.rb', line 12

def self.e(i = '')
  puts i
end

.esystem(i = '') ⇒ Object

#

BackupParadise.esystem

#


14
15
16
17
# File 'lib/backup_paradise/toplevel_methods/esystem.rb', line 14

def self.esystem(i = '')
  e i
  system i
end

.file_config_yamlObject

#

BackupParadise.file_config_yaml

This method will return the proper path to the config.yml file in use.

#


35
36
37
# File 'lib/backup_paradise/project/project.rb', line 35

def self.file_config_yaml
  "#{BackupParadise.project_yaml_dir?}config.yml"
end

.is_on_roebe?Boolean

#

BackupParadise.is_on_roebe?

#

Returns:

  • (Boolean)


149
150
151
# File 'lib/backup_paradise/toplevel_methods/misc.rb', line 149

def self.is_on_roebe?
  ENV['IS_ROEBE'].to_s == '1'
end

.is_this_a_shortcut?(i) ⇒ Boolean

#

BackupParadise.is_this_a_shortcut?

#

Returns:

  • (Boolean)


20
21
22
23
24
25
26
# File 'lib/backup_paradise/toplevel_methods/mountpoint.rb', line 20

def self.is_this_a_shortcut?(i)
  returned_value = return_the_assumed_mountpoint_from_this_input(i)
  # ======================================================================= #
  # It is a shortcut when we have replaced it.
  # ======================================================================= #
  !(returned_value == i)
end

.opnn(i = { namespace: NAMESPACE }) ⇒ Object

#

BackupParadise.opnn

#


16
17
18
19
20
21
22
23
24
25
# File 'lib/backup_paradise/toplevel_methods/opnn.rb', line 16

def self.opnn(
    i = {
      namespace: NAMESPACE
    }
  )
  if i.is_a? String
    i = { namespace: i }
  end
  Opn.opn(i)
end

.project_base_dir?Boolean

#

BackupParadise.project_base_dir?

#

Returns:

  • (Boolean)


18
19
20
# File 'lib/backup_paradise/project/project.rb', line 18

def self.project_base_dir?
  BackupParadise::PROJECT_BASE_DIRECTORY
end

.project_yaml_dir?Boolean

#

BackupParadise.project_yaml_dir?

#

Returns:

  • (Boolean)


25
26
27
# File 'lib/backup_paradise/project/project.rb', line 25

def self.project_yaml_dir?
  "#{BackupParadise::PROJECT_BASE_DIRECTORY}yaml/"
end

.rds(i) ⇒ Object

#

BackupParadise.rds

#


142
143
144
# File 'lib/backup_paradise/toplevel_methods/misc.rb', line 142

def self.rds(i)
  i.to_s.squeeze '/'
end

.remove(i) ⇒ Object

#

BackupParadise.remove

Easier wrapper when we need to remove something, be it a directory or a file or a symlink.

#


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/backup_paradise/toplevel_methods/create_and_remove.rb', line 39

def self.remove(i)
  if i.is_a? Array
    i.each {|entry| remove(entry) }
  else
    i = rds(i)
    _ = i.dup
    if File.directory? i
      _ = sdir(i)
    elsif File.file?(i)
      _ = sfile(i)
    else # else it will just be fancy.
      _ = sfancy(i)
    end
    e "Trying to remove `#{_}` next."
    if File.directory?(i)
      remove_directory(i)
    elsif File.file?(i)
      remove_this_file(i) # Defined in this file here.
    else
      e 'Not found the action: "'+sfancy(i)+'"'
    end
  end
end

.remove_directory(i) ⇒ Object

#

BackupParadise.remove_directory

#


16
17
18
19
20
21
# File 'lib/backup_paradise/toplevel_methods/create_and_remove.rb', line 16

def self.remove_directory(i)
  i = rds(i).strip
  unless i == '/' # Tiny "safeguard".
    FileUtils.rm_rf(i) if File.directory?(i)
  end
end

.remove_this_file(this_file) ⇒ Object

#

BackupParadise.remove_this_file

Use this method to remove a file.

#


28
29
30
31
# File 'lib/backup_paradise/toplevel_methods/create_and_remove.rb', line 28

def self.remove_this_file(this_file)
  e "Removing the file `#{sfile(this_file)}` now."
  FileUtils.rm(this_file)
end

.report_current_dirObject

#

report_current_dir

This method will tell us about the current directory.

#


19
20
21
# File 'lib/backup_paradise/toplevel_methods/misc.rb', line 19

def self.report_current_dir
  e "Current location is: #{sdir(Dir.pwd)}"
end

.return_the_assumed_mountpoint_from_this_input(i) ⇒ Object

#

BackupParadise.return_the_assumed_mountpoint_from_this_input

This method will replace e. g. “usb1” with ENV or the config-setting. The config setting takes priority over the ENV setting.

#


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/backup_paradise/toplevel_methods/mountpoint.rb', line 35

def self.return_the_assumed_mountpoint_from_this_input(i)
  case i # case tag
  # ======================================================================= #
  # === :pwd
  # ======================================================================= #
  when 'pwd',
       :pwd,
       :""
    i = Dir.pwd
  # ======================================================================= #
  # === :usb1
  #
  # Note that nil also defaults to :usb1.
  # ======================================================================= #
  when :usb1,
       :default,
       'usb1',
       'usb',
       'tousb',
       /^-?-?to(-|_)?usb1/,
       '1',
       /^-?-?usb1/,
       nil
    if CONFIG and CONFIG.has_key?('usb1')
      i = CONFIG['usb1'].to_s
    else
      i = ENV['USB1']
    end
  # ======================================================================= #
  # === :usb2
  # ======================================================================= #
  when :usb2,
       'usb2',
       /^-?-?to(-|_)?usb2/,
       '2',
       /^-?-?usb2/
    if CONFIG and CONFIG.has_key?('usb2')
      i = CONFIG['usb2'].to_s
    else
      i = ENV['USB2']
    end
  # ======================================================================= #
  # === :usb3
  # ======================================================================= #
  when '3',
       /^-?-?usb3/,
       /^-?-?to(-|_)?usb3/,
       :usb3
    if CONFIG and CONFIG.has_key?('usb3')
      i = CONFIG['usb3'].to_s
    else
      i = ENV['USB3']
    end
  # ======================================================================= #
  # === :usb4
  # ======================================================================= #
  when '4',
       :usb4,
       /^-?-?usb4/,
       /^-?-?to(-|_)?usb4/
    if CONFIG and CONFIG.has_key?('usb4')
      i = CONFIG['usb4'].to_s
    else
      i = ENV['USB4']
    end
  # ======================================================================= #
  # === :usb5
  # ======================================================================= #
  when 'usb5',
       /^-?-?usb5/,
       /^-?-?to(-|_)?usb5/,
       '5',
       :usb5
    if CONFIG and CONFIG.has_key?('usb5')
      i = CONFIG['usb5'].to_s
    else
      i = ENV['USB5']
    end
  # ======================================================================= #
  # === :chroot
  # ======================================================================= #
  when :chroot,
       'chroot'
    i = ENV['CHROOT_TARGET']
    if i.nil?
      i = '/Depot/Chroot/' # Hardcoded target in this case.
    end
  # ======================================================================= #
  # === :to_hdd
  # ======================================================================= #
  when 'tohd',
       'hdd1',
       :to_hdd,
       /^-?-?to(-|_)?hdd1?/i
    i = BackupParadise.config?['hdd1'] # ENV['FESTPLATTE1'].to_s.dup
  # ======================================================================= #
  # === :to_hdd2
  # ======================================================================= #
  when 'hdd2',
       :to_hdd2,
       /^-?-?to(-|_)?hdd2/i
    i = BackupParadise.config?['hdd2'] # ENV['FESTPLATTE1'].to_s.dup
  end
  # ======================================================================= #
  # The input could still be a Symbol, so the next line exists to protect
  # us against this.
  # ======================================================================= #
  i = i.to_s unless i.is_a?(String)
  if i and File.directory?(i) and !i.end_with?('/')
    i = i.dup if i.frozen?
    i << '/' # Ensure a trailing '/'.
  end
  return i # Always return it.
end

.royalblue(i = '') ⇒ Object

#

BackupParadise.royalblue

#


67
68
69
70
# File 'lib/backup_paradise/colours/colours.rb', line 67

def self.royalblue(i = '')
  return Colours.royalblue(i) if @use_colours
  return i
end

.sdir(i = '') ⇒ Object

#

BackupParadise.sdir

#


43
44
45
46
# File 'lib/backup_paradise/colours/colours.rb', line 43

def self.sdir(i = '')
  return Colours.sdir(i) if @use_colours
  return i
end

.sfancy(i = '') ⇒ Object

#

BackupParadise.sfancy

#


35
36
37
38
# File 'lib/backup_paradise/colours/colours.rb', line 35

def self.sfancy(i = '')
  return Colours.sfancy(i) if @use_colours
  return i
end

.sfile(i = '') ⇒ Object

#

BackupParadise.sfile

#


51
52
53
54
# File 'lib/backup_paradise/colours/colours.rb', line 51

def self.sfile(i = '')
  return Colours.sfile(i) if @use_colours
  return i
end

.show_helpObject

#

BackupParadise.show_help (help tag)

Here we register all help-related methods.

Two hints are registered, “tohdd”, and “no-gtk”. To use this, do: Help.show_help

Or, from the commandline:

rbackup --help
#


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/backup_paradise/toplevel_methods/help.rb', line 25

def self.show_help
  e
  cliner
  e ::Colours.rev+
    '  - Please note that you can use any order for the arguments.'
  e
  e 'Documented help options are:'
  e
  e '  rbackup --programs-dir    # Back up the /Programs/ directory quickly'
  e '  rbackup --backup-to=/PATH # Back up into the PATH directory.'
  e
  e 'The following options are NOT yet tested!'
  e
  e "  - Pass #{sfancy('tohdd')} to backup to the hdd (usually "\
    "this is the second harddisc)."
  e
  e '  - Pass '+sfancy('tousb ')+'to backup to the (first) usb media.'
  e '    (Aliases exist, such as '+sfancy('usb1')+sfancy(' usb2')+
    sfancy(' usb3')+' and so forth)'
  e
  e '  - Pass '+sfancy('data_only ')+'to backup only the '+
    sdir(HOME_DIRECTORY_OF_THE_USER_X+'DATA/')+' directory.'
  e
  e '  - In general you can backup individual directories as well.'
  e
  e '    Examples for this functionality:'
  e
  e sfancy('      rbackup audio')
  e sfancy('      rbackup data')
  e
  e '  - You can also chain together commands.'
  e
  e '    Example for chaining together commands:'
  e
  e sfancy('      rbackup data_only usb1')
  e sfancy('      rbackup audio_only usb1')
  e
  e '  - You can backup the /Programs directory.'
  e
  e '    Issue the following command here:'
  e
  e sfancy('      rbackup usb1 programs')
  e sfancy('      rbackup usb1 /Programs')
  e
  e '  - If you do the following.'
  e '    Examples:'
  e sfancy('      rbackup no-mount1')
  e '    Then we wont try to (re)mount the device again.'
  e
  e 'If you want to show the time it took to backup the last some'
  e 'backup-jobs, use this commandline flag:'
  e
  e sfancy('  rbackup --logfile')
  e
  e 'To simply backup into the current working '\
    'directory (cwd, pwd)'
  e 'use:'
  e
  e sfancy('  rbackup --pwd')
  e
  e 'To use the GTK3 GUI, you could try:'
  e
  e sfancy('  rbackup --gui')
  e
  cliner
  e
end

.show_popup_notification?Boolean

#

BackupParadise.show_popup_notification?

#

Returns:

  • (Boolean)


63
64
65
66
67
68
69
70
71
72
73
# File 'lib/backup_paradise/toplevel_methods/config.rb', line 63

def self.show_popup_notification?
  if CONFIG.has_key?('show_popup_notification')
    if (CONFIG['show_popup_notification'] == true)
      return true
    else
      return false
    end
  else
    return true
  end
end

.simp(i = '') ⇒ Object

#

BackupParadise.simp

#


59
60
61
62
# File 'lib/backup_paradise/colours/colours.rb', line 59

def self.simp(i = '')
  return Colours.simp(i) if @use_colours
  return i
end

.simple_backup(this_directory_or_file = '/home/x/songs/', target_location = '/Mount/USB1/', be_verbose = true) ⇒ Object

#

BackupParadise.simple_backup

Use this toplevel-method to backup something individually. This will deliberately NOT make use of class BackupParadise::Backup, to keep things as simple as possible in this regard.

To invoke this method, try any of the following:

BackupParadise.simple_backup(:audio, '/Mount/HDD1/')
BackupParadise.simple_backup(:audio_dir, '/Mount/HDD1/')
BackupParadise.simple_backup(:system_dir, '/Mount/HDD1/')
BackupParadise.simple_backup(:audio, :usb1)
#


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/backup_paradise/toplevel_methods/misc.rb', line 77

def self.simple_backup(
    this_directory_or_file = '/home/x/songs/',
    target_location        = '/Mount/USB1/', # '/Mount/HDD1/',
    be_verbose             = true
  )
  if this_directory_or_file.is_a? Array
    this_directory_or_file.each {|entry|
      Backup.simple_backup(entry, target_location, be_verbose)
    }
  else
    # ===================================================================== #
    # First, handle some special Symbols. This must come before rds().
    # ===================================================================== #
    case this_directory_or_file
    # ===================================================================== #
    # === :audio
    # ===================================================================== #
    when :audio,
         :audio_dir, :songs, :songs_dir, :default,
         :audio_directory
      this_directory_or_file = DIRECTORY_CONTAINING_ALL_SONGS
    # ===================================================================== #
    # === :pkg_dir
    # ===================================================================== #
    when :pkg_dir
      this_directory_or_file = '/Depot/Packages/'
    # ===================================================================== #
    # === :system_dir
    # ===================================================================== #
    when :system_dir, :sys_dir
      this_directory_or_file = '/System/'
    end
    this_directory_or_file = rds(this_directory_or_file)
    if target_location.is_a? Symbol
      # =================================================================== #
      # Symbols are treated in a special manner.
      # =================================================================== #
      if BackupParadise.is_this_a_shortcut?(target_location.to_s)
        target_location =
          BackupParadise.return_the_assumed_mountpoint_from_this_input(target_location.to_s)
      end
    end
    this_directory_or_file = this_directory_or_file.dup if this_directory_or_file.frozen?
    if this_directory_or_file.end_with?('/.')
      # =================================================================== #
      # The next line was added because it was noticed that windows, for
      # some odd reason, may append a '.' character to a directory.
      # =================================================================== #
      this_directory_or_file.chop! # Remove the last char, which is '.' in this case.
    end
    target_location = target_location.to_s
    e "Now backing up directory `#{sdir(this_directory_or_file)}"\
      "` to `#{sdir(target_location)}`."
    cpr(
      this_directory_or_file,
      target_location,
      be_verbose
    )
    tab_title 'Backing up now ...' unless are_we_on_windows?
  end
end

.size?(subdir_part) ⇒ Boolean

#

BackupParadise.size?

Gives you the size of the given subdirectory.

Usage Example:

BackupParadise.size?(ENV['J']) # => 1_396_436_232
BackupParadise.size?(BackupParadise::AUDIO_DIR) # => 1_396_436_232
#

Returns:

  • (Boolean)


83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/backup_paradise/toplevel_methods/files_and_directories.rb', line 83

def self.size?(subdir_part)
  size = 0 # Default.
  begin
    subdir_part = "#{subdir_part}/**/*"
    results = Dir[subdir_part]
    size = results.inject(0) { |sum, entry|
      result = 0
      result = sum + File.size(entry) if File.exist? entry
      result
    }
  rescue; end # Make it failsave.
  return size.to_s
end

.size_in_gigabytes?(i = BackupParadise::AUDIO_DIR) ⇒ Boolean

#

BackupParadise.size_in_gigabytes?

This method will return the size of the target directory in gigabytes.

#

Returns:

  • (Boolean)


136
137
138
139
140
# File 'lib/backup_paradise/toplevel_methods/files_and_directories.rb', line 136

def self.size_in_gigabytes?(i = BackupParadise::AUDIO_DIR)
  (
    BackupParadise.size?(i).to_f / 1024.0 / 1024.0 / 1000.0
  ).round(1).to_f
end

.steelblue(i = '') ⇒ Object

#

BackupParadise.steelblue

#


83
84
85
86
# File 'lib/backup_paradise/colours/colours.rb', line 83

def self.steelblue(i = '')
  return Colours.steelblue(i) if @use_colours
  return i
end

.tab_title(use_this_title = '') ⇒ Object

#

BackupParadise.tab_title

#


39
40
41
42
43
# File 'lib/backup_paradise/toplevel_methods/misc.rb', line 39

def self.tab_title(
    use_this_title = ''
  )
  BackupParadise::Tab.rename_tab(:default, use_this_title)
end

.target_mountpoint=(i = :usb1) ⇒ Object

#

BackupParadise.target_mountpoint= (target tag)

Use this method to determine the main target mountpoint that is to be used. This must be the base directory, not a subdirectory.

An example for this, on my home system, would be /Mount/USB1/.

#


158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/backup_paradise/toplevel_methods/mountpoint.rb', line 158

def self.target_mountpoint=(i = :usb1)
  if i.is_a? String
    i = i.dup if i.frozen?
    i.squeeze!('/')
  end
  if BackupParadise.is_this_a_shortcut?(i)
    i = return_the_assumed_mountpoint_from_this_input(i)
  end
  # ======================================================================= #
  # Ensure that a trailing '/' is used.
  # ======================================================================= #
  unless i.end_with? '/'
    i = i.dup if i.frozen?
    i << '/'
  end
  @target_mountpoint = i
end

.target_mountpoint?Boolean

#

BackupParadise.target_mountpoint?

#

Returns:

  • (Boolean)


184
185
186
# File 'lib/backup_paradise/toplevel_methods/mountpoint.rb', line 184

def self.target_mountpoint?
  @target_mountpoint
end

.tomato(i = '') ⇒ Object

#

BackupParadise.tomato

#


75
76
77
78
# File 'lib/backup_paradise/colours/colours.rb', line 75

def self.tomato(i = '')
  return Colours.tomato(i) if @use_colours
  return i
end

.use_colours=(i) ⇒ Object

#

BackupParadise.use_colours=

#


28
29
30
# File 'lib/backup_paradise/colours/colours.rb', line 28

def self.use_colours=(i)
  @use_colours = i
end

.use_colours?Boolean

#

BackupParadise.use_colours?

#

Returns:

  • (Boolean)


21
22
23
# File 'lib/backup_paradise/colours/colours.rb', line 21

def self.use_colours?
  @use_colours
end

.use_system_cp?Boolean

#

BackupParadise.use_system_cp?

#

Returns:

  • (Boolean)


52
53
54
55
56
57
58
# File 'lib/backup_paradise/toplevel_methods/config.rb', line 52

def self.use_system_cp?
  if CONFIG.has_key?('use_system_cp')
    return CONFIG['use_system_cp']
  else
    return true
  end
end

.use_this_program_to_rename_tabs?Boolean

#

BackupParadise.use_this_program_to_rename_tabs?

#

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
46
47
# File 'lib/backup_paradise/toplevel_methods/config.rb', line 38

def self.use_this_program_to_rename_tabs?
  if CONFIG.has_key?('use_this_program_to_rename_tabs')
    # ===================================================================== #
    # Obtain the program that we will use for renaming the tab.
    # ===================================================================== #
    CONFIG['use_this_program_to_rename_tabs'].to_sym
  else
    :konsole # Default.
  end
end

Instance Method Details

#debugObject

#

debug (debug tag)

This is just “quick” debug output.

#


29
30
31
32
33
34
# File 'lib/backup_paradise/toplevel_methods/misc.rb', line 29

def debug
  e
  e '  Data directory: '+sfancy(data_directory?)
  e "  Main mount point: #{sfancy(mount_point?.to_s)}"
  e
end