Commit d8a1eeb9 authored by Efthymia Bika's avatar Efthymia Bika
Browse files

Move restore to its own tab

parent cfe8e216
......@@ -10,26 +10,18 @@
} else {
populate_clouds("");
}
console.log("2. selected = " + selected_backup);
$.each(backups, function(i, backup) {
if(backup.name == selected_backup) {
load_backup(backup);
return;
}
});
if(typeof selected_backup != 'undefined') {
$.each(backups, function(i, backup) {
if(backup.name == selected_backup) {
load_backup(backup);
return;
}
});
} else {
disable_actions(true);
}
});
var errors = {
backup_name_empty: 'Provide a Backup Name',
backup_name_illegal: 'Invalid Entry. Name must start with '
+ '\'Backup_\' and followed by characters [A-Za-z0-9-_]',
cloud_empty: 'Select cloud configuration',
dir_not_chosen : 'Provide a local directory',
res_file_illegal: 'Invalid Entry. Provide a valid file name',
path_empty: 'Provide a path',
passphrase_empty: 'Provide a Passphrase'
};
function activate_li(id) {
$("li").each(function(i, li) {
if($(this).is("#" + id)) {
......@@ -59,15 +51,6 @@
return true;
}
function check_directory(dir_id) {
if(!$('#' + dir_id).html()) {
$('#' + dir_id + '-error small').text(errors.dir_not_chosen);
$('#' + dir_id + '-error small').show();
return false;
} else $('#' + dir_id + '-error small').hide();
return true;
}
function check_cloud() {
var cloud = $("#cloud").val();
if(!cloud) {
......@@ -124,31 +107,23 @@
}
function disable_actions(disable) {
$("#restore_details_link").prop("disabled", disable);
$("#backup_details_link").prop("disabled", disable);
$("#status_link").prop("disabled", disable);
$("#timeview_link").prop("disabled", disable);
if(disable) {
$("#restore_details_link").click(function(e) { e.preventDefault(); });
$("#backup_details_link").click(function(e) { e.preventDefault(); });
$("#backup_details_link").unbind("click");
$("#status_link").click(function(e) { e.preventDefault(); });
$("#status_link").unbind("click");
$("#timeview_link").click(function(e) { e.preventDefault(); });
$("#timeview_link").unbind("click");
} else {
$("#restore_details_link").click(function(e) { return true; });
$("#backup_detais_link").click(function(e) { load_backup(); });
$("#status_link").click(function(e) { load_status(); });
$("#timeview_link").click(function(e) { load_timeview(); });
}
}
function backup(restore) {
$("#loader").show();
if(!restore) save_backup_set();
run_duplicity(restore);
disable_form(true);
write_first_backup();
disable_actions(false);
}
function check_fields(restore) {
if(!restore) {
return (check_backup_name()
......@@ -158,6 +133,7 @@
}
return check_directory("res-directory");
}
</script>
</head>
......@@ -296,85 +272,6 @@
</div>
</form>
</div>
<div class="content" id="restore_details">
<div class="clearfix">
<div class="small-3 columns">
<label id="res_directory_label" for="res-directory" class="right">
Local directory
</label>
</div>
<div id="res-directory" class="small-6 columns"></div>
<div id="res-dirdialogue_label" onclick="$('#choose-res-dir').trigger('click');"
class="small-3 columns" id="resdirpick">
<i class="fa fa-folder-o blue-folder">&nbsp;</i>
</div>
</div>
<div class="clearfix">
<div class="small-3 columns">&nbsp;</div>
<div id="res-directory-error" class="small-6 columns">
<small class="error"></small>
</div>
<input type="file" id="choose-res-dir" nwdirectory
style="display:none;"
onchange="$('#res-directory').html($(this).val());
check_directory('res-directory');" />
</div>
<div class="clearfix">
<div class="small-3 columns">
<label id="res-file-label" for="res-file" class="right inline">
<span data-tooltip aria-haspopup="true" class="has-tip"
title="Use relative path">
File to Restore
</span>
</label>
</div>
<div class="small-9 columns error" id="res-file-error">
<input type="text" id="res-file"
placeholder="Only restore this file">
<small class="error"></small>
</div>
</div>
<div class="clearfix">
<div class="small-3 columns">
<label id="timestamp-label" for="timestamp" class="right inline">
Timestamp&nbsp;<i class="fa fa-info-circle green-info"
onclick="$('#timestamp-help').slideDown();"></i>
</label>
</div>
<div class="small-9 columns error" id="timestamp-error">
<input type="text" id="timestamp"
placeholder="Restore from a specific time">
<small class="error"></small>
</div>
<div class="small-3 columns">&nbsp;</div>
<div class="small-9 columns hide info-text panel" id="timestamp-help">
<i class="fa fa-times right" onclick="$('#timestamp-help').slideUp();"></i>
Accepts following formats<br>
1. String "now" refers to current time<br>
2. A sequences of digits, like "123456890"
(indicating the time in seconds after the epoch)<br>
3. A string like "2002-01-25T07:00:00+02:00" in datetime format<br>
4. A number followed by one of the characters s, m, h, D, W, M, or Y
(indicating seconds, minutes, hours, days, weeks, months,
or years respectively), or a series of such pairs.
In this case the string refers to the time that preceded
the current time by the length of the interval.
For instance, "1h78m" indicates the time that was
one hour and 78 minutes ago.<br>
5. A date format of the form YYYY/MM/DD, YYYY-MM-DD, MM/DD/YYYY,
or MM-DD-YYYY, which indicates midnight on the day in question,
relative to the current time zone settings.
</div>
</div>
<div class="clearfix">
<div class="small-6 columns">&nbsp;</div>
<div class="small-6 columns">
<a id="restore_button" class="button radius right small"
onclick="if(check_fields(true)) backup(true);">
<i class="fa fa-cloud-download"></i>&nbsp;Restore</a>
</div>
</div>
</div>
<div class="content" id="status"></div>
<div class="content" id="timeview">
<div class="clearfix">
......
var container = "";
function load_backup(backup) {
$(".tabs").show();
$(".tabs-content").show();
$('#backup_details_tab').addClass('active');
var errors = {
backup_name_empty: 'Provide a Backup Name',
backup_name_illegal: 'Invalid Entry. Name must start with '
+ '\'Backup_\' and followed by characters [A-Za-z0-9-_]',
cloud_empty: 'Select cloud configuration',
dir_not_chosen : 'Provide a local directory',
res_file_illegal: 'Invalid Entry. Provide a valid file name',
path_empty: 'Provide a path',
passphrase_empty: 'Provide a Passphrase'
};
function check_directory(dir_id) {
if(!$('#' + dir_id).html()) {
$('#' + dir_id + '-error small').text(errors.dir_not_chosen);
$('#' + dir_id + '-error small').show();
return false;
} else $('#' + dir_id + '-error small').hide();
return true;
}
function hide_error_divs() {
$('#backup-name-error small').hide();
$('#res-backup-name-error small').hide();
$('#directory-error small').hide();
$('#res-directory-error small').hide();
$('#cloud-error small').hide();
$('#res-cloud-error small').hide();
$('#passphrase-error small').hide();
$('#res-passphrase-error small').hide();
$('#exclude-error small').hide();
$('#include-error small').hide();
$('#res-file-error small').hide();
$('#timestamp-error small').hide();
$('#time-head-error small').hide();
}
function load_backup(backup) {
$(".tabs").show();
$(".tabs-content").show();
$('#backup_details_tab').addClass('active');
$('#msg').html('');
$('#msg').removeClass('panel');
$("#time-dates").html("");
$("#time-contents").html("");
$("#time-path").val("/");
hide_error_divs();
if(backup) {
container = backup.container;
$("#backup-name").val(backup.name);
......
var dup_verbosity = " -v8 ";
function backup(restore) {
$("#loader").show();
if(!restore) save_backup_set();
run_duplicity(restore);
if(!restore) {
disable_form(true);
write_first_backup();
disable_actions(false);
}
}
function set_envs() {
var passphrase = $('#passphrase').val();
var sel_pass = $('#passphrase').val() ? $('#passphrase') : $("#res-passphrase");
var passphrase = sel_pass.val();
if(passphrase) {
process.env['PASSPHRASE'] = passphrase;
}
var cloud_name = $("#cloud").val().replace(/^\s+|\s+$/gm,'');
var sel_cloud = $("#cloud").val() ? $("#cloud") : $("#res-cloud");
var cloud_name = sel_cloud.val().replace(/^\s+|\s+$/gm,'');
$.each(clouds, function(i, cloud) {
if(cloud.name == cloud_name) {
process.env['SWIFT_PREAUTHURL'] = cloud.pithos_public + '/' + cloud.uuid;
......@@ -37,52 +50,61 @@ function build_win_commands() {
function run_duplicity(restore) {
var file_arg = "";
var file_to_restore = $("#res-file").val();
if(restore && file_to_restore) {
file_arg = " --file-to-restore '" + file_to_restore + "' ";
if(restore) {
var file_to_restore = $("#res-file").val();
if(file_to_restore) {
file_arg = " --file-to-restore '" + file_to_restore + "' ";
}
}
var time_arg = "";
var timestamp = $("#timestamp").val();
if(restore && timestamp) {
time_arg = " --time " + timestamp;
if(restore) {
var timestamp = $("#timestamp").val();
if(timestamp) {
time_arg = " --time " + timestamp;
}
}
var exclude_arg = "";
var exclude = $("#exclude").val();
if(exclude && !restore) {
var args = exclude.split(",");
$.each(args, function(i, value) {
if(process.platform == 'win32') {
exec(CYGWIN_BASH + " -c \"/usr/bin/cygpath '" + value + "' \"",
function(error, stdout, stderr) {
if(error) $("#msg").html(error);
var win_value = String(stdout).replace(/(\r\n|\n|\r)/gm, "");
exclude_arg += " --exclude '" + win_value + "' ";
});
} else {
exclude_arg += " --exclude '" + value + "' ";
}
});
if(!restore) {
var exclude = $("#exclude").val();
if(exclude) {
var args = exclude.split(",");
$.each(args, function(i, value) {
if(process.platform == 'win32') {
exec(CYGWIN_BASH + " -c \"/usr/bin/cygpath '" + value + "' \"",
function(error, stdout, stderr) {
if(error) $("#msg").html(error);
var win_value = String(stdout).replace(/(\r\n|\n|\r)/gm, "");
exclude_arg += " --exclude '" + win_value + "' ";
});
} else {
exclude_arg += " --exclude '" + value + "' ";
}
});
}
}
var include_arg = "";
var include = $("#include").val();
if(include && !restore) {
var args = include.split(",");
$.each(args, function(i, value) {
if(process.platform == 'win32') {
exec(CYGWIN_BASH + " -c \"/usr/bin/cygpath '" + value + "' \"",
function(error, stdout, stderr) {
if(error) $("#msg").html(error);
var win_value = String(stdout).replace(/(\r\n|\n|\r)/gm, "");
include_arg += " --include '" + win_value + "' ";
});
} else {
include_arg += " --include '" + value + "' ";
}
});
if(!restore) {
var include = $("#include").val();
if(include) {
var args = include.split(",");
$.each(args, function(i, value) {
if(process.platform == 'win32') {
exec(CYGWIN_BASH + " -c \"/usr/bin/cygpath '" + value + "' \"",
function(error, stdout, stderr) {
if(error) $("#msg").html(error);
var win_value = String(stdout).replace(/(\r\n|\n|\r)/gm, "");
include_arg += " --include '" + win_value + "' ";
});
} else {
include_arg += " --include '" + value + "' ";
}
});
}
}
var directory = "";
if(restore) {
if(file_to_restore) {
......@@ -96,6 +118,14 @@ function run_duplicity(restore) {
} else {
directory = $("#directory").html();
}
var container_name = "";
if(restore) {
container_name = $("#res-backup-name").val();
} else {
container_name = $("#backup-name").val();
}
var log_file = path.join(BAAS_LOG_DIR, "dup_" + new Date().toISOString() + ".log");
var log_arg = " --log-file '" + log_file + "' ";
......@@ -106,12 +136,12 @@ function run_duplicity(restore) {
directory = String(stdout).replace(/(\r\n|\n|\r)/gm, "");
if(error) $("#msg").html(error);
var dirs = directory + " swift://" + container;
var dirs = directory + " swift://" + container_name;
if(restore) {
dirs = " swift://" + container + " " + directory;
dirs = " swift://" + container_name + " " + directory;
}
var cmd = build_win_commands();
var dup_cmd = "duplicity " + dup_verbosity + log_arg + include_arg + exclude_arg + file_arg + time_arg + dirs + ";";
var dup_cmd = "duplicity " + include_arg + exclude_arg + file_arg + time_arg + dirs + ";";
exec(CYGWIN_BASH + " -c '" + cmd + dup_cmd + "'",
function(error, stdout, stderr){
......@@ -128,15 +158,15 @@ function run_duplicity(restore) {
} else {
set_envs();
var dirs = directory + " swift://" + container;
var dirs = directory + " swift://" + container_name;
if(restore) {
dirs = " swift://" + container + " " + directory;
dirs = " swift://" + container_name + " " + directory;
}
var dup_cmd = "duplicity " + dup_verbosity + log_arg + include_arg + exclude_arg + file_arg + time_arg + dirs + ";";
exec(dup_cmd , function(error, stdout, stderr) {
if(error) {
$("#msg").addClass("panel");
$("#msg").html(error);
$("#msg").html(stderr);
} else {
$("#msg").html("");
$("#msg").removeClass("panel");
......
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
$(document).ready(function() {
if(typeof clouds === 'undefined') {
load_data_from_file(CLOUDS_CONF_FILE, populate_clouds);
} else {
populate_clouds("");
}
});
hide_error_divs();
function check_res_backup_name() {
var backup_name = $('#res-backup-name').val().replace(/^\s+|\s+$/gm,'');
if(!backup_name) {
$('#res-backup-name-error small').text(errors.backup_name_empty);
$('#res-backup-name-error small').show();
return false;
} else {
$('#res-backup-name-error small').hide();
}
return true;
}
function check_res_cloud() {
var cloud = $("#res-cloud").val();
if(!cloud) {
$('#res-cloud-error small').text(errors.cloud_empty);
$('#res-cloud-error small').show();
return false;
} else {
$('#res-cloud-error small').hide();
}
return true;
}
function check_res_passphrase() {
var passphrase = $("#passphrase").val();
if(!passphrase) {
$('#passphrase-error small').text(errors.passphrase_empty);
$('#passphrase-error small').show();
return false;
} else {
$('#passphrase-error small').hide();
}
return true;
}
function populate_clouds(data) {
if(typeof clouds === 'undefined') {
if(data != "") {
clouds = JSON.parse(data).clouds;
} else {
clouds = [];
}
}
var cloud_sel = $("#res-cloud");
$.each(clouds, function(i, cloud) {
cloud_sel.append($("<option></option>")
.attr("value", cloud.name)
.text(cloud.name));
});
}
function check_res_fields(restore) {
if(!restore) {
return (check_res_backup_name()
&& check_directory("directory")
&& check_cloud()
&& check_res_passphrase());
}
return (check_directory("res-directory")
&& check_res_cloud()
&& check_res_backup_name());
}
</script>
</head>
<body>
<div class="row">
<div class="small-10 columns">
<form>
<div class="clearfix">
<div class="small-3 columns">
<label id="res_cloud_label" for="res-cloud" class="right inline">Cloud</label>
</div>
<div class="small-9 columns error" id="res-cloud-error">
<select id="res-cloud" onchange="check_cloud();">
</select>
<small class="error"></small>
</div>
</div>
<div class="clearfix">
<div class="small-3 columns">
<label id="res_backup_name_label" for="res-backup-name" class="right inline">Name</label>
</div>
<div class="small-9 columns error" id="res-backup-name-error">
<input type="text" id="res-backup-name"
placeholder="Backup_[A-Za-z0-9-_]"
onchange="check_res_backup_name();">
<small class="error"></small>
</div>
</div>
<div class="clearfix">
<div class="small-3 columns">
<label id="res_passphrase_label" for="res_passphrase" class="right inline">Passphrase</label>
</div>
<div class="small-9 columns error" id="res-passphrase-error">
<input type="password" id="res-passphrase" placeholder="Passphrase">
<small class="error"></small>
</div>
</div>
<div class="clearfix">
<div class="small-3 columns">
<label id="res_directory_label" for="res-directory" class="right">
Local directory
</label>
</div>
<div id="res-directory" class="small-6 columns"></div>
<div id="res-dirdialogue_label" onclick="$('#choose-res-dir').trigger('click');"
class="small-3 columns" id="resdirpick">
<i class="fa fa-folder-o blue-folder">&nbsp;</i>
</div>
</div>
<div class="clearfix">
<div class="small-3 columns">&nbsp;</div>
<div id="res-directory-error" class="small-6 columns">
<small class="error"></small>
</div>
<input type="file" id="choose-res-dir" nwdirectory
style="display:none;"
onchange="$('#res-directory').html($(this).val());
check_directory('res-directory');" />
</div>
<div class="clearfix">
<div class="small-3 columns">
<label id="res-file-label" for="res-file" class="right inline">
<span data-tooltip aria-haspopup="true" class="has-tip"
title="Use relative path">
File to Restore
</span>
</label>
</div>
<div class="small-9 columns error" id="res-file-error">
<input type="text" id="res-file"
placeholder="Only restore this file">
<small class="error"></small>
</div>
</div>
<div class="clearfix">
<div class="small-3 columns">
<label id="timestamp-label" for="timestamp" class="right inline">
Timestamp&nbsp;<i class="fa fa-info-circle green-info"
onclick="$('#timestamp-help').slideDown();"></i>
</label>
</div>
<div class="small-9 columns error" id="timestamp-error">
<input type="text" id="timestamp"
placeholder="Restore from a specific time">
<small class="error"></small>
</div>
<div class="small-3 columns">&nbsp;</div>
<div class="small-9 columns hide info-text panel" id="timestamp-help">
<i class="fa fa-times right" onclick="$('#timestamp-help').slideUp();"></i>
Accepts following formats<br>
1. String "now" refers to current time<br>
2. A sequences of digits, like "123456890"
(indicating the time in seconds after the epoch)<br>
3. A string like "2002-01-25T07:00:00+02:00" in datetime format<br>
4. A number followed by one of the characters s, m, h, D, W, M, or Y
(indicating seconds, minutes, hours, days, weeks, months,
or years respectively), or a series of such pairs.
In this case the string refers to the time that preceded
the current time by the length of the interval.
For instance, "1h78m" indicates the time that was
one hour and 78 minutes ago.<br>
5. A date format of the form YYYY/MM/DD, YYYY-MM-DD, MM/DD/YYYY,
or MM-DD-YYYY, which indicates midnight on the day in question,
relative to the current time zone settings.
</div>
</div>
<div class="clearfix">
<div class="small-6 columns">&nbsp;</div>
<div class="small-6 columns">
<a id="restore_button" class="button radius right small"
onclick="if(check_res_fields(true)) backup(true);">
<i class="fa fa-cloud-download"></i>&nbsp;Restore</a>
</div>