ACC SHELL

Path : /usr/share/YaST2/clients/
File Upload :
Current File : //usr/share/YaST2/clients/backup.ycp

/**
 *  File:
 *    backup.ycp
 *
 *  Module:
 *    Backup module
 *
 *  Authors:
 *    Ladislav Slezak <lslezak@suse.cz>
 *
 *  $Id: backup.ycp 59904 2009-12-02 15:18:27Z locilka $
 *
 *  Main file for backup module - definition of workflow
 *
 */


{

y2milestone(" *** Backup module started *** ");

import "Wizard";
import "Mode";
import "Backup";
import "Report";
import "Sequencer";
import "Popup";
import "CommandLine";

include "backup/functions.ycp";
include "backup/ui.ycp";

textdomain "backup";

boolean confirm_abort = false;	// confirm abort

// sequence of dialogs
map sequence = $[
    "ws_start"	: "readprof",

    "readprof" : $[
	`edit	: "archive",
	`start  : "scripts_before",
	`start  : "constraint",
	`manual : "archive",
	`cron	: "cron",
	`abort	: `abort,
	`finish : `ws_finish
    ],
    "cron" :$[
	`next	: "readprof",
	`abort	: `abort
    ],
    "archive" : $[
        `next	: "backup",
	`tar_opt: "tar_opt",
	`abort	: `abort
    ],
    "tar_opt" : $[
	`ok : "archive",
	`abort	: `abort
    ],
    "backup" : $[
        `next	: "constraint",
	`next2	: "scripts_before",
	`xpert	: "options",
	`abort	: `abort
    ],
    "constraint" : $[
	`next	: "searching",
	`abort	: `abort
    ],
    "options" : $[
	`finish	: "backup",
	`set_system : "system",
	`abort	: `abort
    ],
    "system" : $[
	`finish : "options",
	`abort	: `abort
    ],
    "searching"	: $[
	`next	: "scripts_before",
	`ok	: "readprof"
    ],
    "scripts_before" : $[
	`next	: "do_searching",
	`abort	: `abort,
    ],
    "do_searching"	: $[
	`next	: "files",
	`next2	: "archiving",
	`maindialog	: "readprof",
	`abort	: `abort
    ],
    "files" : $[
        `next	: "archiving",
	`abort	: `abort,
	// from "files" <back points to "constraint"
	`back_from_files : "constraint"
    ],
    "archiving" : $[
	`next	: "scripts_after",
	`abort	: `abort
    ],
    "scripts_after" : $[
	`next	: "summary",
	`abort	: `abort,
    ],
    "summary" : $[
	`abort	: `abort,
	`finish	: "readprof"
    ]
];

// aliases for dialogs
map aliases = $[
    "readprof"	: ``(SelectProfileDialog()),
    "cron"	: [ ``(CronDialog()), true ],
    "files"	: ``(FilesDialog()),
    "tar_opt"	: ``(TarOptionsDialog()),
    "archive"	: ``(ArchDialog()),
    "backup"	: ``(BackupDialog()),
    "options"	: ``(ExpertOptionsDialog()),
    "constraint": ``(ConstraintDialog()),
    "system"	: ``(SystemBackupDialog()),

    "searching"		: ``(PrepareSearching()),
    "scripts_before"	: ``(CallScriptsBeforeBackup()),
    "do_searching"	: [ ``(SearchingModifiedDialog()), true ],
    "archiving"		: [ ``(ArchivingDialog()), true ],
    "scripts_after"	: ``(CallScriptsAfterBackup()),
    "summary"		: ``(SummaryDialog())
];

map cmdline_description = $[
    "id" : "backup",
];

list args = WFM::Args();
y2milestone("args: %1", args);

// starting cron mode
if (args[0]:"" == "cron")
{
    y2milestone("Starting in cron mode");
    Backup::cron_mode = true;

    // BNC #548427: Mode acts like it was in a testsuite
    //              if it actually running in cron mode
    y2milestone ("Adjusting Mode UI to: commandline");
    Mode::SetUI ("commandline");

    if (args[1]:nil != nil)
    {
	Backup::cron_profile = regexpsub(args[1]:"", "^[ \t]*profile[ \t]*=[ \t]*(.*)", "\\1");
	y2milestone("Using profile: '%1'", Backup::cron_profile);
    }
// starting CMDLine mode (!cron mode)
} else if (size(args)>0) {
    any ret = CommandLine::Run(cmdline_description);
    return ret;
}

if (Backup::cron_mode != true)
{
    import "Wizard";

    // create wizard dialog
    Wizard::CreateDialog();
    // set icon
    Wizard::SetTitleIcon("yast-backup");
}

Backup::ReadBackupProfiles();

if (Backup::cron_mode == true)
{
    if (Backup::RestoreSettingsFromBackupProfile(Backup::cron_profile) == false)
    {
	y2error("Cannot read settings from profile '%1'", Backup::cron_profile);
	return false;
    }

    // change workflow - start searching immediately, exit at summary stage
    sequence["ws_start"] = "scripts_before";
    sequence["summary"] = $[
	`abort	: `abort,
	`finish	: `finish
    ];

    // disable user interaction
    Backup::no_interactive = true;

    // dont'display eny message - there is no UI in cron mode
    Report::DisplayMessages(false, 0);
    Report::DisplayWarnings(false, 0);
    Report::DisplayErrors(false, 0);

    map sel_profile = (map)eval(Backup::backup_profiles[Backup::cron_profile]:$[]);

    // prepare backup - e.g. mount NFS share
    Backup::PrepareBackup();

    // check existing archive, remove old archives
    string localfilename = Backup::GetLocalArchiveName();
    Backup::remove_result = Backup::RemoveOldArchives(localfilename, sel_profile[`cron_settings, "old"]:100000, Backup::multi_volume);
}

// start wizard sequencer
Sequencer::Run(aliases, sequence);

if (Backup::cron_mode != true)
{
    // close dialog
    Wizard::CloseDialog();
}

y2milestone(" *** Backup module finished *** ");

}


ACC SHELL 2018