Class: Yast::BackupClass

Inherits:
Module
  • Object
show all
Defined in:
../../src/modules/Backup.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) BackupMtab

Stores the content of /etc/mtab to a 'safe place'



522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
# File '../../src/modules/Backup.rb', line 522

def BackupMtab
  # nothing to backup
  if !FileUtils.Exists(@mtab_file)
    Builtins.y2error("There is no mtab file!")
    return false
  end

  Builtins.y2milestone(
    "Creating backup of %1 to %2\n---\n%3\n---",
    @mtab_file,
    @temporary_mtab_file,
    SCR.Execute(
      path(".target.bash_output"),
      Builtins.sformat("cat '%1'", String.Quote(@mtab_file))
    )
  )

  # creating backup by `cat` - the original file attributes are kept intact
  if Convert.to_integer(
      SCR.Execute(
        path(".target.bash"),
        Builtins.sformat(
          "cat '%1' > '%2'",
          String.Quote(@mtab_file),
          String.Quote(@temporary_mtab_file)
        )
      )
    ) != 0
    Builtins.y2error(
      "Cannot backup %1 to %2",
      @mtab_file,
      @temporary_mtab_file
    )
    return false
  end

  true
end

- (Array) BackupProfileDescriptions

Helper function to extract the list of currently available profiles

Returns:

  • (Array)

    List of item used in the table widget



1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
# File '../../src/modules/Backup.rb', line 1827

def BackupProfileDescriptions
  result = Builtins.maplist(@backup_profiles) do |key, value|
    # description can be multiline - merge lines
    descr = Builtins.mergestring(
      Builtins.splitstring(
        Ops.get_string(value, :description, @default_description),
        "\n"
      ),
      " "
    )
    displayinfo = UI.GetDisplayInfo
    # limit size of description shown in the table
    # maximum length half of width in ncurses UI
    maxsize = Ops.get_boolean(displayinfo, "TextMode", false) ?
      Ops.divide(Ops.get_integer(displayinfo, "Width", 80), 2) :
      40
    if Ops.greater_than(Builtins.size(descr), maxsize)
      # use only the beginning of the description, add dots
      # BNC #446996: substring for localized strings -> lsubstring
      descr = Ops.add(Builtins.lsubstring(descr, 0, maxsize), "...")
    end
    Item(Id(key), key, descr, CreateCronDescription(key))
  end

  if result == nil
    return []
  else
    return deep_copy(result)
  end
end

- (Object) BackupProfileNames

Get a sorted list of profile names currently available.

Returns:

  • the list of strings (possibly empty).



1750
1751
1752
1753
1754
1755
1756
1757
# File '../../src/modules/Backup.rb', line 1750

def BackupProfileNames
  result = Builtins.maplist(@backup_profiles) { |key, value| key }
  if result == nil
    return []
  else
    return Builtins.sort(result)
  end
end

- (String) CreateCronDescription(profilename)

Create description of automatic backup.

Parameters:

  • profilename (String)

    Name of the profile

Returns:

  • (String)

    description string or empty string if profile has disabled automatic start



1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
# File '../../src/modules/Backup.rb', line 1764

def CreateCronDescription(profilename)
  input = Ops.get_map(@backup_profiles, [profilename, :cron_settings], {})
  ret = ""

  return ret if input == nil || input == {}

  if Ops.get_boolean(input, "auto", false) == true
    hour = Ops.get_integer(input, "hour", 0)
    minute = Ops.get_integer(input, "minute", 0)
    day = Ops.get_integer(input, "day", 1)
    weekday = Ops.get_integer(input, "weekday", 0)
    every = Ops.get_symbol(input, "every", :unknown)

    # hour/minutes time format - set according your local used format
    # usually used conversion specificators:
    # %H - hour (0..23), %I - hour (0..12)
    # %M - minute (0..59), %p - `AM' or `PM'
    # (see man date for more details)
    timeformat = _("%I:%M %p")

    bashcommand = Builtins.sformat(
      "/bin/date --date '%1:%2' '+%3'",
      hour,
      minute,
      timeformat
    )
    # convert hour and minutes to localized time string - use date utility
    result = Convert.to_map(
      SCR.Execute(path(".target.bash_output"), bashcommand)
    )
    ltime = Builtins.mergestring(
      Builtins.splitstring(Ops.get_string(result, "stdout", ""), "\n"),
      ""
    )

    if ltime == ""
      # table item - specified time is invalid
      ret = _("Invalid time")
    elsif every == :day
      # table item - start backup every day (%1 is time)
      ret = Builtins.sformat(_("Back up daily at %1"), ltime)
    elsif every == :week
      # table item - start backup every week (%1 is day name, %2 is time)
      ret = Builtins.sformat(
        _("Back up weekly (%1 at %2)"),
        Ops.get(@daynames, weekday, "?"),
        ltime
      )
    elsif every == :month
      # table item - start backup once a month (%1 is day (ordinal number, e.g. 5th), %2 is time)
      ret = Builtins.sformat(
        _("Back up monthly (%1 day at %2)"),
        Ops.get(@ordinal_numbers, day, "?"),
        ltime
      )
    end
  end

  ret
end

- (String) CreateCronSetting(profilename)

Create cron file content for selected profile.

Parameters:

  • profilename (String)

    Name of the profile

Returns:

  • (String)

    Cron content or empty string if profile has disabled automatic start



1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
# File '../../src/modules/Backup.rb', line 1284

def CreateCronSetting(profilename)
  input = Ops.get_map(@backup_profiles, [profilename, :cron_settings], {})
  ret = ""

  # return empty string if cron setting was not changed
  if input == nil || input == {} ||
      Ops.get_boolean(input, "cron_changed", false) == false
    return ret
  end

  if Ops.get_boolean(input, "auto", false) == true
    hour = Ops.get_integer(input, "hour", 0)
    minute = Ops.get_integer(input, "minute", 0)
    day = Ops.get_integer(input, "day", 1)
    weekday = Ops.get_integer(input, "weekday", 0)
    every = Ops.get_symbol(input, "every", :unknown)

    if every == :day
      ret = Builtins.sformat(
        "%1 %2 * * *  root  /usr/lib/YaST2/bin/backup_cron \"profile=%3\"\n",
        minute,
        hour,
        profilename
      )
    elsif every == :week
      ret = Builtins.sformat(
        "%1 %2 * * %3  root  /usr/lib/YaST2/bin/backup_cron \"profile=%4\"\n",
        minute,
        hour,
        weekday,
        profilename
      )
    elsif every == :month
      ret = Builtins.sformat(
        "%1 %2 %3 * *  root  /usr/lib/YaST2/bin/backup_cron \"profile=%4\"\n",
        minute,
        hour,
        day,
        profilename
      )
    end

    # add comment to the first line
    ret = Ops.add(
      "# Please do not edit this file manually, use YaST2 backup module instead\n",
      ret
    )
  end

  ret
end

- (Hash) DetectedMountPoints

Returns detected mount points

Returns:

  • (Hash)

    detected mount points



2106
2107
2108
2109
2110
2111
# File '../../src/modules/Backup.rb', line 2106

def DetectedMountPoints
  # return cached value if available
  @detected_mpoints = DetectMountpoints() if @detected_mpoints == nil

  deep_copy(@detected_mpoints)
end

- (Object) ExcludeNodevFS

Exclude file systems without device



815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
# File '../../src/modules/Backup.rb', line 815

def ExcludeNodevFS
  filesystems = Convert.convert(
    SCR.Read(path(".proc.filesystems")),
    :from => "any",
    :to   => "map <string, string>"
  )

  return if filesystems == nil

  Builtins.foreach(filesystems) do |k, v|
    @fs_exclude = Builtins.add(@fs_exclude, k) if v == "nodev"
  end 


  @fs_exclude = Builtins.toset(@fs_exclude)

  Builtins.y2milestone("Detected nodev filesystems: %1", @fs_exclude)

  nil
end

- (String) get_archive_script_parameters(file_list, file_comment)

Return backup_search.pl script parameters according to state of variables

Parameters:

  • file_list (String)

    Where is list of files to backup stored

  • file_comment (String)

    Where is comment stored

Returns:

  • (String)

    String with command line parameters



658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
# File '../../src/modules/Backup.rb', line 658

def get_archive_script_parameters(file_list, file_comment)
  archive_options = Ops.add(
    Ops.add(
      Ops.add(
        Ops.add(" --verbose --files-info '", String.Quote(file_list)),
        "' --comment-file '"
      ),
      String.Quote(file_comment)
    ),
    "'"
  )

  if Ops.greater_than(Builtins.size(@complete_backup), 0)
    # store list of completely backed up files into a file
    complete_string = Builtins.mergestring(@complete_backup, "\n")
    tmpdir = Convert.to_string(SCR.Read(path(".target.tmpdir")))

    SCR.Write(
      path(".target.string"),
      Ops.add(tmpdir, "/complete_backup"),
      complete_string
    )
    archive_options = Ops.add(
      Ops.add(Ops.add(archive_options, " --complete-backup "), tmpdir),
      "/complete_backup"
    )
  else
    Builtins.y2debug("complete_backup is empty")
  end

  Builtins.y2debug(
    "nfsmount: %1, archive_name: %2",
    @nfsmount,
    @archive_name
  )

  archive_options = Ops.add(
    Ops.add(
      Ops.add(archive_options, " --archive-name '"),
      String.Quote(
        @target_type == :file ?
          @archive_name :
          Builtins.sformat("%1/%2", @nfsmount, @archive_name)
      )
    ),
    "'"
  )

  if @system
    # add partition tabel option
    if @backup_pt
      archive_options = Ops.add(archive_options, " --store-ptable")
    end

    tmp_selected_pt = []
    Builtins.foreach(
      @ext2_backup # get device names from `item(`id(XYZ), "XYZ")
    ) do |sel_tmp_pt|
      tmp = Ops.get_string(sel_tmp_pt, 1)
      tmp_selected_pt = Builtins.add(tmp_selected_pt, tmp) if tmp != nil
    end 


    detected_ext2_strings = []

    Builtins.foreach(@detected_ext2) do |info|
      part = Ops.get_string(info, "partition")
      if part != nil
        detected_ext2_strings = Builtins.add(detected_ext2_strings, part)
      end
    end 


    partitions = @backup_all_ext2 ?
      detected_ext2_strings :
      @backup_none_ext2 ? [] : tmp_selected_pt

    Builtins.y2milestone("Backup Ext2 partitions: %1", partitions)

    Builtins.foreach(partitions) do |spt|
      archive_options = Ops.add(
        Ops.add(archive_options, " --store-ext2 "),
        spt
      )
    end
  end


  typemap = {
    :tgz  => "tgz",
    :tbz  => "tbz2",
    :tar  => "tar",
    :stgz => "stgz",
    :stbz => "stbz2",
    :star => "star",
    :txt  => "txt"
  }

  archive_options = Ops.add(
    Ops.add(archive_options, " --archive-type "),
    Ops.get_string(typemap, @archive_type, "tgz")
  )


  if @multi_volume
    if @volume_size == :user_defined
      # compute volume size (in kiB)
      vol_size = Builtins.tointeger(
        Ops.divide(
          Ops.multiply(
            Builtins.tofloat(@user_volume_size),
            Builtins.tofloat(
              GetCapacity(@units_description, @user_volume_unit)
            )
          ),
          1024.0
        )
      )

      Builtins.y2debug("Volume size is %1 kiB", vol_size)

      if Ops.greater_than(vol_size, 0)
        archive_options = Ops.add(
          Ops.add(archive_options, " --multi-volume "),
          Builtins.sformat("%1", vol_size)
        )
      else
        Builtins.y2warning("Bad volume size: %1", @user_volume_size)
      end
    else
      archive_options = Ops.add(
        Ops.add(archive_options, " --multi-volume "),
        Builtins.tointeger(
          Ops.divide(
            Builtins.tofloat(GetCapacity(@media_descriptions, @volume_size)),
            1024.0
          )
        )
      )
    end
  end

  if Ops.greater_than(Builtins.size(@tmp_dir), 0)
    archive_options = Ops.add(
      Ops.add(archive_options, " --tmp-dir "),
      @tmp_dir
    )
  end

  Builtins.y2milestone("Archive script options: %1", archive_options)

  archive_options
end

- (String) get_search_script_parameters

Return backup_search.pl script parameters according to state of variables

Returns:

  • (String)

    String with command line parameters



408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
# File '../../src/modules/Backup.rb', line 408

def get_search_script_parameters
  script_options = " --start-dir / --output-progress" # required parameter for YaST2 frontend

  if @backup_all_rpms_content
    # see bnc #344643
    Builtins.y2milestone("Backup all RPMs content...")
    script_options = Ops.add(script_options, " --all-rpms-content")
  end

  script_options = Ops.add(script_options, " --search") if @do_search

  # Include Dirs
  @include_dirs = Builtins.toset(@include_dirs)
  Builtins.y2milestone("Directories to include: %1", @include_dirs)
  if Builtins.size(@include_dirs) == 0
    @include_dirs = [@default_include_dir]
  end
  Builtins.foreach(@include_dirs) do |d|
    if d != nil
      script_options = Ops.add(
        script_options,
        Builtins.sformat(" --include-dir '%1'", String.Quote(d))
      )
    end
  end

  # Exclude Dirs
  Builtins.y2milestone("Directories to exclude: %1", @dir_list)
  if Ops.greater_than(Builtins.size(@dir_list), 0)
    Builtins.foreach(@dir_list) do |d|
      if d != nil
        script_options = Ops.add(
          script_options,
          Builtins.sformat(" --exclude-dir '%1'", String.Quote(d))
        )
      end
    end
  end

  # Exclude Files
  Builtins.y2milestone("Files to exclude: %1", @regexp_list)
  if Ops.greater_than(Builtins.size(@regexp_list), 0)
    Builtins.foreach(@regexp_list) do |r|
      if r != nil
        script_options = Ops.add(
          script_options,
          Builtins.sformat(" --exclude-files '%1'", String.Quote(r))
        )
      end
    end
  end

  # Exclude FileSystems
  Builtins.y2milestone("Filesystems to exclude: %1", @fs_exclude)
  if Ops.greater_than(Builtins.size(@fs_exclude), 0)
    Builtins.foreach(@fs_exclude) do |i|
      script_options = Ops.add(
        script_options,
        Builtins.sformat(" --exclude-fs '%1'", String.Quote(i))
      )
    end
  end

  # save list of installable packages and pass it to the search script
  if Ops.greater_than(Builtins.size(@installable_packages), 0)
    content = Builtins.mergestring(@installable_packages, "\n")
    listfile = Ops.add(
      Convert.to_string(SCR.Read(path(".target.tmpdir"))),
      "/packagelist"
    )

    SCR.Write(path(".target.string"), listfile, content)

    script_options = Ops.add(
      Ops.add(script_options, " --inst-src-packages "),
      listfile
    )
  end

  script_options = Ops.add(script_options, " --no-md5") if !@do_md5_test

  # if (display files before archiving them)
  if @display
    Builtins.y2milestone("Files files will be displayed before archiving")
    # add widget file option
    script_options = Ops.add(
      Ops.add(
        Ops.add(script_options, " --widget-file "),
        Convert.to_string(SCR.Read(path(".target.tmpdir")))
      ),
      "/items.ycp"
    )

    # add items list option
    script_options = Ops.add(
      Ops.add(
        Ops.add(script_options, " --list-file "),
        Convert.to_string(SCR.Read(path(".target.tmpdir")))
      ),
      "/items-list.ycp"
    )
  else
    Builtins.y2milestone("Displaying files will be skipped")
  end

  # add package verification option
  script_options = Ops.add(script_options, " --pkg-verification")

  Builtins.y2milestone("Search script options: %1", script_options)

  script_options
end

- (Fixnum) GetCapacity(media, m)

Return capacity of required medium

Parameters:

  • media (Array<Hash{String => Object>})

    Medium descriptions

  • m (Symbol)

    Identification of required medium

Returns:

  • (Fixnum)

    Size of medium in bytes



391
392
393
394
395
396
397
398
399
400
401
402
# File '../../src/modules/Backup.rb', line 391

def GetCapacity(media, m)
  media = deep_copy(media)
  result = nil

  Builtins.foreach(media) do |val|
    if Ops.get_symbol(val, "symbol") == m
      result = Ops.get_integer(val, "capacity")
    end
  end if media != nil

  result
end

- (String) GetLocalArchiveName

Returns local archive name (required if NFS target is used)

Returns:

  • (String)

    local archive name



2115
2116
2117
2118
2119
2120
2121
2122
2123
# File '../../src/modules/Backup.rb', line 2115

def GetLocalArchiveName
  ret = @archive_name

  if @target_type == :nfs && @nfsmount != nil
    ret = Ops.add(Ops.add(@nfsmount, "/"), @archive_name)
  end

  ret
end

- (Object) main



22
23
24
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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
# File '../../src/modules/Backup.rb', line 22

def main
  Yast.import "UI"

  textdomain "backup"

  Yast.import "Progress"
  Yast.import "Report"
  Yast.import "Nfs"
  Yast.import "Popup"
  Yast.import "FileUtils"
  Yast.import "String"
  Yast.import "Service"
  Yast.import "Directory"

  Yast.include self, "backup/functions.rb"

  # include "hwinfo/classnames.ycp";
  # do not include (requires installed yast2-tune)
  # just use that part of the ClassNames from classnames.ycp
  @ClassNames = {
    262 => {
      # TRANSLATORS: name of device (the same as in yast2-tune) - the first device
      "name" => _(
        "Mass storage device"
      ),
      0      => _("Disk"),
      1      => _("Tape"),
      2      => _("CD-ROM"),
      3      => _("Floppy disk"),
      # TRANSLATORS: name of device (the same as in yast2-tune) - the last device
      128    => _(
        "Storage device"
      )
    }
  }

  # maximum cron file index
  @max_cron_index = 0

  @script_store_ext2_area = "/sbin/e2image"
  @script_get_partition_table = "/sbin/fdisk -l"
  @script_get_files = "/usr/lib/YaST2/bin/backup_search.pl"
  @script_create_archive = "/usr/lib/YaST2/bin/backup_archive.pl"

  # day names, key is integer used in crontab
  @daynames = {
    1 => _("Monday"),
    2 => _("Tuesday"),
    3 => _("Wednesday"),
    4 => _("Thursday"),
    5 => _("Friday"),
    6 => _("Saturday"),
    7 => _("Sunday")
  }

  @ordinal_numbers = {
    1  => _("1st"),
    2  => _("2nd"),
    3  => _("3rd"),
    4  => _("4th"),
    5  => _("5th"),
    6  => _("6th"),
    7  => _("7th"),
    8  => _("8th"),
    9  => _("9th"),
    10 => _("10th"),
    11 => _("11th"),
    12 => _("12th"),
    13 => _("13th"),
    14 => _("14th"),
    15 => _("15th"),
    16 => _("16th"),
    17 => _("17th"),
    18 => _("18th"),
    19 => _("19th"),
    20 => _("20th"),
    21 => _("21st"),
    22 => _("22nd"),
    23 => _("23rd"),
    24 => _("24th"),
    25 => _("25th"),
    26 => _("26th"),
    27 => _("27th"),
    28 => _("28th"),
    29 => _("29th"),
    30 => _("30th"),
    31 => _("31st")
  }

  # global settings

  @backup_profiles = {} # map of all available profiles

  # global defaults
  @default_archive_name = "" # archive file name
  @default_description = "" # user comment
  @default_archive_type = :tgz # archive type

  @default_multi_volume = false
  @default_volume_size = :fd144
  @default_user_volume_size = ""
  @default_user_volume_unit = nil

  @default_search = true # search files which do not belong to any package
  @default_all_rpms_content = false # by default only changed RPM-files are backed up
  @default_system = false # backup system areas
  @default_display = false # display files before creating archive
  @default_do_md5_test = true
  @default_perms = true # store RPM file if owner/permissions were changed

  @default_default_dir = [
    "/media",
    "/tmp",
    "/var/lock",
    "/var/run",
    "/var/tmp",
    "/var/cache",
    "/sys",
    "/windows",
    "/mnt",
    "/var/lib/ntp/proc"
  ] # default excluded directoried from search
  @default_dir_list = deep_copy(@default_default_dir) # selected directoried to exclude
  @default_include_dir = "/"
  @default_regexp_list = []

  # iso9660 is used on CDROM, ntfs read-only
  @default_fs_exclude = ["iso9660", "ntfs", "none"] # selected filesystems to exclude from search
  @default_detected_fs = nil # detected filesystems

  @default_detected_ext2 = nil # detected mounted ext2 filesystems
  @default_ext2_backup = [] # selected ext2 filesystems to backup

  @default_backup_pt = true # backup partition table

  @default_backup_all_ext2 = false # backup all mounted ext2 partitions
  @default_backup_none_ext2 = true # backup none ext2 partitions
  @default_backup_selected_ext2 = false # backup selected ext2 partitions

  @default_tmp_dir = "/tmp"

  #global list default_all_entered_dirs = [];

  @default_backup_files = {} # all found files to backup
  @default_selected_files = nil # selected files to backup
  @default_unselected_files = [] # files, which user explicitly unselected
  #global list default_selected_directories = [];	// default directories to backup

  #global boolean default_LVMsnapshot = true;
  #global boolean default_testonly = false;
  @default_autoprofile = true
  #global boolean default_systembackup = true;
  @default_target_type = :file
  #global string default_target_device = nil;
  #global map default_target_devices_options = $[];
  @default_temporary_dir = "/var/lib/YaST2/backup/tmp"

  @default_nfsserver = ""
  @default_nfsexport = ""

  @default_mail_summary = true

  # global variables initialized to default values:
  @archive_name = @default_archive_name # archive file name
  @description = @default_description # user comment
  @archive_type = @default_archive_type # archive type

  @profile_is_new_one = false # newly created archive

  @multi_volume = @default_multi_volume
  @volume_size = @default_volume_size
  @user_volume_size = @default_user_volume_size
  @user_volume_unit = @default_user_volume_unit

  @user_vol_size = 0
  @temporary_dir = @default_temporary_dir
  @mail_summary = @default_mail_summary

  @do_search = @default_search # search files which do not belong to any package
  @backup_all_rpms_content = @default_all_rpms_content # backup content of all packages
  @system = @default_system # backup system areas
  @display = @default_display # display files before creating archive
  @do_md5_test = @default_do_md5_test
  @perms = @default_perms

  @target_type = @default_target_type
  #global string target_device = default_target_device;
  #global map target_devices_options = default_target_devices_options;

  @default_dir = deep_copy(@default_default_dir) # default excluded directoried from search
  @dir_list = deep_copy(@default_dir_list) # selected directoried to exclude
  @include_dirs = [@default_include_dir] # selected included directories

  @regexp_list = deep_copy(@default_regexp_list)

  @fs_exclude = deep_copy(@default_fs_exclude) # selected filesystems to exclude from search
  @detected_fs = deep_copy(@default_detected_fs) # detected filesystems

  @detected_ext2 = deep_copy(@default_detected_ext2) # detected mounted ext2 filesystems
  @ext2_backup = deep_copy(@default_ext2_backup) # selected ext2 filesystems to backup

  @backup_pt = @default_backup_pt # backup partition table

  @backup_all_ext2 = @default_backup_all_ext2 # backup all mounted ext2 partitions
  @backup_none_ext2 = @default_backup_none_ext2 # backup none ext2 partitions
  @backup_selected_ext2 = @default_backup_selected_ext2 # backup selected ext2 partitions

  @tmp_dir = @default_tmp_dir
  # archive target dir used in functions
  @target_dir = ""

  @cron_mode = false
  @cron_profile = ""

  @backup_helper_scripts = []

  #global boolean LVMsnapshot = default_LVMsnapshot;
  #global boolean testonly = default_testonly;
  @autoprofile = @default_autoprofile
  #global boolean systembackup = default_systembackup;

  @nfsserver = @default_nfsserver
  @nfsexport = @default_nfsexport
  @nfsmount = nil # NFS mount point, remember for unmounting

  @backup_files = Builtins.eval(@default_backup_files) # all found files to backup
  @selected_files = Builtins.eval(@default_selected_files) # selected files to backup
  @unselected_files = deep_copy(@default_unselected_files) # files, which user explicitly unselected

  #global list selected_directories = default_selected_directories;
  #global list all_entered_dirs = default_all_entered_dirs;

  @no_interactive = false # whether the user should setup configuration manually
  @selected_profile = nil # name of the selected profile, nil for no selected profile (default settings)

  # default volume size if it wasn't detected
  @undetected_volume_size = 1024 * 1024 * 1024

  @installable_packages = []
  @complete_backup = []

  # list of files to be deleted finishing the backup editation
  @remove_cron_files = []

  # result of removing old archives
  @remove_result = {}

  # cached detected mount points
  @detected_mpoints = nil
  # end of global settings

  @cron_settings = {}

  # media description - capacity is maximum file size which fits
  # to formatted medium using widely used file system (FAT on floppies)

  # just archiving
  @just_creating_archive = false

  @cd_media_descriptions = [
    {
      "label"    => _("CD-R/RW 650 MB (74 min.)"),
      "symbol"   => :cd650,
      "capacity" => 649 * 1024 * 1024
    }, # exact size is 703.1 MB - remaining space is for ISO fs
    {
      "label"    => _("CD-R/RW 700 MB (80 min.)"),
      "symbol"   => :cd700,
      "capacity" => 702 * 1024 * 1024
    }
  ] # exact size is 650.4 MB - remaining space is for ISO fs

  @floppy_media_descriptions = [
    {
      "label"    => _("Floppy 1.44 MB"),
      "symbol"   => :fd144,
      "capacity" => 1423 * 1024
    }, # 1213952B is exact size for FAT fs
    {
      "label"    => _("Floppy 1.2 MB"),
      "symbol"   => :fd12,
      "capacity" => 1185 * 1024
    }
  ] # 1457664B is exact size for FAT fs

  @zip_media_descriptions =
    # $[
    # 	"label" : _("ZIP 250 MB"),
    # 	"symbol" : `zip250,
    # 	"capacity" : ?????
    #     ],
    [
      {
        "label"    => _("ZIP 100 MB"),
        "symbol"   => :zip100,
        "capacity" => 95 * 1024 * 1024
      }
    ] # exact size is 96MiB (64 heads, 32 sectors, 96 cylinders, 512B sector)

  @misc_descriptions =
    # $[
    # 	"label" : _("Default Volume Size"),
    # 	"symbol" : `default_size,
    # 	"capacity" : 1024*1024*1024
    #     ]
    []

  @media_descriptions = Convert.convert(
    Builtins.merge(
      Builtins.merge(
        Builtins.merge(@cd_media_descriptions, @floppy_media_descriptions),
        @zip_media_descriptions
      ),
      @misc_descriptions
    ),
    :from => "list",
    :to   => "list <map <string, any>>"
  )

  @units_description = [
    { "label" => _("bytes"), "capacity" => 1, "symbol" => :B },
    {
      # 10^3 bytes
      "label"    => _("kB"),
      "capacity" => 1000,
      "symbol"   => :kB
    },
    {
      # 2^10 bytes
      "label"    => _("KiB"),
      "capacity" => 1024,
      "symbol"   => :kiB
    },
    {
      # 10^6 bytes
      "label"    => _("MB"),
      "capacity" => 1000000,
      "symbol"   => :MB
    },
    {
      # 2^20 bytes
      "label"    => _("MiB"),
      "capacity" => 1024 * 1024,
      "symbol"   => :MiB
    }
  ]

  # File where configuration is stored
  @configuration_filename = "/var/adm/YaST/backup/profiles"

  @backup_scripts_dir = "/var/adm/YaST/backup/scripts/"

  # When creating backup on NFS share, /etc/mtab is modified after mounting the NFS
  # share to a temporary directory. This causes problems later after restoring
  # the backup because mountpoint was only temporary and doesn't exist anymore.
  #
  # See BNC #675259
  @temporary_mtab_file = Builtins.sformat(
    "%1/temporary_mtab_file",
    Directory.tmpdir
  )
  @mtab_file = "/etc/mtab"
end

- (Hash) MapFilesToString

Writes file using the .backup.file_append SCR agent. This file is accepted by backup_archive.pl script. Used global variables: selected_files, backup_files.

“sel_files” (integer - number of selected files), "sel_packages" (integer: number of selected packages), "ret_file_list_stored" (boolean: whether the filelist has been completely stored)

Returns:

  • (Hash)

    with keys

See Also:

  • href="../backup_specification.html">Backup module specification


2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
# File '../../src/modules/Backup.rb', line 2135

def MapFilesToString
  num_files = 0
  num_pack = 0

  return {} if @selected_files == nil

  UI.OpenDialog(
    Left(
      Label(
        # busy message
        _("Creating the list of files for the backup...")
      )
    )
  )

  Builtins.y2milestone("Storing filenames list...")
  filelist_tmpfile = Ops.add(
    Convert.to_string(SCR.Read(path(".target.tmpdir"))),
    "/filelist"
  )
  ret_file_list_stored = true
  flist_appended = nil

  Builtins.foreach(@selected_files) do |pkg, info|
    if pkg != ""
      flist_appended = SCR.Write(
        path(".backup.file_append"),
        [
          filelist_tmpfile,
          Ops.add(
            Ops.add(
              Ops.add(
                Ops.add(
                  Ops.add(
                    Ops.add(Ops.add("Package: ", pkg), "\n"),
                    "Installed: "
                  ),
                  Ops.get_string(info, "install_prefixes", "(none)")
                ),
                "\n"
              ),
              Builtins.mergestring(
                Ops.get_list(info, "changed_files", []),
                "\n"
              )
            ),
            "\n"
          )
        ]
      )
      if !flist_appended
        ret_file_list_stored = false
        # a popup error, %1 is as file name
        Report.Error(
          Builtins.sformat(
            _("Cannot write the list of selected files to file %1."),
            filelist_tmpfile
          )
        )
        raise Break
      end

      num_files = Ops.add(
        num_files,
        Builtins.size(Ops.get_list(info, "changed_files", []))
      )
      num_pack = Ops.add(num_pack, 1)
    end
  end

  # huge amount of files, write by one (or using a buffer)
  flist_appended = SCR.Write(
    path(".backup.file_append"),
    [filelist_tmpfile, "Nopackage:\n"]
  )
  Builtins.foreach(Ops.get_list(@selected_files, ["", "changed_files"], [])) do |changed_file|
    flist_appended = SCR.Write(
      path(".backup.file_append"),
      [filelist_tmpfile, Ops.add(changed_file, "\n")]
    )
    if !flist_appended
      ret_file_list_stored = false
      # a popup error, %1 is as file name
      Report.Error(
        Builtins.sformat(
          _("Cannot write the list of selected files to file %1."),
          filelist_tmpfile
        )
      )
      raise Break
    end
    num_files = Ops.add(num_files, 1)
  end
  num_pack = Ops.add(num_pack, 1)

  Builtins.y2milestone("Filename stored")

  # free the lizard
  @selected_files = {}

  UI.CloseDialog

  {
    "sel_files"        => num_files,
    "sel_packages"     => num_pack,
    "file_list_stored" => ret_file_list_stored
  }
end

- (Boolean) PostBackup

Post-backup function - unmount mounted NFS share

Returns:

  • (Boolean)

    true on success



643
644
645
646
647
648
649
650
651
# File '../../src/modules/Backup.rb', line 643

def PostBackup
  if @target_type == :nfs && @nfsmount != nil
    ret = Nfs.Unmount(@nfsmount)
    @nfsmount = nil
    return ret
  end

  true
end

- (Boolean) PrepareBackup

Pre-backup function - mount NFS share if required

Returns:

  • (Boolean)

    true on success



625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
# File '../../src/modules/Backup.rb', line 625

def PrepareBackup
  if @target_type == :nfs && @nfsmount == nil
    # BNC #675259: Backup /etc/mtab before it's changed by mounting a NFS share
    BackupMtab()

    @nfsmount = Nfs.Mount(@nfsserver, @nfsexport, nil, "", "")

    # BNC #675259: Restore backup of /etc/mtab before the backup archive is created
    RestoreMtab()

    return @nfsmount != nil
  end

  true
end

- (Boolean) ReadBackupProfiles

Read backup profiles from file, do not set any global settings, just

Returns:

  • (Boolean)

    true if there are some profiles available

See Also:

  • The profiles are stored in hardcoded place (configuration_filename variable).


1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
# File '../../src/modules/Backup.rb', line 1241

def ReadBackupProfiles
  if FileUtils.Exists(@configuration_filename)
    Builtins.y2milestone(
      "Reading configuration from %1",
      @configuration_filename
    )
    @backup_profiles = Convert.convert(
      SCR.Read(path(".target.ycp"), @configuration_filename),
      :from => "any",
      :to   => "map <string, map>"
    )
  else
    Builtins.y2milestone(
      "Configuration file %1 doesn't exist yet",
      @configuration_filename
    )
    @backup_profiles = nil
  end

  # if the list is empty or the file does not exists, set empty map
  @backup_profiles = {} if @backup_profiles == nil

  Builtins.foreach(@backup_profiles) do |profname, opts|
    Builtins.y2debug("Read profile %1: %2", profname, opts)
    if Ops.get_boolean(opts, [:cron_settings, "auto"], false) == true
      Builtins.y2debug("Deactivating profile %1", profname)
      Ops.set(opts, [:cron_settings, "auto"], false)
      Ops.set(@backup_profiles, profname, Builtins.eval(opts))
    end
  end 


  # add cron settings
  ReadCronSettings()

  @backup_profiles != {}
end

- (Hash) ReadCronSetting(filename)

Parse cron file

Parameters:

  • filename (String)

    File to parse

Returns:

  • (Hash)

    parsed values: $[“auto”:boolean, “day”:integer, “hour”:integer, “minute”:integer, “weekday”:integer, “every”:symbol] or empty map if parse error occured



1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
# File '../../src/modules/Backup.rb', line 1016

def ReadCronSetting(filename)
  ret = {}

  return deep_copy(ret) if filename == nil || filename == ""

  filecontent = Convert.to_string(
    SCR.Read(path(".target.string"), filename)
  )
  lines = Builtins.splitstring(filecontent, "\n")

  # filter out comments
  lines = Builtins.filter(lines) { |l| !Builtins.regexpmatch(l, "^[ \t]*#") }

  line = Ops.get(lines, 0, "")

  return deep_copy(ret) if line == nil || line == ""

  regex = "^([^ \t]*)[ \t]*([^ \t]*)[ \t]([^ \t]*)[ \t]([^ \t]*)[ \t]([^ \t]*)[ \t]*[^ \t]*[ \t]*/usr/lib/YaST2/bin/backup_cron[ \t]*\"*[ \t]*profile[ \t]*=[ \t]*([^\"]*)\"*"
  every = :none
  cronsettings = {}
  profilename = ""

  # is cron setting supported (ranges, lists and steps are NOT supported)
  unknown_settings = false
  bad_settings = false

  if Builtins.regexpmatch(line, regex)
    minute_str = Builtins.regexpsub(line, regex, "\\1")
    hour_str = Builtins.regexpsub(line, regex, "\\2")

    Builtins.y2milestone(
      "minute_str: %1, hour_str: %2",
      minute_str,
      hour_str
    )

    if !Builtins.regexpmatch(minute_str, "^[0-9]*$") ||
        !Builtins.regexpmatch(hour_str, "^[0-9]*$")
      unknown_settings = true
    end

    Builtins.y2milestone("unknown_settings: %1", unknown_settings)
    minute = Builtins.tointeger(minute_str)
    hour = Builtins.tointeger(hour_str)

    if Ops.greater_than(hour, 23) || Ops.less_than(hour, 0) ||
        Ops.greater_than(minute, 59) ||
        Ops.less_than(minute, 0)
      bad_settings = true
    end

    day = Builtins.regexpsub(line, regex, "\\3")
    month = Builtins.regexpsub(line, regex, "\\4")
    weekday = Builtins.regexpsub(line, regex, "\\5")

    Builtins.y2milestone("line: %1", line)
    Builtins.y2milestone("day: %1", day)

    intday = 1
    intweekday = 0

    profilename = Builtins.regexpsub(line, regex, "\\6")
    Builtins.y2milestone("profilename: %1", profilename)

    if month != "*"
      # error
      unknown_settings = true
    end

    if day == "*" && weekday == "*"
      # start every day
      every = :day
    elsif day == "*"
      every = :week

      unknown_settings = true if !Builtins.regexpmatch(weekday, "^[0-9]*$")

      intweekday = Builtins.tointeger(weekday)

      if Ops.greater_than(intweekday, 7) || Ops.less_than(intweekday, 0)
        bad_settings = true
      end
    elsif weekday == "*"
      every = :month

      unknown_settings = true if !Builtins.regexpmatch(day, "^[0-9]*$")

      intday = Builtins.tointeger(day)

      if Ops.greater_than(intday, 31) || Ops.less_than(intday, 1)
        bad_settings = true
      end
    else
      unknown_settings = true
    end

    cronsettings = {
      "auto"    => true,
      "day"     => intday,
      "hour"    => hour,
      "minute"  => minute,
      "weekday" => intweekday,
      "every"   => every
    }
    Builtins.y2milestone("cronsettings: %1", cronsettings)
  else
    unknown_settings = true
  end

  if unknown_settings == true
    # %1 is profile name, %2 is filename
    Report.Warning(
      Builtins.sformat(
        _(
          "cron settings for profile %1\n" +
            "in file %2\n" +
            "are not fully supported.\n"
        ),
        profilename,
        filename
      )
    )
  end

  if bad_settings == true
    #%1 is profile name, %2 is file name
    Report.Error(
      Builtins.sformat(
        _(
          "Some time values for profile %1\n" +
            "in file %2\n" +
            "are out of range."
        ),
        profilename,
        filename
      )
    )
  end

  every != :none ?
    { "profilename" => profilename, "cronsettings" => cronsettings } :
    {}
end

- (Object) ReadCronSettings

Parse all /etc/cron.d/yast2-backup-* files and update profiles



1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
# File '../../src/modules/Backup.rb', line 1163

def ReadCronSettings
  crondir = "/etc/cron.d"
  files = Convert.convert(
    SCR.Read(path(".target.dir"), crondir),
    :from => "any",
    :to   => "list <string>"
  )

  # reset cron setings
  Builtins.foreach(@backup_profiles) do |name, opts|
    tmp = Builtins.eval(opts)
    cr = Builtins.eval(Ops.get_map(opts, :cron_settings, {}))
    Ops.set(cr, "cronfile", "")
    Ops.set(cr, "cron_changed", false)
    Ops.set(tmp, :cron_settings, Builtins.eval(cr))
    Ops.set(@backup_profiles, name, Builtins.eval(tmp))
  end 


  if files != nil && Ops.greater_than(Builtins.size(files), 0)
    # parse all /etc/cron.d/yast2-backup-* files
    Builtins.foreach(files) do |file|
      if Builtins.regexpmatch(file, "^yast2-backup-[0-9]*$") == true
        cron_index = Builtins.tointeger(
          Builtins.regexpsub(file, "yast2-backup-([0-9]*)", "\\1")
        )

        Builtins.y2milestone("cron_index: %1", cron_index)
        if Ops.greater_than(cron_index, @max_cron_index)
          @max_cron_index = cron_index
        end

        # parse cron file
        cron = ReadCronSetting(Ops.add(Ops.add(crondir, "/"), file))
        Builtins.y2milestone("parsed cron config: %1", cron)

        if cron != {} && cron != nil
          profilename = Ops.get_string(cron, "profilename", "")
          cronsettings = Builtins.eval(
            Ops.get_map(cron, "cronsettings", {})
          )

          # update profile
          if profilename != "" && cronsettings != {}
            profile = Builtins.eval(
              Ops.get(@backup_profiles, profilename, {})
            )

            Ops.set(
              cronsettings,
              "cronfile",
              Ops.add(Ops.add(crondir, "/"), file)
            )

            # merge maps - include old backup settings from read profile
            cronsettings = Builtins.union(
              Builtins.eval(Ops.get_map(profile, :cron_settings, {})),
              cronsettings
            )

            Ops.set(profile, :cron_settings, Builtins.eval(cronsettings))
            Ops.set(@backup_profiles, profilename, Builtins.eval(profile))
          end
        end
      end
    end
  end

  Builtins.y2milestone("max_cron_index: %1", @max_cron_index)

  nil
end

- (Object) ReadInstallablePackages

Read all packages available on the installation sources



2097
2098
2099
2100
2101
2102
# File '../../src/modules/Backup.rb', line 2097

def ReadInstallablePackages
  @installable_packages = GetInstallPackages()
  Builtins.y2debug("installable_packages: %1", @installable_packages)

  nil
end

- (Hash) RemovableDevices(only_writable)

Try to detect all removable devices present in the system

Parameters:

  • only_writable (Boolean)

    return only writable devices (e.g. exclude CD-ROMs)

Returns:

  • (Hash)

    Removable devices info



1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
# File '../../src/modules/Backup.rb', line 1892

def RemovableDevices(only_writable)
  ret = {}

  # detect SCSI, IDE and floppy devices
  devs = Convert.convert(
    Builtins.merge(
      Builtins.merge(
        Convert.convert(
          SCR.Read(path(".probe.scsi")),
          :from => "any",
          :to   => "list <map>"
        ),
        Convert.convert(
          SCR.Read(path(".probe.ide")),
          :from => "any",
          :to   => "list <map>"
        )
      ),
      Convert.convert(
        SCR.Read(path(".probe.floppy")),
        :from => "any",
        :to   => "list <map>"
      )
    ),
    :from => "list",
    :to   => "list <map>"
  )

  Builtins.foreach(devs) do |dev|
    if Ops.get(dev, "class_id") == 262 &&
        Ops.get_integer(dev, "sub_class_id", 0) != 0 # Mass storage device, but not a disk
      dev_name = Ops.get_string(dev, "dev_name", "")
      model = Ops.get_string(dev, "model", "")
      bus = Ops.get_string(dev, "bus", "")
      sub_class_id = Ops.get_integer(dev, "sub_class_id", 128) # default is "Storage device"
      type_symbol = :unknown

      # use non-rewinding tape device
      if Ops.greater_than(Builtins.size(dev_name), 0) && sub_class_id == 1 # check if device is tape
        parts = Builtins.splitstring(dev_name, "/")

        # add 'n' to the device name if it is missing
        # e.g. /dev/st0 (rewinding) -> /dev/nst0 (non-rewinding)
        if !Builtins.regexpmatch(
            Ops.get(parts, Ops.subtract(Builtins.size(parts), 1), ""),
            "^n"
          )
          Ops.set(
            parts,
            Ops.subtract(Builtins.size(parts), 1),
            Ops.add(
              "n",
              Ops.get(parts, Ops.subtract(Builtins.size(parts), 1), "")
            )
          )

          dev_name = Builtins.mergestring(parts, "/")

          Ops.set(dev, "dev_name", dev_name)
        end

        type_symbol = :tape
      end

      # type of device (cdrom, disk, tape...) was not detected
      type = Ops.get_locale(
        @ClassNames,
        [262, sub_class_id],
        _("Unknown device type")
      )

      # remove read only devices if it was requested
      # remove CD/DVD-ROM devices, other devices are considered as writable,
      # it doesn't check if inserted medium is writable!

      if sub_class_id == 2 && only_writable
        # CD-ROM sub class, only writable devices are requested
        # if CD device is not CD-R/RW or DVD-R/RW/RAM it is read only
        if !(Ops.get_boolean(dev, "cdr", false) ||
            Ops.get_boolean(dev, "cdrw", false) ||
            Ops.get_boolean(dev, "dvdram", false) ||
            Ops.get_boolean(dev, "dvdr", false))
          dev_name = ""
        end

        type_symbol = :cd
      end

      # predefined media sizes for device - initialize to all types
      media = deep_copy(@media_descriptions)
      preselected = nil
      user_size = 0

      if Ops.get_boolean(dev, "dvd", false)
        type = "DVD-ROM"
        type_symbol = :dvd

        dev_name = "" if only_writable
      elsif Ops.get_boolean(dev, "cdr", false) ||
          Ops.get_boolean(dev, "cdrw", false)
        # CD-R or CD-RW writer device
        type = _("CD Writer")
        type_symbol = Ops.get_boolean(dev, "cdr", false) ? :cdr : :cdrw
        media = deep_copy(@cd_media_descriptions)
        preselected = :cd700
      elsif Ops.get_boolean(dev, "dvdr", false)
        # DVD-R, DVD+R... writer device
        type = _("DVD Writer")
        type_symbol = :dvdr
      elsif Ops.get_boolean(dev, "dvdram", false)
        type = "DVD-RAM"
        type_symbol = :dvdram
      elsif Ops.get_boolean(dev, "zip", false) &&
          Ops.get_integer(dev, "sub_class_id", 0) == 3
        type = "ZIP"
        type_symbol = :zip
        media = deep_copy(@zip_media_descriptions)

        # get medium size
        geometry = Ops.get_map(dev, ["resource", "disk_log_geo"], {})
        sz = Ops.multiply(
          Ops.multiply(
            Ops.get_integer(geometry, "cylinders", 0),
            Ops.get_integer(geometry, "heads", 0)
          ),
          Ops.get_integer(geometry, "sectors", 0)
        )
        sect_sz = Ops.get_string(dev, ["size", "unit"], "") == "sectors" ?
          Ops.get_integer(dev, ["size", "y"], 512) :
          0
        raw_size = Ops.multiply(sz, sect_sz)

        # preselect medium size
        if raw_size == 96 * 64 * 32 * 512
          # this is ZIP-100
          preselected = :zip100
        elsif Ops.greater_than(raw_size, 0)
          # unknown medium, use raw size minus 1MB for file system
          preselected = :user
          user_size = Ops.subtract(raw_size, 1024 * 1024)
        end
      # floppy
      elsif Ops.get_integer(dev, "sub_class_id", 0) == 3
        type_symbol = :floppy
        media = deep_copy(@floppy_media_descriptions)
        sizes = Ops.get_list(dev, ["resource", "size"], [])
        sect_sz = 0

        Builtins.foreach(sizes) do |m|
          unit = Ops.get_string(m, "unit", "")
          if unit == "sectors"
            sect_sz = Ops.multiply(
              Ops.get_integer(m, "x", 0),
              Ops.get_integer(m, "y", 512)
            )
          end
        end 


        Builtins.y2milestone("sect_sz: %1", sect_sz)

        if Ops.greater_than(sect_sz, 0)
          if sect_sz == 2880 * 512
            # 1.44 floppy
            preselected = :fd144
          end 
          # else if (sect_sz == 1186*512)
          # 			    {
          # 				// 1.2 floppy
          # 				preselected = `fd12;
          # 			    }
        end
      end

      # volume size was'nt detected, use default value
      if preselected == nil
        preselected = :user
        user_size = @undetected_volume_size
      end

      if Ops.greater_than(Builtins.size(dev_name), 0)
        ret = Builtins.add(
          ret,
          dev_name,
          {
            "model"       => model,
            "type"        => type,
            "bus"         => bus,
            "media"       => media,
            "preselected" => preselected,
            "user_size"   => user_size,
            "type_symbol" => type_symbol
          }
        )
      end
    end
  end if Ops.greater_than(
    Builtins.size(devs),
    0
  )

  deep_copy(ret)
end

- (Object) RemoveBackupProfile(profile_name, remove_cronfile)

Remove given profile.

Parameters:

  • profile_name (String)

    name of a profile to be removed

  • remove_cronfile (Boolean)

    defines whether also the cron settings (stored in file) should be removed

Returns:

  • If the name of the profile cannot be found, return false, otherwise return true.



1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
# File '../../src/modules/Backup.rb', line 1862

def RemoveBackupProfile(profile_name, remove_cronfile)
  # return false, is there is no such profile
  return false if !Builtins.haskey(@backup_profiles, profile_name)

  # If there is some cronfile assigned to the profile, remove it too
  if remove_cronfile &&
      Ops.get(@backup_profiles, [profile_name, :cron_settings, "cronfile"]) != nil
    filename = Ops.get_string(
      @backup_profiles,
      [profile_name, :cron_settings, "cronfile"],
      ""
    )

    Builtins.y2milestone(
      "File '%1' has been marked to be removed",
      filename
    )
    @remove_cron_files = Builtins.add(@remove_cron_files, filename)
  end
  @backup_profiles = Builtins.remove(@backup_profiles, profile_name)

  true
end

- (Hash) RemoveOldArchives(name, max, multivolume)

Remove and/or rename old existing archives

Parameters:

  • name (String)

    Archive name

  • max (Fixnum)

    Maximum count of existing archives

  • multivolume (Boolean)

    Is archive archive multivolume?

Returns:

  • (Hash)

    result



2684
2685
2686
2687
2688
# File '../../src/modules/Backup.rb', line 2684

def RemoveOldArchives(name, max, multivolume)
  multivolume == true ?
    RemoveOldMultiArchives(name, max) :
    RemoveOldSingleArchives(name, max)
end

- (Hash) RemoveOldMultiArchives(name, max)

Remove and/or rename old existing multivolume archives

Parameters:

  • name (String)

    Archive name

  • max (Fixnum)

    Maximum count of existing archives

Returns:

  • (Hash)

    result



2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
# File '../../src/modules/Backup.rb', line 2433

def RemoveOldMultiArchives(name, max)
  removed = []
  renamed = {}

  return {} if name == "" || name == nil

  # check wheter older archives exist
  parts = Builtins.splitstring(name, "/")
  fname = Ops.get(parts, Ops.subtract(Builtins.size(parts), 1), "")
  dir = Builtins.mergestring(
    Builtins.remove(parts, Ops.subtract(Builtins.size(parts), 1)),
    "/"
  )

  return {} if Builtins.size(fname) == 0

  # check whether first archive already exists
  sz = Convert.to_integer(
    SCR.Read(
      path(".target.size"),
      Ops.add(Ops.add(Ops.add(dir, "/"), "01_"), fname)
    )
  )

  if Ops.less_than(sz, 0)
    # file doesn't exist, success
    Builtins.y2milestone("First multivolume archive doesn't exist")
    return {}
  else
    Builtins.y2milestone("First multivolume archive already exists")
  end

  command = Ops.add(
    Ops.add(Ops.add(Ops.add("/bin/ls -1 -t ", dir), "/*-*_"), fname),
    " 2> /dev/null"
  )
  result = Convert.to_map(SCR.Execute(path(".target.bash_output"), command))
  files = Builtins.splitstring(Ops.get_string(result, "stdout", ""), "\n")

  mv_dates = []

  # filter files with date - use regexp
  multi = []
  Builtins.foreach(files) do |file|
    if Builtins.regexpmatch(
        file,
        Ops.add(
          Ops.add(
            Ops.add(Ops.add("^", dir), "/[0-9]{14}-[0-9][0-9]+_"),
            fname
          ),
          "$"
        )
      )
      multi = Builtins.add(multi, file)

      date = Builtins.regexpsub(
        file,
        Ops.add(
          Ops.add(
            Ops.add(Ops.add("^", dir), "/([0-9]{14})-[0-9][0-9]+_"),
            fname
          ),
          "$"
        ),
        "\\1"
      )

      if !Builtins.contains(mv_dates, date)
        mv_dates = Builtins.add(mv_dates, date)
      end
    end
  end 

  files = deep_copy(multi)

  Builtins.y2milestone("Old archives: %1", files)
  Builtins.y2milestone("Old archive dates: %1", mv_dates)

  if Ops.greater_or_equal(Builtins.size(mv_dates), max) &&
      Ops.greater_or_equal(max, 0)
    # remove the old archives
    while Ops.greater_or_equal(Builtins.size(mv_dates), max)
      oldarchivedate = Ops.get_string(
        mv_dates,
        Ops.subtract(Builtins.size(mv_dates), 1),
        "__DUMMY__"
      )

      Builtins.y2milestone("removing archives with date %1", oldarchivedate)

      Builtins.foreach(files) do |fn|
        if Builtins.regexpmatch(
            fn,
            Ops.add(
              Ops.add(
                Ops.add(
                  Ops.add(Ops.add(Ops.add("^", dir), "/"), oldarchivedate),
                  "-[0-9]+_"
                ),
                fname
              ),
              "$"
            )
          )
          # remove old archive
          command = Ops.add("/bin/rm -f ", fn)
          Builtins.y2milestone("Removing old volume: %1", fn)

          # update NFS archive name
          if @target_type == :nfs
            fn = Ops.add(
              Ops.add(Ops.add(@nfsserver, ":"), @nfsexport),
              Builtins.substring(fn, Builtins.size(@nfsmount))
            )
          end

          removed = Builtins.add(removed, fn)
          SCR.Execute(path(".target.bash_output"), command)
        end
      end 


      # remove old XML profile
      oldXML2 = Ops.add(
        Ops.add(
          Ops.add(Ops.add(Ops.add(dir, "/"), oldarchivedate), "-"),
          GetBaseName(fname)
        ),
        ".xml"
      )
      command = Ops.add("/bin/rm -f ", oldXML2)

      # update NFS archive name
      if @target_type == :nfs
        oldXML2 = Ops.add(
          Ops.add(Ops.add(@nfsserver, ":"), @nfsexport),
          Builtins.substring(oldXML2, Builtins.size(@nfsmount))
        )
      end

      removed = Builtins.add(removed, oldXML2)
      result = Convert.to_map(
        SCR.Execute(path(".target.bash_output"), command)
      )

      mv_dates = Builtins.remove(
        mv_dates,
        Ops.subtract(Builtins.size(mv_dates), 1)
      )
    end
  end

  # get creation time of the first part of the archive
  stat = Convert.to_map(
    SCR.Read(
      path(".target.stat"),
      Ops.add(Ops.add(Ops.add(dir, "/"), "01_"), fname)
    )
  )
  ctime = Ops.get_integer(stat, "ctime", 0)
  ctime_str = SecondsToDateString(ctime)

  command = Ops.add(
    Ops.add(Ops.add(Ops.add("/bin/ls -1 -t ", dir), "/*_"), fname),
    " 2> /dev/null"
  )
  result = Convert.to_map(SCR.Execute(path(".target.bash_output"), command))
  files = Builtins.splitstring(Ops.get_string(result, "stdout", ""), "\n")
  files = Builtins.filter(files) do |file|
    Builtins.regexpmatch(
      file,
      Ops.add(Ops.add(Ops.add(Ops.add("^", dir), "/[0-9]+_"), fname), "$")
    )
  end
  Builtins.y2milestone("Existing volumes: %1", files)

  Builtins.foreach(files) do |volume|
    vol_parts = Builtins.splitstring(volume, "/")
    vol_fname = Ops.get(
      vol_parts,
      Ops.subtract(Builtins.size(vol_parts), 1),
      ""
    )
    vol_dir = Builtins.mergestring(
      Builtins.remove(vol_parts, Ops.subtract(Builtins.size(vol_parts), 1)),
      "/"
    )
    # rename existing archive
    from = Ops.add(Ops.add(vol_dir, "/"), vol_fname)
    to = Ops.add(
      Ops.add(Ops.add(Ops.add(vol_dir, "/"), ctime_str), "-"),
      vol_fname
    )
    command = Ops.add(Ops.add(Ops.add("/bin/mv -f ", from), " "), to)
    result = Convert.to_map(
      SCR.Execute(path(".target.bash_output"), command)
    )
    # update NFS archive name
    if @target_type == :nfs
      from = Ops.add(
        Ops.add(Ops.add(@nfsserver, ":"), @nfsexport),
        Builtins.substring(from, Builtins.size(@nfsmount))
      )
      to = Ops.add(
        Ops.add(Ops.add(@nfsserver, ":"), @nfsexport),
        Builtins.substring(to, Builtins.size(@nfsmount))
      )
      Builtins.y2debug("NFS archive, from: %1, to: %2", from, to)
    end
    Ops.set(renamed, from, to)
    Builtins.y2milestone("renamed volume %1", volume)
  end 


  # rename autoinstallation profile
  oldXML = Ops.add(Ops.add(Ops.add(dir, "/"), GetBaseName(name)), ".xml")
  newXML = Ops.add(
    Ops.add(
      Ops.add(Ops.add(Ops.add(dir, "/"), ctime_str), "-"),
      GetBaseName(fname)
    ),
    ".xml"
  )

  command = Ops.add(Ops.add(Ops.add("/bin/mv -f ", oldXML), " "), newXML)
  result = Convert.to_map(SCR.Execute(path(".target.bash_output"), command))

  # update NFS archive name
  if @target_type == :nfs
    oldXML = Ops.add(
      Ops.add(Ops.add(@nfsserver, ":"), @nfsexport),
      Builtins.substring(oldXML, Builtins.size(@nfsmount))
    )
    newXML = Ops.add(
      Ops.add(Ops.add(@nfsserver, ":"), @nfsexport),
      Builtins.substring(newXML, Builtins.size(@nfsmount))
    )
    Builtins.y2debug("NFS archive, oldXML: %1, newXML: %2", oldXML, newXML)
  end

  Ops.set(renamed, oldXML, newXML)

  { "removed" => removed, "renamed" => renamed }
end

- (Hash) RemoveOldSingleArchives(name, max)

Remove and/or rename old existing single archives

Parameters:

  • name (String)

    Archive name

  • max (Fixnum)

    Maximum count of existing archives

Returns:

  • (Hash)

    result



2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
# File '../../src/modules/Backup.rb', line 2248

def RemoveOldSingleArchives(name, max)
  removed = []
  renamed = {}

  return {} if name == "" || name == nil

  # check whether archive already exists
  sz = Convert.to_integer(SCR.Read(path(".target.size"), name))

  if Ops.less_than(sz, 0)
    # file doesn't exist, success
    Builtins.y2milestone("Archive doesn't exist")
    return {}
  end

  # check wheter older archives exist
  parts = Builtins.splitstring(name, "/")
  fname = Ops.get(parts, Ops.subtract(Builtins.size(parts), 1), "")
  dir = Builtins.mergestring(
    Builtins.remove(parts, Ops.subtract(Builtins.size(parts), 1)),
    "/"
  )

  return {} if Builtins.size(fname) == 0

  command = Ops.add(
    Ops.add(Ops.add(Ops.add("/bin/ls -1 -t ", dir), "/*-"), fname),
    " 2> /dev/null"
  )
  result = Convert.to_map(SCR.Execute(path(".target.bash_output"), command))
  files = Builtins.splitstring(Ops.get_string(result, "stdout", ""), "\n")

  mv_dates = []

  # filter files with date - use regexp
  files = Builtins.filter(files) do |file|
    Builtins.regexpmatch(
      file,
      Ops.add(
        Ops.add(Ops.add(Ops.add("^", dir), "/[0-9]{14}-"), fname),
        "$"
      )
    )
  end

  Builtins.y2milestone("Old archives: %1", files)

  if Ops.greater_than(Builtins.size(files), 0) &&
      Ops.greater_or_equal(Builtins.size(files), max) &&
      Ops.greater_or_equal(max, 0)
    # remove the old archives
    while Ops.greater_than(Builtins.size(files), 0) &&
        Ops.greater_or_equal(Builtins.size(files), max)
      oldarchive = Ops.get(
        files,
        Ops.subtract(Builtins.size(files), 1),
        "__DUMMY__"
      )

      # remove old archive
      command = Ops.add("/bin/rm -f ", oldarchive)
      Builtins.y2milestone("Removing old archive: %1", oldarchive)
      result = Convert.to_map(
        SCR.Execute(path(".target.bash_output"), command)
      )

      removedoldarchive = oldarchive

      # update NFS archive name
      if @target_type == :nfs
        removedoldarchive = Ops.add(
          Ops.add(Ops.add(@nfsserver, ":"), @nfsexport),
          Builtins.substring(oldarchive, Builtins.size(@nfsmount))
        )
      end

      removed = Builtins.add(removed, removedoldarchive)

      # remove old XML profile
      oldXML2 = Ops.add(
        Ops.add(Ops.add(dir, "/"), GetBaseName(oldarchive)),
        ".xml"
      )
      command = Ops.add("/bin/rm -f ", oldXML2)
      result = Convert.to_map(
        SCR.Execute(path(".target.bash_output"), command)
      )

      # update NFS archive name
      if @target_type == :nfs
        oldXML2 = Ops.add(
          Ops.add(Ops.add(@nfsserver, ":"), @nfsexport),
          Builtins.substring(oldXML2, Builtins.size(@nfsmount))
        )
      end

      removed = Builtins.add(removed, oldXML2)

      files = Builtins.remove(files, Ops.subtract(Builtins.size(files), 1))
    end
  end

  stat = Convert.to_map(SCR.Read(path(".target.stat"), name))
  ctime = Ops.get_integer(stat, "ctime", 0)
  ctime_str = SecondsToDateString(ctime)

  # rename existing archive
  command = Ops.add(
    Ops.add(
      Ops.add(
        Ops.add(
          Ops.add(Ops.add(Ops.add("/bin/mv -f ", name), " "), dir),
          "/"
        ),
        ctime_str
      ),
      "-"
    ),
    fname
  )
  result = Convert.to_map(SCR.Execute(path(".target.bash_output"), command))

  old_name = name
  new_name = Ops.add(
    Ops.add(Ops.add(Ops.add(dir, "/"), ctime_str), "-"),
    fname
  )

  # update NFS archive name
  if @target_type == :nfs
    old_name = Ops.add(
      Ops.add(Ops.add(@nfsserver, ":"), @nfsexport),
      Builtins.substring(name, Builtins.size(@nfsmount))
    )
    new_name = Ops.add(
      Ops.add(Ops.add(@nfsserver, ":"), @nfsexport),
      Builtins.substring(new_name, Builtins.size(@nfsmount))
    )
    Builtins.y2debug(
      "NFS archive, old_name: %1, new_name: %2",
      old_name,
      new_name
    )
  end


  #    renamed[name] = dir + "/" + ctime_str + "-" + fname;
  Ops.set(renamed, old_name, new_name)

  # rename autoinstallation profile
  oldXML = Ops.add(Ops.add(Ops.add(dir, "/"), GetBaseName(name)), ".xml")
  newXML = Ops.add(
    Ops.add(
      Ops.add(Ops.add(Ops.add(dir, "/"), ctime_str), "-"),
      GetBaseName(fname)
    ),
    ".xml"
  )

  command = Ops.add(Ops.add(Ops.add("/bin/mv -f ", oldXML), " "), newXML)
  result = Convert.to_map(SCR.Execute(path(".target.bash_output"), command))

  # update NFS archive name
  if @target_type == :nfs
    oldXML = Ops.add(
      Ops.add(Ops.add(@nfsserver, ":"), @nfsexport),
      Builtins.substring(oldXML, Builtins.size(@nfsmount))
    )
    newXML = Ops.add(
      Ops.add(Ops.add(@nfsserver, ":"), @nfsexport),
      Builtins.substring(newXML, Builtins.size(@nfsmount))
    )
    Builtins.y2debug("NFS archive, oldXML: %1, newXML: %2", oldXML, newXML)
  end

  Ops.set(renamed, oldXML, newXML)

  { "removed" => removed, "renamed" => renamed }
end

- (Object) RestoreDefaultSettings

Restore the default global settings.



1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
# File '../../src/modules/Backup.rb', line 1695

def RestoreDefaultSettings
  # setup global settings according to defaults
  @archive_name = @default_archive_name
  @description = @default_description
  @archive_type = @default_archive_type
  @multi_volume = @default_multi_volume
  @volume_size = @default_volume_size
  @user_volume_size = @default_user_volume_size
  @user_volume_unit = @default_user_volume_unit
  @do_search = @default_search
  @backup_all_rpms_content = @default_all_rpms_content
  @system = @default_system
  @display = @default_display
  @do_md5_test = @default_do_md5_test
  @default_dir = deep_copy(@default_default_dir)
  @dir_list = deep_copy(@default_dir_list)
  @fs_exclude = deep_copy(@default_fs_exclude)
  @detected_fs = deep_copy(@default_detected_fs)
  @detected_ext2 = deep_copy(@default_detected_ext2)
  @ext2_backup = deep_copy(@default_ext2_backup)
  @backup_pt = @default_backup_pt
  @backup_all_ext2 = @default_backup_all_ext2
  @backup_none_ext2 = @default_backup_none_ext2
  @backup_selected_ext2 = @default_backup_selected_ext2
  @unselected_files = deep_copy(@default_unselected_files)
  #    all_entered_dirs =	eval( default_all_entered_dirs );
  #    selected_directories = eval( default_selected_directories );
  #    LVMsnapshot = default_LVMsnapshot;
  #    testonly = default_testonly;
  @autoprofile = @default_autoprofile
  #    systembackup = default_systembackup;
  @perms = @default_perms
  @nfsserver = @default_nfsserver
  @nfsexport = @default_nfsexport
  @target_type = @default_target_type
  #    target_devices_options = eval(default_target_devices_options);
  @mail_summary = @default_mail_summary
  @tmp_dir = @default_tmp_dir
  @regexp_list = deep_copy(@default_regexp_list)
  @include_dirs = [@default_include_dir]

  @selected_files = Builtins.eval(@default_selected_files)
  @backup_files = Builtins.eval(@default_backup_files)

  @backup_helper_scripts = []

  @selected_profile = nil

  @cron_settings = {}

  nil
end

- (Object) RestoreMtab

Restores the original content of /etc/mtab



562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
# File '../../src/modules/Backup.rb', line 562

def RestoreMtab
  # nothing to restore from
  if !FileUtils.Exists(@temporary_mtab_file)
    Builtins.y2error(
      "There is no mtab file (%1) to restore",
      @temporary_mtab_file
    )
    return false
  end

  Builtins.y2milestone(
    "Restoring backup of %1 from %2",
    @mtab_file,
    @temporary_mtab_file
  )

  # restoring by `cat` - the original file attributes are kept intact
  if Convert.to_integer(
      SCR.Execute(
        path(".target.bash"),
        Builtins.sformat(
          "cat '%1' > '%2'",
          String.Quote(@temporary_mtab_file),
          String.Quote(@mtab_file)
        )
      )
    ) != 0
    Builtins.y2error(
      "Cannot restore content of %1 to %2",
      @temporary_mtab_file,
      @mtab_file
    )
    return false
  end

  Builtins.y2milestone(
    "Current %1 file contains\n---\n%2\n---",
    @mtab_file,
    SCR.Execute(
      path(".target.bash_output"),
      Builtins.sformat("cat '%1'", String.Quote(@mtab_file))
    )
  )

  # cleaning up
  if Convert.to_integer(
      SCR.Execute(
        path(".target.bash"),
        Builtins.sformat("rm -f '%1'", @temporary_mtab_file)
      )
    ) != 0
    Builtins.y2error(
      "Cannot remove temporary mtab file %1",
      @temporary_mtab_file
    )
    return false
  end

  true
end

- (Object) RestoreSettingsFromBackupProfile(profile_name)

Restore the global settings from a given backup profile.

Parameters:

  • profile_name (String)

    name of a profile to be used

Returns:

  • If the name of the profile cannot be found, return false, otherwise return true.



1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
# File '../../src/modules/Backup.rb', line 1511

def RestoreSettingsFromBackupProfile(profile_name)
  # return false, is there is no such profile
  return false if !Builtins.haskey(@backup_profiles, profile_name)

  # get the profile data
  profile = Ops.get(@backup_profiles, profile_name)

  # editing archive instead of adding new one
  @profile_is_new_one = false

  # setup global settings according to profile
  # TODO: check, if all settings are valid
  @archive_name = Ops.get_string(
    profile,
    :archive_name,
    @default_archive_name
  )
  @description = Ops.get_string(profile, :description, @default_description)
  @archive_type = Ops.get_symbol(
    profile,
    :archive_type,
    @default_archive_type
  )
  @multi_volume = Ops.get_boolean(
    profile,
    :multi_volume,
    @default_multi_volume
  )
  @volume_size = Ops.get_symbol(profile, :volume_size, @default_volume_size)
  @user_volume_size = Ops.get_string(
    profile,
    :user_volume_size,
    @default_user_volume_size
  )
  @user_volume_unit = Ops.get_symbol(
    profile,
    :user_volume_unit,
    @default_user_volume_unit
  )
  @do_search = Ops.get_boolean(profile, :search, @default_search)
  @backup_all_rpms_content = Ops.get_boolean(
    profile,
    :all_rpms_content,
    @default_all_rpms_content
  )
  @system = Ops.get_boolean(profile, :system, @default_system)
  @display = Ops.get_boolean(profile, :display, @default_display)
  @do_md5_test = Ops.get_boolean(
    profile,
    :do_md5_test,
    @default_do_md5_test
  )
  @default_dir = Convert.convert(
    Ops.get(profile, :default_dir, @default_default_dir),
    :from => "any",
    :to   => "list <string>"
  )

  #    dir_list =		profile[ `dir_list ]:		default_dir_list;

  read_dir_list = Convert.convert(
    Ops.get(profile, :dir_list, @default_dir_list),
    :from => "any",
    :to   => "list <string>"
  )

  # convert list of items to list of strings
  if Ops.is(read_dir_list, "list <string>")
    @dir_list = Convert.convert(
      read_dir_list,
      :from => "any",
      :to   => "list <string>"
    )
  elsif Ops.is(read_dir_list, "list <term>")
    # convert dir list from the old format
    new_dir_list = []

    Builtins.foreach(
      Convert.convert(read_dir_list, :from => "any", :to => "list <term>")
    ) do |i|
      tmp_id = Ops.get_term(i, 0)
      if tmp_id != nil
        tmp_d = Ops.get_string(tmp_id, 0)

        new_dir_list = Builtins.add(new_dir_list, tmp_d) if tmp_d != nil
      end
    end 


    @dir_list = deep_copy(new_dir_list)
  else
    Builtins.y2warning(
      "Excluded directories - unsupported data type, value is %1",
      read_dir_list
    )
  end

  @fs_exclude = Convert.convert(
    Ops.get(profile, :fs_exclude, @default_fs_exclude),
    :from => "any",
    :to   => "list <string>"
  )
  @detected_fs = Convert.convert(
    Ops.get(profile, :detected_fs, @default_detected_fs),
    :from => "any",
    :to   => "list <string>"
  )
  @detected_ext2 = Convert.convert(
    Ops.get(profile, :detected_ext2, @default_detected_ext2),
    :from => "any",
    :to   => "list <map <string, any>>"
  )
  @ext2_backup = Convert.convert(
    Ops.get(profile, :ext2_backup, @default_ext2_backup),
    :from => "any",
    :to   => "list <term>"
  )
  @backup_pt = Ops.get_boolean(profile, :backup_pt, @default_backup_pt)
  @backup_all_ext2 = Ops.get_boolean(
    profile,
    :backup_all_ext2,
    @default_backup_all_ext2
  )
  @backup_none_ext2 = Ops.get_boolean(
    profile,
    :backup_none_ext2,
    @default_backup_none_ext2
  )
  @backup_selected_ext2 = Ops.get_boolean(
    profile,
    :backup_selected_ext2,
    @default_backup_selected_ext2
  )
  @unselected_files = Convert.convert(
    Ops.get(profile, :unselected_files, @default_unselected_files),
    :from => "any",
    :to   => "list <string>"
  )
  #    all_entered_dirs =	profile[ `all_entered_dirs ]:	default_all_entered_dirs;
  #    selected_directories = profile[ `selected_directories ]:	default_selected_directories;
  #    LVMsnapshot =	profile[ `LVMsnapshot ]:	default_LVMsnapshot;
  #    testonly =		profile[ `testonly ]:		default_testonly;
  @autoprofile = Ops.get_boolean(
    profile,
    :autoprofile,
    @default_autoprofile
  )
  #    systembackup =	profile[ `systembackup ]:	default_systembackup;
  @perms = Ops.get_boolean(profile, :perms, @default_perms)
  @nfsserver = Ops.get_string(profile, :nfsserver, @default_nfsserver)
  @nfsexport = Ops.get_string(profile, :nfsexport, @default_nfsexport)
  @target_type = Ops.get_symbol(profile, :target_type, @default_target_type)
  #    target_device =	profile[ `target_device ]:	default_target_device;
  #    target_devices_options = profile[ `target_devices_options ]:	default_target_devices_options;
  @mail_summary = Ops.get_boolean(
    profile,
    :mail_summary,
    @default_mail_summary
  )
  @tmp_dir = Ops.get_string(profile, :tmp_dir, @default_tmp_dir)
  @regexp_list = Convert.convert(
    Ops.get(profile, :regexp_list, @default_regexp_list),
    :from => "any",
    :to   => "list <string>"
  )
  @include_dirs = Convert.convert(
    Ops.get(profile, :include_dirs) { [@default_include_dir] },
    :from => "any",
    :to   => "list <string>"
  )

  @selected_files = deep_copy(@default_selected_files)
  @backup_files = deep_copy(@default_backup_files)

  @selected_profile = profile_name

  @backup_helper_scripts = Ops.get_list(profile, :backup_helper_scripts, [])

  @cron_settings = Ops.get_map(profile, :cron_settings, {})

  true
end

- (Object) StoreSettingsToBackupProfile(profile_name)

Take the current profile information and store it into a given profile. If the profile already exists, it will be overwritten.

Parameters:

  • profile_name (String)

    name of a profile to be stored into



1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
# File '../../src/modules/Backup.rb', line 1457

def StoreSettingsToBackupProfile(profile_name)
  new_profile = {
    :archive_name          => @archive_name,
    :description           => @description,
    :archive_type          => @archive_type,
    :multi_volume          => @multi_volume,
    :volume_size           => @volume_size,
    :user_volume_size      => @user_volume_size,
    :user_volume_unit      => @user_volume_unit,
    :search                => @do_search,
    :all_rpms_content      => @backup_all_rpms_content,
    :system                => @system,
    :display               => @display,
    :do_md5_test           => @do_md5_test,
    :default_dir           => @default_dir,
    :dir_list              => @dir_list,
    :fs_exclude            => @fs_exclude,
    :regexp_list           => @regexp_list,
    :include_dirs          => @include_dirs,
    :detected_fs           => @detected_fs,
    :detected_ext2         => @detected_ext2,
    :ext2_backup           => @ext2_backup,
    :backup_pt             => @backup_pt,
    :backup_all_ext2       => @backup_all_ext2,
    :backup_none_ext2      => @backup_none_ext2,
    :backup_selected_ext2  => @backup_selected_ext2,
    :unselected_files      => @unselected_files,
    #	`all_entered_dirs	: all_entered_dirs,
    #	`selected_directories	: selected_directories,
    #	`LVMsnapshot		: LVMsnapshot,
    #	`testonly		: testonly,
    :autoprofile           => @autoprofile,
    #	`systembackup		: systembackup,
    :perms                 => @perms,
    :nfsserver             => @nfsserver,
    :nfsexport             => @nfsexport,
    :mail_summary          => @mail_summary,
    :tmp_dir               => @tmp_dir,
    :target_type           => @target_type,
    #	`target_device		: target_device,
    #	`target_devices_options	: target_devices_options,
    :backup_helper_scripts => @backup_helper_scripts,
    :cron_settings         => @cron_settings
  }

  # add the new profile
  Ops.set(@backup_profiles, profile_name, new_profile)

  nil
end

- (Boolean) WriteBackupProfiles

Write the backup profiles to a file - hardcoded configuration_filename.

Returns:

  • (Boolean)

    true if the write operation was successful.



1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
# File '../../src/modules/Backup.rb', line 1420

def WriteBackupProfiles
  # update cron setting
  WriteCronSettings()

  profiles_file = @configuration_filename
  if !SCR.Write(path(".target.ycp"), profiles_file, @backup_profiles)
    Builtins.y2error("Unable to write profiles into a file")
    # TRANSLATORS: An error popup message
    #		%1 is the file name
    Popup.Error(
      Builtins.sformat(
        _(
          "Could not store profiles to the file %1.\nThe profile changes will be lost."
        ),
        profiles_file
      )
    )
    return false
  end

  Builtins.foreach(@remove_cron_files) do |filename|
    if filename != ""
      Builtins.y2milestone("Removing file: '%1'", filename)
      if !Convert.to_boolean(SCR.Execute(path(".target.remove"), filename))
        Builtins.y2warning("Cannot remove cron file '%1'", filename)
      end
    end
  end

  true
end

- (Object) WriteCronSettings

Write cron settings from profiles to /etc/cron.d/yast2-backup-* files



1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
# File '../../src/modules/Backup.rb', line 1339

def WriteCronSettings
  Builtins.y2milestone("backup_profiles: %1", @backup_profiles)

  cron_settings_changed = false
  cron_is_needed = false

  # write cron files
  Builtins.foreach(@backup_profiles) do |name, opts|
    # cron file content
    setting = CreateCronSetting(name)
    cron_file = Ops.get_string(opts, [:cron_settings, "cronfile"], "")
    Builtins.y2milestone("name: %1", name)
    Builtins.y2milestone("setting: %1", setting)
    Builtins.y2milestone(
      "cron_settings: %1",
      Ops.get_map(opts, :cron_settings, {})
    )
    if setting != "" && setting != nil
      # is already cron file existing?
      if Builtins.size(cron_file) == 0
        # no, create new file
        @max_cron_index = Ops.add(@max_cron_index, 1)
        cron_file = Builtins.sformat(
          "/etc/cron.d/yast2-backup-%1",
          @max_cron_index
        )

        # remember new cron file name
        Ops.set(
          @backup_profiles,
          [name, :cron_settings, "cronfile"],
          cron_file
        )
      end

      SCR.Write(path(".target.string"), cron_file, setting)
      Builtins.y2milestone("Created file: %1", cron_file)

      cron_settings_changed = true
      cron_is_needed = true
    elsif Ops.greater_than(Builtins.size(cron_file), 0) &&
        Ops.get_boolean(opts, [:cron_settings, "auto"], false) == false
      # remove existing cron file
      SCR.Execute(path(".target.bash"), Ops.add("/bin/rm -f ", cron_file))
      Builtins.y2milestone("removed old cron file: %1", cron_file)

      cron_settings_changed = true
    end
    # mark saved value as unchanged
    prof = Builtins.eval(Ops.get(@backup_profiles, name, {}))
    cron_s = Builtins.eval(Ops.get_map(prof, :cron_settings, {}))
    Ops.set(cron_s, "cron_changed", false)
    Ops.set(prof, :cron_settings, Builtins.eval(cron_s))
    Ops.set(@backup_profiles, name, Builtins.eval(prof))
  end 


  # Cron needs to be restarted for changes to take effect
  # bugzilla #285442
  if cron_settings_changed
    # running
    if Service.Status("cron") == 0
      # restart it only
      Service.Restart("cron") 

      # not running but needed
    elsif cron_is_needed
      # not enabled, enable it
      Service.Enable("cron") if !Service.Enabled("cron")
      # and start it
      Service.Start("cron")
    end
  end

  nil
end

- (Hash) WriteProfile(volumes)

Write autoinstallation profile to file autoinst.xml to the same directory as archive

Parameters:

  • volumes (Array<String>)

    list of created archives (it is written to the XML profile as restoration source)

Returns:

  • (Hash)

    map $[ “result” : boolean (true on success), “profile” : string (profile file name) ]



840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
# File '../../src/modules/Backup.rb', line 840

def WriteProfile(volumes)
  volumes = deep_copy(volumes)
  archive = Ops.add(
    @target_type == :nfs && @nfsmount != nil ? Ops.add(@nfsmount, "/") : "",
    @archive_name
  )

  pos = Builtins.findlastof(archive, "/")
  dir = ""
  file = archive

  if pos != nil && Ops.greater_than(pos, 0)
    dir = Ops.add(Builtins.substring(archive, 0, pos), "/")
    file = Builtins.substring(archive, Ops.add(pos, 1))
  end

  directory = dir

  Builtins.y2debug("dir: %1, file: %2", dir, file)

  prefix = "file://"

  # change prefix according to volume size or archive destination
  # check if file is written to NFS file system
  fs = Convert.convert(
    SCR.Read(path(".proc.mounts")),
    :from => "any",
    :to   => "list <map>"
  )

  fs = Builtins.filter(fs) do |info|
    Ops.get_string(info, "vfstype", "") == "nfs"
  end

  Builtins.foreach(fs) do |info|
    mountpoint = Ops.get_string(info, "file", "")
    spec = Ops.get_string(info, "spec", "")
    server = Builtins.substring(spec, 0, Builtins.findfirstof(spec, ":"))
    remdir = Builtins.substring(
      spec,
      Ops.add(Builtins.findfirstof(spec, ":"), 1)
    )
    if mountpoint != "" && spec != ""
      if Builtins.substring(archive, 0, Builtins.size(mountpoint)) == mountpoint
        Builtins.y2milestone(
          "NFS server: %1, directory: %2",
          server,
          remdir
        )

        prefix = "nfs://"
        dir = Ops.add(Ops.add(Ops.add(server, ":"), remdir), "/")
      end
    end
  end 


  # set prefix according to volume size
  if prefix == "" && @multi_volume == true
    if @volume_size == :fd144 || @volume_size == :fd12
      prefix = "fd://"
      dir = "/"
    elsif @volume_size == :cd700 || @volume_size == :cd650
      prefix = "cd://"
      dir = "/"
    end
  end

  Builtins.y2debug("backup write profile: prefix=%1, dir=%2", prefix, dir)

  volumestrings = []

  if Ops.greater_than(Builtins.size(volumes), 0)
    Builtins.foreach(volumes) do |volfile|
      f = volfile
      pos2 = Builtins.findlastof(volfile, "/")
      if pos2 != nil && Ops.greater_than(pos2, 0)
        f = Builtins.substring(volfile, Ops.add(pos2, 1))
      end
      volumestrings = Builtins.add(
        volumestrings,
        Ops.add(Ops.add(prefix, dir), f)
      )
    end
  else
    volumestrings = [Ops.add(Ops.add(prefix, dir), file)]
  end

  restore = { "archives" => volumestrings }

  # add default selection - select all packages to restore
  packages_sel = {}

  Builtins.foreach(@selected_files) do |pkg, info|
    # get package base name
    if pkg != ""
      pkg = Builtins.regexpsub(pkg, "(.*)-.*-.*", "\\1")
    else
      pkg = "_NoPackage_"
    end
    Ops.set(packages_sel, pkg, { "sel_type" => "X" })
  end 


  directory = "/" if directory == ""

  # store profile to this file
  profilefile = Ops.add(
    Ops.add(directory, GetBaseName(@archive_name)),
    ".xml"
  )
  # (tapes)
  removable_device = false
  if Builtins.regexpmatch(archive, "^/dev/")
    # save xml to a temporary file
    removable_device = true
    profilefile = Ops.add(
      Convert.to_string(SCR.Read(path(".target.tmpdir"))),
      "/backup-profile.xml"
    )
  end

  Builtins.y2debug("Profile location: %1", profilefile)

  # create and save autoinstallation profile
  res = CloneSystem(profilefile, ["lan"], "restore", restore)
  Builtins.y2milestone("Clone result: %1", res)

  # tar that temporary file to a device
  if removable_device
    command = Builtins.sformat(
      "cd '%1'; /bin/tar -cf '%2' 'backup-profile.xml'",
      String.Quote(Convert.to_string(SCR.Read(path(".target.tmpdir")))),
      String.Quote(@archive_name)
    )
    run = Convert.to_map(SCR.Execute(path(".target.bash_output"), command))
    Builtins.y2milestone("Running command %1 -> %2", command, run)
    res = false if Ops.get_integer(run, "exit", -1) != 0
    profilefile = @archive_name
  end

  if @target_type == :nfs
    pos = Builtins.findlastof(@archive_name, "/")
    nm = pos != nil && Ops.greater_than(pos, 0) ?
      Builtins.substring(@archive_name, 0, pos) :
      ""

    Builtins.y2debug("pos: %1, nm: %2", pos, nm)

    # update XML location if it was stored on NFS
    profilefile = Ops.add(
      Ops.add(
        Ops.add(
          Ops.add(
            Ops.add(Ops.add(Ops.add(@nfsserver, ":"), @nfsexport), "/"),
            nm
          ),
          Ops.greater_than(Builtins.size(nm), 0) ? "/" : ""
        ),
        GetBaseName(@archive_name)
      ),
      ".xml"
    )
    Builtins.y2debug("Updated profile location: %1", profilefile)
  end

  { "result" => res, "profile" => profilefile }
end