Class: Yast::RestoreClass
- Inherits:
-
Module
- Object
- Module
- Yast::RestoreClass
- Defined in:
- ../../src/modules/Restore.rb
Instance Method Summary (collapse)
-
- (Boolean) ActivateBootloader
Activate boot loader configuration if requested.
-
- (Hash) AddVolume(file)
Add next volume - check volume, copy volume to the temp.
-
- (Object) CheckAndPrepareNFS(parsed_url)
Checks whether the portmapper service is installed and started.
-
- (Hash) CheckVolume(filename, num)
Check if volume number in archive is equal to expected volume number.
-
- (Object) ClearInstalledPackagesCache
Clear cache of installed packages.
-
- (Hash) CopyVolume(filename, num)
Copy volume to the local temporary directory.
-
- (Hash) Export
Dump the restore settings to a single map - for use by autoinstallation.
-
- (Hash) GetActualInstalledPackages
Return installed packages.
-
- (String) GetArchiveComment
Return user comment stored in archive.
-
- (String) GetArchiveDate
Return date when backup archive was created.
-
- (Array) GetArchiveFiles
Return list of files in the backup archive.
-
- (String) GetArchiveHostname
Return host name of machine on which backup archive was created.
-
- (Hash) GetArchiveInfo
Return restore configuration.
-
- (Hash) GetArchiveInstalledPackages
Return map with packages installed at backup time (form is $[“package name” : “version”]).
-
- (String) GetArchiveName
Return name of backup archive.
-
- (Hash) GetExtraPackages
Return extra packages (packages which are installed at restore time, but at restore time they are installed).
-
- (String) GetInputName
Return name of backup archive.
-
- (Hash) GetMismatchedPackages
Return packages which have different version at backup archive and in system.
-
- (Hash) GetMissingPackages
Return missing packages (packages which were installed at backup time, but at restore time they are not installed).
-
- (Hash) GetSelectedPackages
Returns selected packages (even partially).
-
- (Boolean) Import(settings)
Get all restore settings - for use by autoinstallation.
-
- (Object) IsMultiVolume
Selected archive has more parts.
- - (Object) main
-
- (Object) Modified
Return modified flag.
-
- (Hash) mountCD(cdindex)
Access to file on CD.
-
- (Hash) mountDevice(device)
Mount device.
-
- (Hash) mountFloppy(fdindex)
Access to file on floppy.
-
- (Hash) MountInput(input)
Mount input source.
-
- (Hash) mountNFS(server, file)
Access to file on NFS server.
- - (Object) ProposeRPMdbRestoration
-
- (Boolean) Read(input)
Read contents of archive.
-
- (Hash) ReadActualInstalledPackages
Read installed packages.
-
- (Hash) ReadNextVolume(input)
Read next volume of multi volume archive.
-
- (String) RemoveShortCut(scut)
Remove shortcut mark from string.
-
- (Object) ResetAll
Clear all settings (archive and list of installed packages).
-
- (Object) ResetArchiveSelection
Clear all archive settings.
- - (Object) RPMrestorable
-
- (Object) Set(settings)
Set settings.
- - (Object) SetModified
-
- (Object) SetRestoreSelection(pkgname, selection)
Change restore selection of package.
-
- (Object) SetSelectionProperty(settings)
Set selection in _auto client and display properties of archive.
-
- (String) Summary
Create restore configuration summary.
-
- (Boolean) TestAllVolumes
Test all volumes together.
-
- (Fixnum) TotalFilesToRestore
Return number of files which will be unpacked from archive.
-
- (Fixnum) TotalPackagesToRestore
Return number of packages which will be restored from archive.
-
- (Object) Umount
Umount mounted file system.
-
- (Hash) Write(abort, progress, targetdir)
Restore files from archive.
-
- (String) yesno(b)
Convert boolean value to translated “yes” or “no” string.
Instance Method Details
- (Boolean) ActivateBootloader
Activate boot loader configuration if requested. Uses variable Restore::runbootloader
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 |
# File '../../src/modules/Restore.rb', line 1369 def ActivateBootloader ret = nil # disable Bootloader's progress bar Progress.off if @runbootloader == true && Mode.test == false Builtins.y2milestone("activating boot loader configuration") # Bootloader function calls were moved to a client # to break the build-dependency on yast2-bootloader ret = Convert.to_boolean(WFM.call("restore_bootloader")) if ret == false # error popup message Report.Error(_("Boot loader configuration failed.")) end Builtins.y2milestone("boot loader activated: %1", ret) end # re-enable progress bar Progress.on ret end |
- (Hash) AddVolume(file)
Add next volume - check volume, copy volume to the temp. dir.
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 |
# File '../../src/modules/Restore.rb', line 734 def AddVolume(file) vol = Ops.add(Builtins.size(@volumeparts), 1) success = false # check if file is next volume check = CheckVolume(file, vol) Builtins.y2debug("CheckVolume(%1, %2): %3", file, vol, check) if Ops.get_boolean(check, "success", false) == true # copy file to temporary directory copy = CopyVolume(file, vol) Builtins.y2debug("CopyVolume(%1, %2): %3", file, vol, copy) if Ops.get_boolean(copy, "success", false) == true partname = Ops.get_string(copy, "file", "") @volumeparts = Builtins.add(@volumeparts, partname) success = true end end { "success" => success, "lastvolume" => Ops.get_boolean(check, "lastvolume", true) } end |
- (Object) CheckAndPrepareNFS(parsed_url)
Checks whether the portmapper service is installed and started. Installs and/or starts the service otherwise.
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 520 |
# File '../../src/modules/Restore.rb', line 473 def CheckAndPrepareNFS(parsed_url) parsed_url = deep_copy(parsed_url) ret = false # both new and old services are supported (portmap got replaced by rpcbind) # names of packages and service names match Builtins.foreach(["rpcbind", "portmap"]) do |portmapper| # checking if rpcbind is installed package_installed = Convert.to_integer( SCR.Execute( path(".target.bash"), Builtins.sformat("/bin/rpm -q %1", portmapper) ) ) Builtins.y2milestone( "%1 is instaled: %2", portmapper, package_installed ) if package_installed != 0 Builtins.y2milestone("%1 package is not installed", portmapper) installed = Package.DoInstall([portmapper]) Builtins.y2milestone( "Package %1 installed: %2", portmapper, installed ) # try next service next if installed != true end # checking if portmapper is running portmapper_status = Service.Status(portmapper) Builtins.y2milestone("portmap status: %1", portmapper_status) # portmapper is running if portmapper_status == 0 ret = true else # start portmapper started = Service.Start(portmapper) Builtins.y2milestone("%1 start result: %2", portmapper, started) ret = started end raise Break if ret == true end ret end |
- (Hash) CheckVolume(filename, num)
Check if volume number in archive is equal to expected volume number
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 |
# File '../../src/modules/Restore.rb', line 659 def CheckVolume(filename, num) success = false lastvolume = true # test if archive is multi volume - use -v parameter to get file descriptions detailresult = Convert.to_map( SCR.Execute( path(".target.bash_output"), Ops.add(Ops.add("/bin/tar -v -t -f '", String.Quote(filename)), "'") ) ) stdout = Builtins.splitstring( Ops.get_string(detailresult, "stdout", ""), "\n" ) firstline = Ops.get(stdout, 0, "") Builtins.y2debug("Test: First line: %1", firstline) # check if first line is volume label number num if Builtins.regexpmatch( firstline, Builtins.sformat("V--------- .* YaST2 backup: Volume %1--.*--", num) ) == true success = true end { "success" => success, "lastvolume" => Ops.get_integer(detailresult, "exit", -1) == 0 } end |
- (Object) ClearInstalledPackagesCache
Clear cache of installed packages. Next use of GetActualInstalledPackages() function will reread installed packages.
332 333 334 335 336 |
# File '../../src/modules/Restore.rb', line 332 def ClearInstalledPackagesCache @actualinstalledpackages = nil nil end |
- (Hash) CopyVolume(filename, num)
Copy volume to the local temporary directory
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 |
# File '../../src/modules/Restore.rb', line 699 def CopyVolume(filename, num) success = false tmpfile = Ops.add( Ops.add(Ops.add(@tempdir, "/"), Builtins.sformat("%1", num)), ".tar" ) # copy multi volume part to temp directory exit = Convert.to_integer( SCR.Execute( path(".target.bash"), Ops.add( Ops.add( Ops.add(Ops.add("/bin/cp '", String.Quote(filename)), "' '"), String.Quote(tmpfile) ), "'" ) ) ) if exit == 0 success = true else Builtins.y2error("Copy failed") end { "success" => success, "file" => tmpfile } end |
- (Hash) Export
Dump the restore settings to a single map - for use by autoinstallation.
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 |
# File '../../src/modules/Restore.rb', line 1293 def Export selection = {} if @inputname == "" # unconfigured return {} end Builtins.foreach(@archive_info) do |package, info| sel_type = Ops.get_string(info, "sel_type", " ") sel_file = Ops.get_list(info, "sel_file", []) package = @nopackage_id if package == "" selection = Builtins.add( selection, package, { "sel_type" => sel_type, "sel_file" => sel_file } ) end { "archives" => Builtins.prepend(@inputvolumes, @inputname), "runbootloader" => @runbootloader, "restoreRPMdb" => @restoreRPMdb, "completerestoration" => @completerestoration, "selection" => selection } end |
- (Hash) GetActualInstalledPackages
Return installed packages. Result is cached in Restore module, so only first use takes long time
214 215 216 217 218 219 220 |
# File '../../src/modules/Restore.rb', line 214 def GetActualInstalledPackages if @actualinstalledpackages == {} || @actualinstalledpackages == nil @actualinstalledpackages = ReadActualInstalledPackages() end deep_copy(@actualinstalledpackages) end |
- (String) GetArchiveComment
Return user comment stored in archive. Comment is stored in file info/comment.
160 161 162 |
# File '../../src/modules/Restore.rb', line 160 def GetArchiveComment @comment end |
- (String) GetArchiveDate
Return date when backup archive was created. Date is stored in archive in file info/date.
142 143 144 |
# File '../../src/modules/Restore.rb', line 142 def GetArchiveDate @date end |
- (Array) GetArchiveFiles
Return list of files in the backup archive
178 179 180 |
# File '../../src/modules/Restore.rb', line 178 def GetArchiveFiles deep_copy(@archivefiles) end |
- (String) GetArchiveHostname
Return host name of machine on which backup archive was created. Host name is stored in archive in file info/hostname.
166 167 168 |
# File '../../src/modules/Restore.rb', line 166 def GetArchiveHostname @hostname end |
- (Hash) GetArchiveInfo
Return restore configuration
1324 1325 1326 |
# File '../../src/modules/Restore.rb', line 1324 def GetArchiveInfo deep_copy(@archive_info) end |
- (Hash) GetArchiveInstalledPackages
Return map with packages installed at backup time (form is $[“package name” : “version”]).
172 173 174 |
# File '../../src/modules/Restore.rb', line 172 def GetArchiveInstalledPackages deep_copy(@installedpkgs) end |
- (String) GetArchiveName
Return name of backup archive
154 155 156 |
# File '../../src/modules/Restore.rb', line 154 def GetArchiveName @filename end |
- (Hash) GetExtraPackages
Return extra packages (packages which are installed at restore time, but at restore time they are installed)
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File '../../src/modules/Restore.rb', line 258 def GetExtraPackages r = {} GetActualInstalledPackages() # filter actual installed packages out r = Builtins.filter(@actualinstalledpackages) do |p, v| Builtins.haskey(@installedpkgs, p) != true end # add descriptions ret = Builtins.mapmap(r) do |pkg, version| descr = Mode.test == false ? Pkg.PkgSummary(pkg) : "" if descr == nil next { pkg => { "ver" => version } } else next { pkg => { "ver" => version, "descr" => descr } } end end deep_copy(ret) end |
- (String) GetInputName
Return name of backup archive
148 149 150 |
# File '../../src/modules/Restore.rb', line 148 def GetInputName @inputname end |
- (Hash) GetMismatchedPackages
Return packages which have different version at backup archive and in system
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 |
# File '../../src/modules/Restore.rb', line 283 def GetMismatchedPackages ret = {} GetActualInstalledPackages() Builtins.foreach(@actualinstalledpackages) do |p, v| if Builtins.haskey(@installedpkgs, p) == true backupversion = Ops.get(@installedpkgs, p, "") if backupversion != v descr = Mode.test == false ? Pkg.PkgSummary(p) : "" ret = descr != nil ? Builtins.add( ret, p, { "ver" => backupversion, "inst" => v, "descr" => descr } ) : Builtins.add(ret, p, { "ver" => backupversion, "inst" => v }) end end end deep_copy(ret) end |
- (Hash) GetMissingPackages
Return missing packages (packages which were installed at backup time, but at restore time they are not installed)
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 |
# File '../../src/modules/Restore.rb', line 225 def GetMissingPackages r = {} GetActualInstalledPackages() # filter actual installed packages out r = Builtins.filter(@installedpkgs) do |p, v| Builtins.haskey(@actualinstalledpackages, p) != true end Builtins.y2debug("actualinstalledpackages: %1", @actualinstalledpackages) Builtins.y2debug("GetMissingPackages r: %1", r) # add descriptions ret = Builtins.mapmap(r) do |pkg, version| descr = Mode.test == false ? Pkg.PkgSummary(pkg) : "" if descr == nil next { pkg => { "ver" => version } } else next { pkg => { "ver" => version, "descr" => descr } } end end # ignore gpg-pubkey packages - they are not real RPMs ret = Builtins.filter(ret) { |pkg, inf| pkg != "gpg-pubkey" } Builtins.y2debug("GetMissingPackages ret: %1", ret) deep_copy(ret) end |
- (Hash) GetSelectedPackages
Returns selected packages (even partially).
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
# File '../../src/modules/Restore.rb', line 313 def GetSelectedPackages ret = {} if @archive_info != nil # filter out unselected packages ret = Builtins.filter(@archive_info) do |p, info| sel_type = Ops.get_string(info, "sel_type", " ") if sel_type == "X" || sel_type == "P" next true else next false end end end deep_copy(ret) end |
- (Boolean) Import(settings)
Get all restore settings - for use by autoinstallation
1281 1282 1283 1284 1285 1286 1287 1288 |
# File '../../src/modules/Restore.rb', line 1281 def Import(settings) settings = deep_copy(settings) return false if settings == nil Set(settings) true end |
- (Object) IsMultiVolume
Selected archive has more parts
136 137 138 |
# File '../../src/modules/Restore.rb', line 136 def IsMultiVolume Ops.greater_than(Builtins.size(@volumeparts), 0) end |
- (Object) main
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 |
# File '../../src/modules/Restore.rb', line 45 def main Yast.import "UI" Yast.import "Pkg" Yast.import "Progress" Yast.import "Report" Yast.import "Mode" Yast.import "Summary" Yast.import "Service" Yast.import "Package" Yast.import "Label" Yast.import "Popup" Yast.import "URL" Yast.import "Message" Yast.import "String" textdomain "restore" # local file name (can be on mounted file system) @filename = "" # entered file name (e.g. nfs://server:/dir/archive.tar) @inputname = "" @completerestoration = false # list of volumes in URL-like syntax @inputvolumes = [] # contents of archive @archivefiles = [] # installed packages at backup time @installedpkgs = {} # list of installed packages @actualinstalledpackages = {} @complete_backup = [] # restoration archive and selection # "vers" : "version", "files" : ["files"], "prefix" : "prefix", "descr" : "description", "sel_type" : "X", "sel_file" : [""] @archive_info = {} @autoinst_info = {} # information stored in archive @date = "" @hostname = "" @comment = "" # list of files @volumeparts = [] # temporary directory @tempdir = "" # restore files to the selected directory @targetDirectory = "/" # mount point, stored for unmounting @mountpoint = "" # nopackage identification stored in Exported map # (to prevent empty tag in XML profile) @nopackage_id = "_NoPackage_" # Run lilo after files are restored @runbootloader = true # Rewrite RPM db - unapack /var/lib/rpm/* files from backup if present @restoreRPMdb = nil @config_modified = false end |
- (Object) Modified
Return modified flag
124 125 126 |
# File '../../src/modules/Restore.rb', line 124 def Modified @config_modified end |
- (Hash) mountCD(cdindex)
Access to file on CD
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
# File '../../src/modules/Restore.rb', line 399 def mountCD(cdindex) drives = Convert.to_list(SCR.Read(path(".probe.cdrom"))) if cdindex == nil || Ops.greater_than(cdindex, Ops.subtract(Builtins.size(drives), 1)) return { "mounted" => false } end cddevice = Ops.get_string(drives, [cdindex, "dev_name"], "/dev/cdrom") tmpdir = Convert.to_string(SCR.Read(path(".target.tmpdir"))) mpoint = Ops.add(tmpdir, "/cd") # create mount point directory SCR.Execute(path(".target.mkdir"), mpoint) result = Convert.to_boolean( SCR.Execute(path(".target.mount"), [cddevice, mpoint], "-o ro") ) { "mounted" => result, "mpoint" => mpoint } end |
- (Hash) mountDevice(device)
Mount device
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
# File '../../src/modules/Restore.rb', line 453 def mountDevice(device) return { "mounted" => false } if device == nil || device == "" tmpdir = Convert.to_string(SCR.Read(path(".target.tmpdir"))) mpoint = Ops.add(tmpdir, "/mount") # create mount point directory SCR.Execute(path(".target.mkdir"), mpoint) # mount read-only result = Convert.to_boolean( SCR.Execute(path(".target.mount"), [device, mpoint], "-o ro") ) { "mounted" => result, "mpoint" => mpoint } end |
- (Hash) mountFloppy(fdindex)
Access to file on floppy
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 |
# File '../../src/modules/Restore.rb', line 426 def mountFloppy(fdindex) drives = Convert.to_list(SCR.Read(path(".probe.floppy"))) if fdindex == nil || Ops.greater_than(fdindex, Ops.subtract(Builtins.size(drives), 1)) return { "mounted" => false } end fddevice = Ops.get_string(drives, [fdindex, "dev_name"], "/dev/fd0") tmpdir = Convert.to_string(SCR.Read(path(".target.tmpdir"))) mpoint = Ops.add(tmpdir, "/fd") # create mount point directory SCR.Execute(path(".target.mkdir"), mpoint) result = Convert.to_boolean( SCR.Execute(path(".target.mount"), [fddevice, mpoint], "-o ro") ) { "mounted" => result, "mpoint" => mpoint } end |
- (Hash) MountInput(input)
Mount input source
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 560 561 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 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 |
# File '../../src/modules/Restore.rb', line 526 def MountInput(input) Builtins.y2milestone("MountInput(%1)", input) success = false mpoint = "" file = "" #parse 'input' nfsprefix = "nfs://" fileprefix = "file://" devprefix = "dev://" cdprefix = "cd" # cd prefix can be "cd://" (equivalent to "cd0://"), "cd1://", "cd2://", ... number of CD identification fdprefix = "fd" parsed_url = URL.Parse(input) scheme = Ops.get_string(parsed_url, "scheme", "file") if scheme == "nfs" if CheckAndPrepareNFS(parsed_url) Builtins.y2milestone("NFS-related services adjusted") else Builtins.y2error("Cannot adjust NFS-related services") end Builtins.y2milestone( "NFS source - server: %1 file: %2", Ops.get_string(parsed_url, "host", ""), Ops.get_string(parsed_url, "path", "") ) mountresult = mountNFS( Ops.get_string(parsed_url, "host", ""), Ops.get_string(parsed_url, "path", "") ) if Ops.get_boolean(mountresult, "mounted", false) == false Builtins.y2error("Cannot read source '%1' - NFS mount failed", input) else mpoint = Ops.get_string(mountresult, "mountpoint", "") file = Ops.add( Ops.add(mpoint, "/"), Ops.get_string(mountresult, "file", "") ) success = true Builtins.y2milestone("mpoint: %1", mpoint) Builtins.y2milestone("file: %1", file) end elsif scheme == "dev" device = Ops.get_string(parsed_url, "host", "") devfile = Ops.get_string(parsed_url, "path", "") Builtins.y2milestone( "Device source - device: %1 file: %2", device, devfile ) mountresult = mountDevice(device) if Ops.get_boolean(mountresult, "mounted", false) == false Builtins.y2error( "Cannot read source '%1' - device mount failed", input ) else mpoint = Ops.get_string(mountresult, "mpoint", "") file = Ops.add(Ops.add(mpoint, "/"), devfile) success = true end elsif scheme == "file" file = Builtins.substring(input, Builtins.size(fileprefix)) Builtins.y2milestone("FILE source: %1", file) success = true elsif Builtins.regexpmatch(scheme, "^cd[0-9]*") # get CD drive index cdindex = Builtins.regexpsub(scheme, "^cd0*([0-9]*)", "\\1") cdfile = Ops.get_string(parsed_url, "path", "") cdindex = "0" if cdindex == nil || cdindex == "" cdfile = "" if cdfile == nil Builtins.y2milestone("CD source - drive: %1 file: %2", cdindex, cdfile) # mount CD mountresult = mountCD(Builtins.tointeger(cdindex)) if Ops.get_boolean(mountresult, "mounted", false) == false Builtins.y2error("Cannot read source '%1' - mount failed", input) else mpoint = Ops.get_string(mountresult, "mpoint", "") file = Ops.add(Ops.add(mpoint, "/"), cdfile) success = true end elsif Builtins.regexpmatch(scheme, "^fd[0-9]*") # get floppy index fdindex = Builtins.regexpsub(scheme, "fd0*([0-9]*)://(.*)", "\\1") fdfile = Ops.get_string(parsed_url, "path", "") fdindex = "0" if fdindex == nil || fdindex == "" fdfile = "" if fdfile == nil Builtins.y2milestone( "Floppy source - drive: %1 file: %2", fdindex, fdfile ) # mount floppy mountresult = mountFloppy(Builtins.tointeger(fdindex)) if Ops.get_boolean(mountresult, "mounted", false) == false Builtins.y2error("Cannot read source '%1' - mount failed", input) else mpoint = Ops.get_string(mountresult, "mpoint", "") file = Ops.add(Ops.add(mpoint, "/"), fdfile) success = true end else Builtins.y2error("Unknown prefix in input: %1", input) end { "success" => success, "mpoint" => mpoint, "file" => file } end |
- (Hash) mountNFS(server, file)
Access to file on NFS server
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 385 386 387 388 389 390 391 392 |
# File '../../src/modules/Restore.rb', line 355 def mountNFS(server, file) pos = Builtins.findlastof(file, "/") if pos != nil dir = Builtins.substring(file, 0, pos) f = Builtins.substring(file, Ops.add(pos, 1)) tmpdir = Convert.to_string(SCR.Read(path(".target.tmpdir"))) mpoint = Ops.add(tmpdir, "/nfs") dir = "/" if dir == "" || dir == nil # create mount point directory SCR.Execute(path(".target.mkdir"), mpoint) Builtins.y2milestone("dir: %1", dir) Builtins.y2milestone("file: %1", f) Builtins.y2milestone("mpoint: %1", mpoint) # BNC #682064: also 'nolock' is required result = Convert.to_boolean( SCR.Execute( path(".target.mount"), [Ops.add(Ops.add(server, ":"), dir), mpoint], "-t nfs -o ro,nolock" ) ) return { "mounted" => result, "mountpoint" => mpoint, "file" => f, "server_dir" => dir } end { "mounted" => false } end |
- (Object) ProposeRPMdbRestoration
2244 2245 2246 2247 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 |
# File '../../src/modules/Restore.rb', line 2244 def ProposeRPMdbRestoration extra = GetExtraPackages() missing = GetMissingPackages() mismatched = GetMismatchedPackages() selected = GetSelectedPackages() # proposed DB restoration propose = nil Builtins.y2debug("extra: %1, missig: %2", extra, missing) selected_list = [] Builtins.foreach(selected) do |p, _in| # store package name and vesion to the list selected_list = Builtins.add( selected_list, Ops.add(Ops.add(p, "-"), Ops.get_string(_in, "vers", "")) ) end Builtins.y2debug("selected_list: %1", selected_list) # propose restoration when: # - missing packages contain only fully backed packages # - all fully backed packages will be restored # - there is no extra package if Builtins.size(extra) == 0 all = true Builtins.y2debug("size(extra): %1", Builtins.size(extra)) Builtins.foreach(@complete_backup) do |fullpkg| # integer pos = findlastof(fullpkg, "-"); # string basename = substring(fullpkg, pos); # string version = substring(fullpkg, 0, pos); all = false if !Builtins.contains(selected_list, fullpkg) end Builtins.y2debug("all completely packages selected: %1", all) if all == true # check missing packages - it should contain only completely backed up packages Builtins.foreach(missing) do |pkg, inf| fpkg = Ops.add(Ops.add(pkg, "-"), Ops.get_string(inf, "vers", "")) all = false if !Builtins.contains(@complete_backup, fpkg) end if all == true Builtins.y2debug("only fully backed up packages are missing") # RPM DB restoration is recommended return { "proposed" => true } end end end ok = true # propose no restoration if only installed packages will be restored Builtins.foreach(selected) do |pk, inf| version = Ops.get_string(inf, "vers", "") # selected packages are not missing if ok && (Ops.get(missing, pk) != nil || Ops.get(mismatched, pk) != nil) ok = false end end return { "proposed" => false } if ok == true # there will be inconsistency between RPM DB and system, # some packages will be in DB but no files will be present # or there will be files without RPM entry or both # it is also possible that package versions do not match different_versions = {} # package in system => package in RPM in the archive not_in_system = [] # package is in DB in the archive, but not in the system and it won't be restored not_in_archiveDB = [] # not in the archive, but in the system Builtins.foreach(mismatched) do |p, inf| if Ops.get(selected, p) != nil # different_versions[p + "-" + selected["vers"]:""] = p + "-" + inf["inst"]:""; Ops.set( different_versions, p, Ops.add(Ops.add(p, "-"), Ops.get(inf, "inst", "")) ) end end Builtins.foreach(missing) do |p, inf| not_in_system = Builtins.add( not_in_system, Ops.add(Ops.add(p, "-"), Ops.get_string(inf, "vers", "")) ) end Builtins.foreach(extra) do |p, inf| not_in_archiveDB = Builtins.add( not_in_archiveDB, Ops.add(Ops.add(p, "-"), Ops.get_string(inf, "vers", "")) ) end # both possible operations (restoration or preserving RPM DB) # will cause to inconsistency in system { "proposed" => nil, "mismatched" => different_versions, "missing" => missing, "extra" => extra } end |
- (Boolean) Read(input)
Read contents of archive
826 827 828 829 830 831 832 833 834 835 836 837 838 839 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 1008 1009 1010 1011 1012 1013 1014 1015 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 1159 1160 1161 1162 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 1235 1236 1237 1238 |
# File '../../src/modules/Restore.rb', line 826 def Read(input) # umount old mount point Umount() if @tempdir == "" @tempdir = Convert.to_string(SCR.Read(path(".target.tmpdir"))) end @inputname = input if Mode.test == true @filename = "/tmp/dummy.tar" @archivefiles = [ "info/", "info/date", "info/comment", "info/files", "info/packages_info", "info/installed_packages", "info/hostname", "NOPACKAGE-20020509-0.tar.gz", "kdebase3-3.0-19-20020509-0.tar.gz", "lprng-3.8.5-49-20020509-0.tar.gz", "mozilla-0.9.8-54-20020509-0.tar.gz", "netcfg-2002.3.20-0-20020509-0.tar.gz" ] @date = "13.01.2002 14:25" @comment = "Some comments" @hostname = "linux.local" @installedpkgs = { "netcfg" => "2002.3.20-0", "lprng" => "3.8.5-49", "kdebase3" => "3.0-19", "gnome-applets" => "1.4.0.5-98", "mozilla" => "0.9.8-54" } @actualinstalledpackages = { "ggv" => "1.1.93-167", "netcfg" => "2002.3.20-0", "lprng" => "3.8.5-49", "kdebase3" => "3.0-19", "aterm" => "0.4.0" } @archive_info = { "" => { "descr" => "Files not owned by any package", "files" => ["/.qt/", "/dev/dvd", "/dev/cdrom"], "sel_type" => "X" }, "kdebase3" => { "descr" => "KDE base package: base system", "files" => ["/etc/opt/kde3/share/config/kdm/kdmrc"], "prefix" => "", "sel_type" => "X", "vers" => "3.0-19" }, "mozilla" => { "descr" => "Open Source WWW browser", "files" => ["/opt/mozilla/chrome/installed-chrome.txt"], "prefix" => "", "sel_type" => "X", "vers" => "0.9.8-54" }, "lprng" => { "descr" => "LPRng Print Spooler", "files" => ["/etc/init.d/lpd"], "prefix" => "", "sel_type" => "X", "vers" => "3.8.5-49" }, "netcfg" => { "descr" => "Network configuration files in /etc", "files" => [ "/etc/HOSTNAME", "/etc/defaultdomain", "/etc/exports", "/etc/hosts" ], "prefix" => "", "sel_type" => "X", "vers" => "2002.3.20-0" } } # set default selection @archive_info = Builtins.mapmap(@archive_info) do |p, i| i = Builtins.add( i, "sel_type", p == "" ? "X" : Builtins.haskey(@actualinstalledpackages, p) ? "X" : " " ) { p => i } end return true end # mount source mresult = MountInput(input) Builtins.y2debug("MountInput: %1", mresult) if Ops.get_boolean(mresult, "success", false) == false # error message Report.Error(_("Cannot mount file system.")) return false end @filename = Ops.get_string(mresult, "file", "") @mountpoint = Ops.get_string(mresult, "mpoint", "") Builtins.y2milestone("filename: %1", @filename) Builtins.y2milestone("mountpoint: %1", @mountpoint) # get archive contents result = Convert.to_map( SCR.Execute( path(".target.bash_output"), Ops.add(Ops.add("/bin/tar -t -f '", String.Quote(@filename)), "'") ) ) # check tar exit value if Ops.get_integer(result, "exit", -1) != 0 # tar failed, check whether file is first volume of multivolume archive @volumeparts = [] addresult = AddVolume(@filename) if Ops.get_boolean(addresult, "success", false) == true # read archive info from local copy (should be faster) @filename = Ops.get(@volumeparts, 0, "") else # error message Report.Error( _( "Cannot read archive file.\nIt is not a tar archive or it is broken.\n" ) ) return false end else # if archive is not local or NFS file copy it to tempdir (even if it isn't multi volume), # so removable device (e.g. CD-ROM) can be used for package installation later if Builtins.substring(input, 0, Builtins.size("file://")) != "file://" && Builtins.substring(input, 0, Builtins.size("nfs://")) != "nfs://" # copy archive to local file copy = CopyVolume(@filename, 0) if Ops.get_boolean(copy, "success", false) == true # set file name to local copy @filename = Ops.get_string(copy, "file", "") # umount file system Umount() else # error message: copy failed Report.Error( _("Cannot copy archive file\nto temporary directory.\n") ) return false end end end # get list of files @archivefiles = Builtins.splitstring( Ops.get_string(result, "stdout", ""), "\n" ) @archivefiles = Builtins.filter(@archivefiles) { |f| f != "" && f != nil } compressed_packages_info = Builtins.contains( @archivefiles, "info/packages_info.gz" ) Builtins.y2milestone( "compressed_packages_info: %1", compressed_packages_info ) if !(Builtins.contains(@archivefiles, "info/files") && (Builtins.contains(@archivefiles, "info/packages_info") || Builtins.contains(@archivefiles, "info/packages_info.gz")) && Builtins.contains(@archivefiles, "info/installed_packages")) # archive doesn't contain files from backup - file is not backup archive or not first volume of multi volume archive Builtins.y2error( "Archive does not contain 'info/files' or 'info/packages_info' or 'info/installed_packages' file!" ) # error message Report.Error( _( "The archive does not contain the required files.\nIt was probably not created by the backup module.\n" ) ) return false end Builtins.y2debug("read archivefiles: %1", @archivefiles) infofiles = "info/comment info/hostname info/date info/installed_packages info/files info/complete_backup " infofiles = Ops.add( infofiles, compressed_packages_info ? "info/packages_info.gz" : "info/packages_info" ) # unpack info files result = Convert.to_map( SCR.Execute( path(".target.bash_output"), Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add("/bin/tar -C '", String.Quote(@tempdir)), "' -x -f '" ), String.Quote(@filename) ), "' " ), infofiles ), " 2> /dev/null" ) ) ) @date = Convert.to_string( SCR.Read(path(".target.string"), Ops.add(@tempdir, "/info/date")) ) @comment = Convert.to_string( SCR.Read(path(".target.string"), Ops.add(@tempdir, "/info/comment")) ) @hostname = Convert.to_string( SCR.Read(path(".target.string"), Ops.add(@tempdir, "/info/hostname")) ) complete_backup_str = Ops.greater_than( SCR.Read( path(".target.size"), Ops.add(@tempdir, "/info/complete_backup") ), 0 ) ? Convert.to_string( SCR.Read( path(".target.string"), Ops.add(@tempdir, "/info/complete_backup") ) ) : "" Builtins.y2debug("complete_backup_str: %1", complete_backup_str) @complete_backup = Builtins.splitstring(complete_backup_str, "\n") Builtins.y2milestone("Complete backup: %1", @complete_backup) # read archive contents file archivefs = Convert.to_string( SCR.Read(path(".target.string"), Ops.add(@tempdir, "/info/files")) ) if archivefs != nil @archivefiles = Builtins.splitstring(archivefs, "\n") @archivefiles = Builtins.filter(@archivefiles) do |pk| pk != "" && pk != nil end end Builtins.y2debug("final archivefiles: %1", @archivefiles) # read installed packages installedpkgs_str = Convert.to_string( SCR.Read( path(".target.string"), Ops.add(@tempdir, "/info/installed_packages") ) ) # convert string to list installedpkgs_list = Builtins.splitstring(installedpkgs_str, "\n") installedpkgs_list = Builtins.filter(installedpkgs_list) do |pk| pk != "" && pk != nil end # convert list to map (key - package name, value - package version) @installedpkgs = {} Builtins.foreach(installedpkgs_list) do |fullname| version = Builtins.regexpsub(fullname, ".*-(.*-.*)", "\\1") name = Builtins.substring( fullname, 0, Ops.subtract( Ops.subtract(Builtins.size(fullname), Builtins.size(version)), 1 ) ) @installedpkgs = Builtins.add(@installedpkgs, name, version) end if compressed_packages_info == true Builtins.y2milestone("Unpacking packages_info.gz file") # uncompress compressed package info SCR.Execute( path(".target.bash"), Ops.add( Ops.add( Ops.add( Ops.add("/usr/bin/gunzip -c ", @tempdir), "/info/packages_info.gz > " ), @tempdir ), "/info/packages_info" ) ) Builtins.y2milestone("File unpacked") end # covert package info file to YCP structure by perl script Builtins.y2milestone("Converting package info") SCR.Execute( path(".target.bash"), Ops.add( Ops.add( Ops.add( Ops.add( "/usr/lib/YaST2/bin/restore_parse_pkginfo.pl < ", @tempdir ), "/info/packages_info > " ), @tempdir ), "/info.ycp" ) ) Builtins.y2milestone("Reading package info") @archive_info = Convert.convert( SCR.Read(path(".target.ycp"), Ops.add(@tempdir, "/info.ycp")), :from => "any", :to => "map <string, map <string, any>>" ) Builtins.y2milestone("Read %1 packages", Builtins.size(@archive_info)) # read actual installed packages GetActualInstalledPackages() mismatched = GetMismatchedPackages() # add package descriptions and default selection @archive_info = Builtins.mapmap(@archive_info) do |p, i| # decription of files not owned by any package descr = p == "" ? _("Files not owned by any package") : Pkg.PkgSummary(p) i = {} if i == nil descr = "" if descr == nil t = Builtins.add(i, "descr", descr) sel_type = " " if Mode.config == false # set default selection to "X" (package is installed) or " " (package is not installed) if p == "" # set "no package" default value to "X" sel_type = "X" else sel_type = Builtins.haskey(@actualinstalledpackages, p) && !Builtins.haskey(mismatched, p) ? "X" : " " end else # in autoinstall-config mode leave preselected value sel_type = Ops.get_string(i, "sel_type", " ") end t = Builtins.add(t, "sel_type", sel_type) { p => t } end if Mode.config == true # refresh file selection in autoinstall config mode Builtins.y2debug("Setting selection: %1", @autoinst_info) SetSelectionProperty(@autoinst_info) end Builtins.y2milestone( "values from archive: date=%1, comment=%2, hostname=%3", @date, @comment, @hostname ) Builtins.y2debug("installed packages at backup time: %1", @installedpkgs) Builtins.y2debug( "actual installed packages: %1", GetActualInstalledPackages() ) true end |
- (Hash) ReadActualInstalledPackages
Read installed packages.
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 |
# File '../../src/modules/Restore.rb', line 185 def ReadActualInstalledPackages # do not read installed packages in autoyast config mode return {} if Mode.config == true # init packager (TODO: later should be removed...) Pkg.TargetInit("/", false) # read info about installed packages info = Pkg.GetPackages(:installed, false) Builtins.y2debug("ReadActualInstalledPackages: %1", Builtins.sort(info)) # process version info ret = {} Builtins.foreach(info) do |pkg| all = Builtins.splitstring(pkg, " ") ret = Builtins.add( ret, Ops.get(all, 0, "unknown"), Ops.add(Ops.add(Ops.get(all, 1, ""), "-"), Ops.get(all, 2, "")) ) end deep_copy(ret) end |
- (Hash) ReadNextVolume(input)
Read next volume of multi volume archive
2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 |
# File '../../src/modules/Restore.rb', line 2051 def ReadNextVolume(input) # umount mounted file system Umount() ret = false last = true # mount source mount = MountInput(input) if Ops.get_boolean(mount, "success", false) == true @mountpoint = Ops.get_string(mount, "mpoint", "") # add mounted file addvol = AddVolume(Ops.get_string(mount, "file", "dummy")) ret = Ops.get_boolean(addvol, "success", false) last = Ops.get_boolean(addvol, "lastvolume", true) @inputvolumes = Builtins.add(@inputvolumes, input) if ret == true end { "success" => ret, "lastvolume" => last } end |
- (String) RemoveShortCut(scut)
Remove shortcut mark from string
2150 2151 2152 |
# File '../../src/modules/Restore.rb', line 2150 def RemoveShortCut(scut) Builtins.mergestring(Builtins.splitstring(scut, "&"), "") end |
- (Object) ResetAll
Clear all settings (archive and list of installed packages)
2138 2139 2140 2141 2142 2143 2144 2145 |
# File '../../src/modules/Restore.rb', line 2138 def ResetAll ResetArchiveSelection() # clear list of installed packages @actualinstalledpackages = {} nil end |
- (Object) ResetArchiveSelection
Clear all archive settings
2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 |
# File '../../src/modules/Restore.rb', line 2108 def ResetArchiveSelection # clear selected archive @filename = "" @inputname = "" # clear content of archive @archivefiles = [] # clear installed packages at backup time @installedpkgs = {} # clear archive selection @archive_info = {} # clear archive info @date = "" @hostname = "" @comment = "" # clear list of files @volumeparts = [] Umount() nil end |
- (Object) RPMrestorable
2363 2364 2365 2366 |
# File '../../src/modules/Restore.rb', line 2363 def RPMrestorable nopkgfiles = Ops.get_list(@archive_info, ["", "files"], []) Builtins.contains(nopkgfiles, "/var/lib/rpm/Packages") end |
- (Object) Set(settings)
Set settings
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 |
# File '../../src/modules/Restore.rb', line 1244 def Set(settings) settings = deep_copy(settings) Builtins.y2milestone("Using settings: %1", settings) @runbootloader = Ops.get_boolean(settings, "runbootloader", true) @restoreRPMdb = Ops.get_boolean(settings, "restoreRPMdb", false) @completerestoration = Ops.get_boolean( settings, "completerestoration", true ) archiveslist = Ops.get_list(settings, "archives", []) @inputname = Ops.get(archiveslist, 0, "") # read archives if Builtins.size(archiveslist) == 0 # set unconfigured state @inputname = "" @archive_info = {} end # set restore selection SetSelectionProperty(Ops.get_map(settings, "selection", {})) # store settings - file selection will be refreshed after archive selection # autoinstall config mode @autoinst_info = Ops.get_map(settings, "selection", {}) Builtins.y2debug("setting autoinst_info: %1", @autoinst_info) Builtins.y2debug("archive_info: %1", @archive_info) nil end |
- (Object) SetModified
128 129 130 131 132 |
# File '../../src/modules/Restore.rb', line 128 def SetModified @config_modified = true nil end |
- (Object) SetRestoreSelection(pkgname, selection)
Change restore selection of package.
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 |
# File '../../src/modules/Restore.rb', line 766 def SetRestoreSelection(pkgname, selection) selection = deep_copy(selection) pkgname = "" if pkgname == @nopackage_id if Builtins.haskey(@archive_info, pkgname) == false Builtins.y2warning( "Package %1 is not in archive, cannot be restored!", pkgname ) else sel_type = Ops.get_string(selection, "sel_type", " ") sel_file = [] pkginfo = Ops.get(@archive_info, pkgname, {}) pkginfo = {} if pkginfo == nil if sel_type == "P" sel_file = Ops.get_list(selection, "sel_file", []) elsif sel_type != "X" && sel_type != " " Builtins.y2warning( "Unknown selection type '%1' for package '%2'", sel_type, pkgname ) end pkginfo = Builtins.add(pkginfo, "sel_type", sel_type) pkginfo = Builtins.add(pkginfo, "sel_file", sel_file) @archive_info = Builtins.add(@archive_info, pkgname, pkginfo) end nil end |
- (Object) SetSelectionProperty(settings)
Set selection in _auto client and display properties of archive
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 |
# File '../../src/modules/Restore.rb', line 805 def SetSelectionProperty(settings) settings = deep_copy(settings) # set selection for this archive and display archive propertyt Builtins.foreach(settings) do |package, info| Builtins.y2debug( "setting selection: package:%1, selection:%2)", package, info ) package = "" if package == @nopackage_id SetRestoreSelection(package, info) end nil end |
- (String) Summary
Create restore configuration summary. Used in autoinstallation restore module configuration.
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 |
# File '../../src/modules/Restore.rb', line 2169 def Summary if @inputname == "" # not configured yet return Summary.NotConfigured else # Summary text header archives_info = "<P><B>" + _("Backup Archive") + "<B></P>" archives_info = Ops.add(Ops.add(archives_info, "<P>"), @inputname) Builtins.foreach(@inputvolumes) do |vol| archives_info = Ops.add(Ops.add(archives_info, vol), "<BR>") end archives_info = Ops.add(archives_info, "</P>") # Summary text header = "<P><B>" + _("Restore Options") + "<B></P>" = Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add(, "<P>"), RemoveShortCut( _( "Activate &boot loader configuration after restoration" ) ) ), ": " ), yesno(@runbootloader) ), "<BR>" ), RemoveShortCut( _("Restore RPM &database (if present in archive)") ) ), ": " ), yesno(@restoreRPMdb) ), "<BR></P>" ) # summary text heading selection_info = "<P><B>" + _("Packages to Restore") + "</B></P><P>" if @completerestoration # part of the summary text selection_info = Ops.add( selection_info, _("<I>Restore all files from the archive</I>") ) elsif @archive_info != nil Builtins.foreach(@archive_info) do |p, info| p = _("--No package--") if p == "" if Ops.get_string(info, "sel_type", " ") != " " selection_info = Ops.add(Ops.add(selection_info, p), "<BR>") end end end selection_info = Ops.add(selection_info, "</P>") return Ops.add(Ops.add(archives_info, ), selection_info) end end |
- (Boolean) TestAllVolumes
Test all volumes together
2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 |
# File '../../src/modules/Restore.rb', line 2080 def TestAllVolumes ret = false if Ops.greater_than(Builtins.size(@volumeparts), 0) param = "" Builtins.foreach(@volumeparts) do |f| param = Ops.add(Ops.add(Ops.add(param, "-f "), f), " ") end # echo 'q' to tar stdin - if error occurs tar asks for next volume, q means quit exit = Convert.to_integer( SCR.Execute( path(".target.bash"), Ops.add("echo q | /bin/tar -t -M ", param) ) ) Builtins.y2milestone("Test result: %1", exit) ret = exit == 0 end ret end |
- (Fixnum) TotalFilesToRestore
Return number of files which will be unpacked from archive
1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 |
# File '../../src/modules/Restore.rb', line 1346 def TotalFilesToRestore total = 0 # filter out unselected packages and compute total restored files Builtins.foreach(@archive_info) do |p, info| sel_type = Ops.get_string(info, "sel_type", " ") if sel_type == "X" total = Ops.add(total, Builtins.size(Ops.get_list(info, "files", []))) elsif sel_type == "P" total = Ops.add( total, Builtins.size(Ops.get_list(info, "sel_file", [])) ) end end total end |
- (Fixnum) TotalPackagesToRestore
Return number of packages which will be restored from archive
1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 |
# File '../../src/modules/Restore.rb', line 1330 def TotalPackagesToRestore total = 0 # filter out unselected packages Builtins.foreach(@archive_info) do |p, info| sel_type = Ops.get_string(info, "sel_type", " ") total = Ops.add(total, 1) if sel_type == "X" || sel_type == "P" end total end |
- (Object) Umount
Umount mounted file system.
340 341 342 343 344 345 346 347 348 |
# File '../../src/modules/Restore.rb', line 340 def Umount if @mountpoint != "" && @mountpoint != nil Builtins.y2milestone("Umount called - unmounting %1", @mountpoint) SCR.Execute(path(".target.umount"), @mountpoint) @mountpoint = "" end nil end |
- (Hash) Write(abort, progress, targetdir)
Restore files from archive
1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 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 1451 1452 1453 1454 1455 1456 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 1507 1508 1509 1510 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 1693 1694 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 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 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 1824 1825 1826 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 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 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 |
# File '../../src/modules/Restore.rb', line 1402 def Write(abort, progress, targetdir) abort = deep_copy(abort) restore = deep_copy(@archive_info) total = 0 restoredpackages = 0 restoredfiles = [] failedfiles = [] aborted = false if Builtins.size(targetdir) == 0 || Builtins.substring(targetdir, 0, 1) != "/" # error message, %1 is directory Report.Error( Builtins.sformat(_("Invalid target directory (%1)."), targetdir) ) return { "aborted" => aborted, "restored" => restoredfiles, "failed" => failedfiles, "packages" => restoredpackages, "bootloader" => false } end # create target directory if it doesn't exist out = Convert.to_integer( SCR.Execute(path(".target.bash"), Ops.add("/bin/mkdir -p ", targetdir)) ) if out != 0 # error message Report.Error(Message.UnableToCreateDirectory(targetdir)) end # filter out unselected packages and compute total restored files restore = Builtins.filter(restore) do |p, info| sel_type = Ops.get_string(info, "sel_type", " ") sel_type = "X" if @completerestoration if sel_type == "X" total = Ops.add(total, Builtins.size(Ops.get_list(info, "files", []))) next true elsif sel_type == "P" total = Ops.add( total, Builtins.size(Ops.get_list(info, "sel_file", [])) ) next true else next false end end Builtins.y2milestone("%1 files will be restored from archive", total) packages = [] Builtins.foreach(restore) do |package, info| packages = Builtins.add(packages, package) end i = 0 ret = :next if @restoreRPMdb == true rpm_backup_script = "/etc/cron.daily/suse.de-backup-rpmdb" # backup existing RPM DB - use aaa_base script which is started from cron if Ops.greater_than( SCR.Read(path(".target.size"), rpm_backup_script), 0 ) Builtins.y2milestone( "Startting RPM backup script (%1)", rpm_backup_script ) result = Convert.to_integer( SCR.Execute(path(".target.bash"), rpm_backup_script) ) Builtins.y2milestone("RPM backup exit value: %1", result) else Builtins.y2warning( "RPM DB backup script (%1) was not found, DB was not backed up!", rpm_backup_script ) end stat = Ops.get_string(@archive_info, ["", "sel_type"], " ") Builtins.y2warning("NOPACKAGE status: '%1'", stat) Builtins.y2warning( "NOPACKAGE files: '%1'", Ops.get_list(@archive_info, ["", "files"], []) ) if stat == " " || stat == "P" # RPM DB restoration is selected, but files not owned by any package are deselected # uncompress only RPM DB files, which are in directory /var/lib/rpm _RPM = [] # search RPM DB files Builtins.foreach(Ops.get_list(@archive_info, ["", "files"], [])) do |f| if Builtins.regexpmatch(f, "^/var/lib/rpm/") == true _RPM = Builtins.add(_RPM, f) end end Builtins.y2warning("found RPM DB files: %1", _RPM) if stat == " " _in = Builtins.eval(Ops.get(@archive_info, "", {})) Ops.set(_in, "sel_type", "P") Ops.set(_in, "sel_file", _RPM) # set new values Ops.set(restore, "", Builtins.eval(_in)) total = Ops.add(total, Builtins.size(_RPM)) else # may be some files are already selected # check status of each file already_selected = Ops.get_list(@archive_info, ["", "sel_file"], []) Builtins.foreach(_RPM) do |rpm_file| if !Builtins.contains(already_selected, rpm_file) already_selected = Builtins.add(already_selected, rpm_file) total = Ops.add(total, 1) end end _in = Builtins.eval(Ops.get(@archive_info, "", {})) Ops.set(_in, "sel_file", already_selected) # set new values Ops.set(restore, "", Builtins.eval(_in)) end end end Builtins.y2warning("packages: %1", packages) while Ops.less_than(i, Builtins.size(packages)) package = Ops.get(packages, i, "nonexistingpackage") info = Ops.get(restore, package, {}) # progress bar label label = package == "" ? _("Restoring files not owned by any package...") : # progress bar label - %1 is package name Builtins.sformat(_("Restoring package %1..."), package) sel_type = Ops.get_string(info, "sel_type", "") if progress != nil # update name of package UI.ChangeWidget(Id(progress), :Label, label) UI.ChangeWidget(Id(progress), :Value, i) end if Mode.test == true # delay Builtins.sleep(300) else # y2logs will be probably overwritten - backup them if package == "" && @targetDirectory == "/" copy = Convert.to_integer( SCR.Execute( path(".target.bash"), "cp -r /var/log/YaST2 /var/log/YaST2.before_restore" ) ) Builtins.y2milestone( "copy y2logs to /var/log/YaST2.before_restore: ret=%1", copy ) end # get subarchive name name = package == "" ? "NOPACKAGE" : Ops.add(Ops.add(package, "-"), Ops.get_string(info, "vers", "")) fileinarchive = "" Builtins.foreach(@archivefiles) do |f| if Builtins.regexpmatch( f, Ops.add(Ops.add("^", name), "-........-.\\.s{0,1}tar.*") ) == true Builtins.y2debug("package %1 is in archive file %2", package, f) fileinarchive = f end end # BNC #460674, Do not change the system locale # It can change I18N characters in output locale_modifications = "" if fileinarchive == "" Builtins.y2error("Can't find subarchive for package %1", package) else # unpack subarchive at background started = nil if IsMultiVolume() == true param = " " Builtins.foreach(@volumeparts) do |f| param = Ops.add( Ops.add(Ops.add(param, "-f '"), String.Quote(f)), "' " ) end command = Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add(locale_modifications, "echo q | /bin/tar -C "), @tempdir ), " -x -M " ), param ), "'" ), String.Quote(fileinarchive) ), "' 2> /dev/null" ) Builtins.y2milestone("Running command: %1", command) started = Convert.to_boolean( SCR.Execute(path(".background.run"), command) ) else command = Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add(locale_modifications, "/bin/tar -C "), @tempdir ), " -x -f '" ), String.Quote(@filename) ), "' '" ), String.Quote(fileinarchive) ), "'" ) Builtins.y2milestone("Running command: %1", command) started = Convert.to_boolean( SCR.Execute(path(".background.run"), command) ) end # abort test cycle while Convert.to_boolean(SCR.Read(path(".background.isrunning"))) Builtins.sleep(100) aborted = Builtins.eval(abort) if aborted == true Builtins.y2warning("Restoration aborted!") SCR.Execute(path(".background.kill"), nil) # kill subprocess break end end # break all packages cycle break if aborted == true # set compression parameter compress = "" # use star archiver star = false if Builtins.regexpmatch(fileinarchive, ".*\\.tar\\.gz$") == true compress = "-z" elsif Builtins.regexpmatch(fileinarchive, ".*\\.tar\\.bz2$") == true compress = "-j" elsif Builtins.regexpmatch(fileinarchive, ".*\\.star$") || Builtins.regexpmatch(fileinarchive, ".*\\.star\\.gz$") || Builtins.regexpmatch(fileinarchive, ".*\\.star\\.bz2$") == true # star can autodetect used compression compress = "" star = true end Builtins.y2debug("compress: %1", compress) Builtins.y2debug("star: %1", star) Builtins.y2debug("fileinarchive: %1", fileinarchive) _RPMdb = @restoreRPMdb ? "" : star ? "-not pat=var/lib/rpm" : "--exclude var/lib/rpm" # files to unpack, "" means all files unpackfiles = "" # select files to unpack if sel_type == "P" # strip leading '/' Builtins.foreach(Ops.get_list(info, "sel_file", [])) do |f| if Ops.greater_than(Builtins.size(f), 1) # remove a leading slash if Builtins.substring(f, 0, 1) == "/" f = Builtins.substring(f, 1) end # every single entry must be quoted unpackfiles = Ops.add( Ops.add(Ops.add(unpackfiles, " '"), String.Quote(f)), "'" ) end end end # FIXME: use list of files # for star: list=filename # for tar: --files-from=filename # create (s)tar command tarcommand = star == false ? Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( locale_modifications, "/bin/tar -C " ), targetdir ), " " ), compress ), " -x -v -f " ), @tempdir ), "/" ), fileinarchive ), " " ), _RPMdb ), " " ), unpackfiles ), " 2> " ), @tempdir ), "/tar.stderr > " ), @tempdir ), "/tar.stdout" ) : Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( locale_modifications, "/usr/bin/star -C " ), targetdir ), " " ), compress ), " -x -v -U -f " ), @tempdir ), "/" ), fileinarchive ), " " ), _RPMdb ), " " ), unpackfiles ), " 2> " ), @tempdir ), "/tar.stderr > " ), @tempdir ), "/tar.stdout" ) # -U option: replace existing files Builtins.y2milestone("tarcommand: %1", tarcommand) # check whether star is installed if Ops.less_than(SCR.Read(path(".target.size"), "/usr/bin/star"), 0) && star == true # remove short cont = Label.ContinueButton cont = Builtins.mergestring(Builtins.splitstring(cont, "&"), "") # popup message text - ask to install 'star' package # %1 is translated 'Continue' label inst = Popup.ContinueCancel( Builtins.sformat( _( "Package star is needed to extract\n" + "files from the archive.\n" + "Press %1 to install this package.\n" ), cont ) ) if inst == true # install star package # initialize package manager Pkg.SourceStartCache(true) Pkg.TargetInit("/", false) ok = true # select star package to installation ok = Pkg.PkgInstall("star") # solve dependencies ok = ok && Pkg.PkgSolve(false) # perform installation (0 means install from all media) result = Pkg.PkgCommit(0) # check result Builtins.y2debug("PkgCommit: %1", result) inst = ok && Ops.get(result, 1) == [] && Ops.get(result, 2) == [] end # abort restoration if star installation failed if inst == false # error popup message Report.Error( _("Package star is not installed.\nPress OK to exit.\n") ) Builtins.y2error("star package wasn't installed - aborting") return { "aborted" => true, "restored" => restoredfiles, "failed" => failedfiles, "packages" => restoredpackages, "bootloader" => false } end end # start subprocess started = Convert.to_boolean( SCR.Execute(path(".background.run_output"), tarcommand) ) Builtins.y2milestone("Tar command started: %1", started) while SCR.Read(path(".background.isrunning")) == true Builtins.sleep(100) # small delay aborted = Builtins.eval(abort) if aborted == true Builtins.y2warning("Restoration aborted!") SCR.Execute(path(".background.kill"), nil) # kill subprocess break end end # read restored files stdout = Builtins.splitstring( Convert.to_string( SCR.Read( path(".target.string"), Ops.add(@tempdir, "/tar.stdout") ) ), "\n" ) # remove empty lines stdout = Builtins.filter(stdout) do |line| Ops.greater_than(Builtins.size(line), 0) end if stdout != nil # star has more verbose output - get only file names if star && stdout != nil filteredstdout = [] Builtins.foreach(stdout) do |line| new = Builtins.regexpsub( line, "x (.*) .* bytes, .* tape blocks", "\\1" ) filteredstdout = Builtins.add(filteredstdout, new) if new != nil end stdout = deep_copy(filteredstdout) end Builtins.y2debug("stdout: %1", stdout) if stdout != nil restoredfiles = Convert.convert( Builtins.merge(restoredfiles, stdout), :from => "list", :to => "list <string>" ) end # read failed files stderr = Builtins.splitstring( Convert.to_string( SCR.Read( path(".target.string"), Ops.add(@tempdir, "/tar.stderr") ) ), "\n" ) # remove empty lines stderr = Builtins.filter(stderr) do |line| Ops.greater_than(Builtins.size(line), 0) end packagefailedfiles = 0 Builtins.y2warning("stderr: %1", stderr) if stderr != [] # add file names to failedfiles Builtins.foreach(stderr) do |line| Builtins.y2warning("line: %1", line) if line != nil && line != "" file = Builtins.regexpsub(line, "s{0,1}tar: (.*)", "\\1") # ignore final star summary if file != nil && !Builtins.regexpmatch( line, "star: .* blocks \\+ .* bytes \\(total of .* bytes = .*k\\)\\." ) && !Builtins.regexpmatch(line, "star: WARNING: .*") failedfiles = Builtins.add(failedfiles, file) packagefailedfiles = Ops.add(packagefailedfiles, 1) Builtins.y2warning("Restoration of file %1 failed", file) end end end # package restoration failed if restoredfiles != nil && packagefailedfiles == Builtins.size(restoredfiles) Builtins.y2warning("failed package: %1", package) else restoredpackages = Ops.add(restoredpackages, 1) end break if aborted == true end end i = Ops.add(i, 1) end # sort list of restored files and remove duplicates (caused by multiple unpacking) restoredfiles = Builtins.toset(restoredfiles) # remove failed files restoredfiles = Builtins.filter(restoredfiles) do |f| !Builtins.contains(failedfiles, f) end if @runbootloader == true && progress != nil # progess bar label UI.ChangeWidget(Id(progress), :Label, _("Configuring boot loader...")) UI.ChangeWidget(Id(progress), :Value, i) end bootload = ActivateBootloader() { "aborted" => aborted, "restored" => restoredfiles, "failed" => failedfiles, "packages" => restoredpackages, "bootloader" => bootload } end |
- (String) yesno(b)
Convert boolean value to translated “yes” or “no” string
2157 2158 2159 2160 2161 2162 2163 2164 |
# File '../../src/modules/Restore.rb', line 2157 def yesno(b) ret = "?" ret = _("Yes") if b == true ret = _("No") if b == false ret end |