backup_paradise 1.2.13

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of backup_paradise might be problematic. Click here for more details.

Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +231 -0
  3. data/backup_paradise.gemspec +51 -0
  4. data/bin/backup_paradise +7 -0
  5. data/doc/README.gen +214 -0
  6. data/doc/TODO.md +221 -0
  7. data/lib/backup_paradise.rb +5 -0
  8. data/lib/backup_paradise/advanced_backup/advanced_backup.rb +53 -0
  9. data/lib/backup_paradise/advanced_backup/audio.rb +124 -0
  10. data/lib/backup_paradise/advanced_backup/constants.rb +34 -0
  11. data/lib/backup_paradise/advanced_backup/data_directory.rb +50 -0
  12. data/lib/backup_paradise/advanced_backup/do_perform_the_backup_tasks.rb +95 -0
  13. data/lib/backup_paradise/advanced_backup/initialize.rb +38 -0
  14. data/lib/backup_paradise/advanced_backup/menu.rb +280 -0
  15. data/lib/backup_paradise/advanced_backup/misc.rb +836 -0
  16. data/lib/backup_paradise/advanced_backup/reset.rb +56 -0
  17. data/lib/backup_paradise/advanced_backup/run.rb +26 -0
  18. data/lib/backup_paradise/advanced_backup/system_directory.rb +35 -0
  19. data/lib/backup_paradise/base/base.rb +440 -0
  20. data/lib/backup_paradise/base/colours.rb +123 -0
  21. data/lib/backup_paradise/base/constants.rb +16 -0
  22. data/lib/backup_paradise/constants/constants.rb +192 -0
  23. data/lib/backup_paradise/gui/gtk2/backup.rb +345 -0
  24. data/lib/backup_paradise/gui/gtk3/backup.rb +383 -0
  25. data/lib/backup_paradise/project/project_base_directory.rb +22 -0
  26. data/lib/backup_paradise/requires/require_the_backup_paradise_project.rb +14 -0
  27. data/lib/backup_paradise/tab/tab.rb +84 -0
  28. data/lib/backup_paradise/toplevel_methods/cliner.rb +16 -0
  29. data/lib/backup_paradise/toplevel_methods/colours.rb +80 -0
  30. data/lib/backup_paradise/toplevel_methods/e.rb +16 -0
  31. data/lib/backup_paradise/toplevel_methods/help.rb +88 -0
  32. data/lib/backup_paradise/toplevel_methods/misc.rb +343 -0
  33. data/lib/backup_paradise/toplevel_methods/mountpoint.rb +80 -0
  34. data/lib/backup_paradise/toplevel_methods/opnn.rb +21 -0
  35. data/lib/backup_paradise/version/version.rb +19 -0
  36. data/lib/backup_paradise/yaml/config.yml +22 -0
  37. metadata +178 -0
data/doc/TODO.md ADDED
@@ -0,0 +1,221 @@
1
+ ...........................................................................
2
+
3
+ - AdvancedBackup won't have GTK code. But we will still
4
+ maintain the GTK Bindings somewhere.
5
+
6
+ bl $RUBY_GTK/TOOLS/gtk2_backup_wrapper.rb
7
+
8
+ Ok, we do this as part of the backup project since Nov 2013.
9
+ Also document this!
10
+
11
+ ...........................................................................
12
+ - If log_last_backup already exists AND also
13
+ last_backup exists, then we automatically rename.
14
+ Then we can continue.
15
+
16
+ ...........................................................................
17
+
18
+ - Test this project on windows as well. If it works there,
19
+ we can eliminate this point.
20
+
21
+ ...........................................................................
22
+ - Consider allowing the following:
23
+
24
+ backup :audio_dir, :pkg_dir, :system_dir
25
+
26
+ And multiple arguments.
27
+
28
+ attr_writer :target_device
29
+
30
+ def initialize(show_info = true, invoke_dcop = true)
31
+ e N+'Init Backup to Second HDD or external USB Device now.' if show_info
32
+ @target_device = ENV['USB1'] # stores for example /Mount/USB1
33
+ @mount_to = @target_device.dup # isnt that the same?
34
+ # Is default
35
+ @dir_name = 'last_backup' # will contain name of our dir to create
36
+ @which_device_entry = '' # zb /dev/sda1
37
+ end
38
+
39
+ # ========================================================================= #
40
+ # === report_and_mount_to
41
+ #
42
+ # Wrapper. What to do if there are multiple device entries found? Then
43
+ # we use the last one. @mount_to tells us where to mount our partition.
44
+ # ========================================================================= #
45
+ def report_and_mount_to(number, usb_device)
46
+ @which_device_entry = usb_device
47
+ @mount_to = ENV['USB'+number]
48
+ e "Found usb#{number} string pointing to "+
49
+ "#{@which_device_entry} -> #{@mount_to}",CI
50
+ end
51
+
52
+ # ========================================================================= #
53
+ # === decide_what_and_where_to_mount
54
+ # rbackup no-mount
55
+ # dann wird nit gemounted.
56
+ # Expects two arguments. The second argument is the check for a
57
+ # case menu. The first specifies where to mount it.
58
+ # ========================================================================= #
59
+ def decide_what_and_where_to_mount(mount_to = @mount_to, case_argument = '')
60
+ mount_to = @mount_to if mount_to.nil? # safe check
61
+ case case_argument
62
+ when 'no-mount','nomount' # passthru
63
+
64
+ e 'Backing up to '+mount_to,CFANCY
65
+ e 'Set new target to '+mount_to, CII
66
+ @target_device = mount_to
67
+ else # default, will mount to USB entry.
68
+ e "Mounting to #{mount_to}",CII
69
+ mount_device(mount_to)
70
+ end
71
+ end
72
+
73
+ # ========================================================================= #
74
+ # === mount_device
75
+ #
76
+ # Normal usage is to call this from:
77
+ # scan_for_usb_entries
78
+ # ========================================================================= #
79
+ def mount_device(which_one = ENV['USB1'])
80
+ @target_device = which_one
81
+ e "Now mounting device #{@which_device_entry} "+
82
+ "to #{@target_device}", CII
83
+ tmp = "mount #{@which_device_entry} #{@target_device}"
84
+ system(tmp)
85
+ @date # zeigt einfach nur das aktuelle datum an
86
+ end
87
+
88
+ # ========================================================================= #
89
+ # === pre_backup_process
90
+ # This method is invoked at start of backup_system()
91
+ # What is this method doing?
92
+ # It does these things in the following order:
93
+ # (a) renames last_backup dir to backup_DAY.MONTH.YEAR
94
+ # (b) Deletes log_last_backup file (which contains time of last update)
95
+ # (c) Deletes already existing backup dirs before it continues.
96
+ # (d) Creates directories.
97
+ #
98
+ # base_dir signifies the absolute target.
99
+ # You are in /Mount/USB1 when this method is started.
100
+ # ========================================================================= #
101
+ def pre_backup_process(base_dir = @target_device)
102
+ # rename last_backup if it exists
103
+ if File.exist? base_dir+'/log_last_backup_'+@date
104
+ _ = File.read(base_dir+'/log_last_backup_'+@date).chomp # _ is nun zb "05.11.2007"
105
+ # What if it already exists? Then we delete the old file first.
106
+ # We will NOT do this silently!
107
+ to_rename = base_dir+'/'+@dir_name
108
+ to_new_rename = base_dir+'/backup_'+_
109
+ string = 'Renaming '+to_rename+' to '+to_new_rename
110
+ e N+string,CII
111
+ puts
112
+ # must begin/rescue it because it could be read-only file system
113
+ if File.exist? to_rename
114
+ File.rename(to_rename, to_new_rename) # old_name, new_name
115
+ else
116
+ e to_rename+' does not exist.', CWARN
117
+ end
118
+ # rescue Exception => e
119
+ # e 'Exception occured!!! '+e, CWARN
120
+ else # puts 'DOES NOT EXIST!!! '+Dir.pwd
121
+ end
122
+ if File.exist? base_dir+'/log_last_backup_'+@date
123
+ e 'We delete the file: '+base_dir+'/log_last_backup_'+@date,CWARN
124
+ remove(base_dir+'/log_last_backup_'+@date)
125
+ end
126
+ e "Changing into this dir: #{_}"
127
+ change_directory(_)
128
+ write_last_backup
129
+ end
130
+
131
+ # ========================================================================= #
132
+ # === backup_system
133
+ #
134
+ # backup_system() to backup your system. This method is the actual working
135
+ # dog of this script. It accepts one main argument, a symbol, which
136
+ # defaults to nogtk to avoid using gtk, and which also can use tohdd
137
+ # to only backup to my (2nd) harddrive.
138
+ #
139
+ # The mode argument should be either one of these:
140
+ # :nogtk
141
+ # :tohdd
142
+ # :tousb
143
+ # :data_only # this also assumes :tousb
144
+ # ========================================================================= #
145
+ def backup_system(mode = :nogtk, sleep_for_this_time = 0)
146
+ pre_backup_process() # all processes before starting backuping
147
+ # Now splitting towards mode content
148
+ case mode.to_sym
149
+ # dont use gtk
150
+ when :nogtk
151
+ report_backup_process_to('USB device')
152
+ my_sys_cmd = 'cp -vr /Users/x/* .'
153
+ sys(my_sys_cmd)
154
+ synchronize
155
+
156
+ # Because my hdd is so slow, we nice the process
157
+ # on -19. Not very important.
158
+ when :tohdd, :festplatte, :hdd
159
+ report_backup_process_to('second HDD')
160
+ my_sys_cmd='nice -19 cp -vr /Users/x/* .'
161
+ e(my_sys_cmd)
162
+ sleep(sleep_for_this_time) # sleeping so that user gets a chance to view the command.
163
+ sys(my_sys_cmd)
164
+ backup :audio_dir, :pkg_dir, :system_dir
165
+ when :data_only, :dataonly, :data, :donly, :onlydata
166
+ report_backup_process_to('Data only (default into USB)')
167
+ my_sys_cmd='nice -19 cp -vr /Users/x/DATA/* .'
168
+ e(my_sys_cmd)
169
+ sleep(sleep_for_this_time) # sleeping so that user gets a chance to view the command.
170
+ sys(my_sys_cmd)
171
+ # tousb backup
172
+ when :tousb, :tousb1, :tousb2, :tousb3, :tousb4
173
+ report_backup_process_to('USB Removable media')
174
+ my_sys_cmd = 'nice -19 cp -vr /Users/x/* .'
175
+ e(my_sys_cmd)
176
+ sleep(sleep_for_this_time) # sleeping so that user gets a chance to view the command.
177
+ pp Dir['*']
178
+ sys(my_sys_cmd)
179
+ backup :audio_dir, :pkg_dir, :system_dir
180
+ synchronize # must sync
181
+ # else. Nah, there are no "unhandled cases".
182
+ end
183
+ end
184
+
185
+ # ========================================================================= #
186
+ # === change_to_device_and_start_backup
187
+ #
188
+ # Here we change to the Mount point in question.
189
+ # Also, this method invokes backup_system, which does the
190
+ # actual backup. Thus you must first ensure that you are in the
191
+ # correct base directory, before invoking backup_system.
192
+ # ========================================================================= #
193
+ def change_to_device_and_start_backup(which_mode = @array_argv[0])
194
+ if Dir.pwd.include? ENV['MY_MOUNT']
195
+ # Prepend the string 'backup_'
196
+ @dir_name = 'last_backup' # name for our backup dir. Normally sets to: last_backup
197
+ # which_mode decides what to do. default is in else
198
+ # The second arg to backup_system means sleep_for_n_seconds
199
+ case which_mode.to_s
200
+ when 'no-gtk','nogtk'
201
+ backup_system()
202
+ when 'to-hdd','tohdd','tohdd1'
203
+ backup_system(:tohdd, 2)
204
+ unmount :hdd # since 17.06.2008 we unmount the hdd too
205
+ when 'tousb','tousb1','1'
206
+ backup_system(:tousb1, 2)
207
+ when 'tousb2','2'
208
+ backup_system(:tousb2, 2)
209
+ when 'tousb3','usb3','3'
210
+ backup_system(:tousb3, 2)
211
+ when 'data_only', 'dataonly', 'data', 'donly', 'onlydata'
212
+ backup_system(:data_only, 2)
213
+ end
214
+ end
215
+ end
216
+
217
+ USB_ENTRY = RBackup::ENV['MOUNT'] # or '/mnt' ?
218
+ e "\n"+'Running standalone.'+"\n", StdColours::CWARN
219
+ _ = RBackup.new
220
+ _.scan_for_usb_entries
221
+ _.change_to_device_and_start_backup # also invokes backup_system
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'backup_paradise/requires/require_the_backup_paradise_project.rb'
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === BackupParadise::AdvancedBackup
6
+ #
7
+ # This is the main class that will be used for making a backup, usually
8
+ # onto an external USB device, but optionally also to another (second)
9
+ # harddisc (HDD).
10
+ #
11
+ # Note that we will still store some information on the toplevel namespace
12
+ # where we will backup to.
13
+ #
14
+ # For a listing of specifict options have a look at the file "help.rb", or
15
+ # do "rbackup help" from the commandline.
16
+ #
17
+ # This class will backup a system, usually on an external USB device.
18
+ #
19
+ # Usage examples:
20
+ #
21
+ # BackupParadise::AdvancedBackup.new(ARGV)
22
+ #
23
+ # =========================================================================== #
24
+ # require 'backup_paradise/advanced_backup/advanced_backup.rb'
25
+ # =========================================================================== #
26
+ require 'backup_paradise/toplevel_methods/colours.rb'
27
+ require 'backup_paradise/toplevel_methods/help.rb'
28
+ require 'backup_paradise/base/base.rb'
29
+ # =========================================================================== #
30
+ # Next, require .rb files that are specific to class AdvancedBackup.
31
+ # =========================================================================== #
32
+ require 'backup_paradise/advanced_backup/audio.rb'
33
+ require 'backup_paradise/advanced_backup/constants.rb'
34
+ require 'backup_paradise/advanced_backup/data_directory.rb'
35
+ require 'backup_paradise/advanced_backup/do_perform_the_backup_tasks.rb'
36
+ require 'backup_paradise/advanced_backup/misc.rb'
37
+ require 'backup_paradise/advanced_backup/initialize.rb'
38
+ require 'backup_paradise/advanced_backup/menu.rb'
39
+ require 'backup_paradise/advanced_backup/reset.rb'
40
+ require 'backup_paradise/advanced_backup/run.rb'
41
+ require 'backup_paradise/advanced_backup/system_directory.rb'
42
+
43
+ module BackupParadise
44
+
45
+ class AdvancedBackup < ::BackupParadise::Base # === BackupParadise::AdvancedBackup
46
+
47
+ end; end
48
+
49
+ if __FILE__ == $PROGRAM_NAME
50
+ BackupParadise::AdvancedBackup.new(ARGV)
51
+ end # rbackup --help
52
+ # rbackup --data_only
53
+ # rbackup data_only
@@ -0,0 +1,124 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'backup_paradise/advanced_backup/audio.rb'
6
+ # =========================================================================== #
7
+ module BackupParadise
8
+
9
+ class AdvancedBackup < ::BackupParadise::Base # === BackupParadise::AdvancedBackup
10
+
11
+ # ========================================================================= #
12
+ # === try_to_backup_the_audio_directory (audio tag, audio dir tag)
13
+ #
14
+ # This method can be used to backup my audio directory, which normally
15
+ # resides at "/home/x/songs/".
16
+ #
17
+ # This method accepts two arguments.
18
+ #
19
+ # If the first argument is true then only those audio files that
20
+ # are missing will be copied.
21
+ #
22
+ # The second argument specifies which directory is used as the input
23
+ # directory, where the songs that are to be copied should reside.
24
+ # ========================================================================= #
25
+ def try_to_backup_the_audio_directory(
26
+ copy_only_missing_audio_files = true,
27
+ use_this_as_audio_directory_target = AUDIO_DIRECTORY
28
+ )
29
+ if File.directory? use_this_as_audio_directory_target
30
+ copied_n_files = 0
31
+ _ = target_mountpoint?+File.basename(use_this_as_audio_directory_target)
32
+ _ = _.dup if _.frozen?
33
+ _ << '/' unless _.end_with? '/'
34
+ cliner
35
+ opnn; e "Now trying to backup the Audio directory "\
36
+ "at `#{sdir(use_this_as_audio_directory_target)}`."
37
+ opnn; e "The target for this will be at `#{sdir(_)}`."
38
+ n_gigabytes = BackupParadise.size_in_gigabytes?(use_this_as_audio_directory_target).to_s
39
+ opnn; e 'This directory has a total of '+
40
+ sfancy(n_files_in?(use_this_as_audio_directory_target).to_s)+' entries '\
41
+ '(Total size: '+n_gigabytes+' GB).'
42
+ cliner
43
+ unless File.directory? _
44
+ opnn; verbose_create_a_directory_at_this_position(_)
45
+ end
46
+ rename_tab(:default, 'Backing up the main audio directory.')
47
+ unless use_this_as_audio_directory_target.end_with? '*'
48
+ if use_this_as_audio_directory_target.frozen?
49
+ use_this_as_audio_directory_target = use_this_as_audio_directory_target.dup
50
+ end
51
+ use_this_as_audio_directory_target << '*'
52
+ end
53
+ # ===================================================================== #
54
+ # Else we will copy only the audio files that are missing. In order
55
+ # to do so we have to obtain all audio-files - we will simply
56
+ # pick all files, anyway. We will keep these entries sorted, too.
57
+ # ===================================================================== #
58
+ these_audio_files_may_be_copied = Dir[
59
+ rds("#{use_this_as_audio_directory_target.delete('*')}/*")
60
+ ].sort
61
+ if copy_only_missing_audio_files
62
+ these_audio_files_may_be_copied.each {|this_file|
63
+ new_target = "#{_}#{File.basename(this_file)}"
64
+ # ================================================================= #
65
+ # We check whether the target-file exists. Only if it does not
66
+ # exist will it be copied.
67
+ # ================================================================= #
68
+ unless File.exist? new_target
69
+ copied_n_files += 1
70
+ # =============================================================== #
71
+ # Pad the display.
72
+ # =============================================================== #
73
+ padded_file = this_file.ljust(40)
74
+ padded_target = new_target.ljust(40)
75
+ e "Copying `#{sfile(padded_file)}` to"
76
+ e " `#{sfile(padded_target)}`."
77
+ copy_this_file(this_file, new_target)
78
+ end
79
+ }
80
+ else
81
+ copy_recursively(use_this_as_audio_directory_target, _)
82
+ end
83
+ # ======================================================================= #
84
+ # Ok, now, if we removed a file from /Depot/Audio, then the Audio/
85
+ # directory at the mounted USB device may still have such a file.
86
+ # So we will warn the user about this.
87
+ # ======================================================================= #
88
+ target = "#{mount_point?}#{File.basename(use_this_as_audio_directory_target)}/"
89
+ unless these_audio_files_may_be_copied.size == Dir["#{target}*"].size
90
+ opnn; e 'It seems as if we have an unequal amount of Audio files in '
91
+ opnn; e 'the two directories.'
92
+ opnn; e 'This usually means that the original directory '+
93
+ sdir(use_this_as_audio_directory_target)+' has some files'
94
+ opnn; e 'deleted, but the target directory at '+sdir(target)+' does not.'
95
+ opnn; e 'The old directory has '+simp(
96
+ these_audio_files_may_be_copied.size.to_s
97
+ )+' entries.'
98
+ end
99
+ if copied_n_files == 0
100
+ opnn; e "No file was copied into the directory "\
101
+ "#{sdir(_)}."
102
+ opnn; e 'This may indicate that the target audio-directory already '
103
+ opnn; e 'contains all necessary audio-files.'
104
+ else
105
+ opnn; e "Finished backing up the directory "\
106
+ "#{sdir(use_this_as_audio_directory_target.delete('*'))} into #{sdir(_)}."
107
+ end
108
+ else
109
+ can_not_backup_this_directory_as_it_does_not_exist(use_this_as_audio_directory_target)
110
+ end
111
+ end; alias backup_audio_directory try_to_backup_the_audio_directory # === backup_audio_directory
112
+ alias backup_the_audio_directory try_to_backup_the_audio_directory # === backup_the_audio_directory
113
+
114
+ # ========================================================================= #
115
+ # === backup_audio_directory_then_exit
116
+ #
117
+ # Backup the audio directory, then exit the program.
118
+ # ========================================================================= #
119
+ def backup_audio_directory_then_exit
120
+ backup_audio_directory
121
+ exit_program
122
+ end
123
+
124
+ end; end
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'backup_paradise/advanced_backup/constants.rb'
6
+ # =========================================================================== #
7
+ require 'backup_paradise/base/base.rb'
8
+
9
+ module BackupParadise
10
+
11
+ class AdvancedBackup < ::BackupParadise::Base
12
+
13
+ # ========================================================================= #
14
+ # === NAMESPACE
15
+ # ========================================================================= #
16
+ NAMESPACE = inspect
17
+
18
+ # ========================================================================= #
19
+ # === MINIMAL_FILESIZE
20
+ # ========================================================================= #
21
+ MINIMAL_FILESIZE = 5 * (1000 ** 3) # 5 * 1024 * 1024 * 1024
22
+
23
+ # ========================================================================= #
24
+ # === FILE_BACKUP_LOG
25
+ #
26
+ # Denote where to keep the backup.log file, if we log that is.
27
+ # ========================================================================= #
28
+ if File.directory? '/home/Temp/'
29
+ FILE_BACKUP_LOG = '/home/Temp/advanced_backup.log'
30
+ else
31
+ FILE_BACKUP_LOG = '/tmp/advanced_backup.log'
32
+ end
33
+
34
+ end; end
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'backup_paradise/advanced_backup/data_directory.rb'
6
+ # =========================================================================== #
7
+ module BackupParadise
8
+
9
+ class AdvancedBackup < ::BackupParadise::Base
10
+
11
+ # ========================================================================= #
12
+ # === backup_the_data_directory_then_exit
13
+ #
14
+ # Backup only Data directory.
15
+ # ========================================================================= #
16
+ def backup_the_data_directory_then_exit
17
+ backup_data_directory
18
+ exit_program
19
+ end; alias backup_data_directory_then_exit backup_the_data_directory_then_exit # === backup_data_directory_then_exit
20
+
21
+ # ========================================================================= #
22
+ # === backup_the_data_directory (data tag)
23
+ #
24
+ # This method will backup the DATA directory, e. g. the one that is
25
+ # at "/home/x/DATA/" on my home system.
26
+ # ========================================================================= #
27
+ def backup_the_data_directory(
28
+ target_directory = DATA_DIRECTORY
29
+ )
30
+ if File.directory? target_directory
31
+ mountpoint_target = main_target?+File.basename(target_directory)
32
+ cliner
33
+ e "Now backing up the DATA directory from "\
34
+ "#{sfancy(target_directory)} into "\
35
+ "#{sfile(mountpoint_target)}."
36
+ cliner
37
+ report_total_size_of(target_directory)
38
+ unless File.directory? mountpoint_target
39
+ create_directory(mountpoint_target, 0755)
40
+ end
41
+ backup_this_directory_if_it_exists(
42
+ target_directory, :default, :do_not_continue
43
+ )
44
+ else
45
+ can_not_backup_this_directory_as_it_does_not_exist(target_directory)
46
+ end
47
+ end; alias backup_only_data_directory backup_the_data_directory # === backup_only_data_directory
48
+ alias backup_data_directory backup_the_data_directory # === backup_data_directory
49
+
50
+ end; end