Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api & ui. added support for directory restore #24

Merged
merged 1 commit into from
Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion api/execute
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use strict;
use NethServer::ApiTools;
use esmith::ConfigDB;
use File::Basename;
use File::Copy;
use JSON qw(encode_json decode_json);
use POSIX qw(strftime);
use feature qw(switch);
Expand Down Expand Up @@ -90,6 +91,13 @@ if ($action eq 'list-files') {
chomp($date);
}

if ($type eq 'duplicity') {
my $datestring = strftime "%Y%m%d%H%M", localtime($date);
my $logfile = "/var/log/backup/backup-$backup-$datestring.log";
$date = `/usr/bin/egrep 'StartTime ' $logfile | awk '{print \$2'} | sed 's/.\{3\}$//'`;
chomp($date);
}

my @restored;
for my $file (@$files) {
my $filepath = $override ? '/' : "/tmp";
Expand All @@ -109,7 +117,7 @@ if ($action eq 'list-files') {
my $datestring = strftime "%Y%m%d-%H%M%S", localtime;
my $fileName = basename($file);
my $dirName = dirname($file);
rename "/tmp$file", "$dirName/.restore-$datestring-$fileName";
move("/tmp$file", "$dirName/.restore-$datestring-$fileName");
unlink "/tmp$file";
push(@restored, {"original" => "$file", "restored" => "$dirName/.restore-$datestring-$fileName"});
} else {
Expand Down
14 changes: 7 additions & 7 deletions ui/public/i18n/language.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"no_results_text": "Select a backup and insert at least 4 characters, then press Search",
"warning": "Warning",
"too_many_results": "Your search has produced {0} results. Try to reduce the results changing the pattern. (Max results: 500)",
"restore_files": "Restore {0} files",
"overwrite_files": "Overwrite {0} files",
"files_restored_ok": "Files restored successfully!",
"files_restored_error": "Files not restored.",
"restore_files": "Restore {0} items",
"overwrite_files": "Overwrite {0} items",
"files_restored_ok": "Items restored successfully!",
"files_restored_error": "Items not restored.",
"override_restore": "Overwrite",
"choose_mode": "Choose mode",
"files_directories": "Files or directories",
Expand All @@ -27,8 +27,8 @@
"nothing_selected": "Nothing selected to restore",
"selected": "Selected",
"overwritten": "overwritten",
"restored_list": "List of restored files",
"error_restored_list": "There was an error restoring the files.",
"restored_list": "List of restored items",
"error_restored_list": "There was an error restoring the items.",
"are_you_sure": "Are you sure",
"cancel": "Cancel",
"backup_disabled": "This backup is disabled. Enable it before restore data.",
Expand All @@ -54,7 +54,7 @@
},
"docs": {
"more_info_about": "More info about",
"override_restore": "<li>If <b>checked</b> the restored files will overwrite the current files.</li><li>If <b>not checked</b> the restored files will be created in the same path with date included in the name and <code>.restore</code> prepended (es. .restore-20190729-153318-myfile).</li>",
"override_restore": "<li>If <b>checked</b> the restored items will overwrite the current item.</li><li>If <b>not checked</b> the restored items will be created in the same path with date included in the name and <code>.restore</code> prepended (es. .restore-20190729-153318-myitem).</li>",
"choose_mode": "<li><b>Files or directories</b>: Search only file and directories</li><li><b>Mail folders</b>: Search only email folders</li><li><b>Advanced</b>: Search everything (supports wildcards)</li>"
}
}
22 changes: 16 additions & 6 deletions ui/src/views/Restore.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
<span v-show="isDisabled" class="help-block help-disabled">
<span class="pficon pficon-warning-triangle-o mg-right"></span>
{{$t('restore.backup_disabled')}}
<a href="/nethserver#/backup" target="_blank">{{$t('restore.enable')}}</a>
<a
href="/nethserver#/backup"
target="_blank"
>{{$t('restore.enable')}}</a>
</span>
</div>
</div>
Expand Down Expand Up @@ -118,7 +121,12 @@
></doc-info>
</label>
<div class="col-sm-1">
<input :disabled="isDisabled" class="form-control" type="checkbox" v-model="choosedOverride" />
<input
:disabled="isDisabled"
class="form-control"
type="checkbox"
v-model="choosedOverride"
/>
</div>
</div>
<div class="form-group">
Expand Down Expand Up @@ -228,7 +236,8 @@ export default {
treeData: [],
treeOptions: {
checkbox: true,
paddingLeft: 21
paddingLeft: 21,
autoCheckChildren: false
},
selectedCount: 0,
selectedFiles: [],
Expand All @@ -252,7 +261,7 @@ export default {
methods: {
updateDate() {
this.choosedDate = this.backups[this.choosedBackup].dates[0];
this.isDisabled = this.backups[this.choosedBackup].status == 'disabled';
this.isDisabled = this.backups[this.choosedBackup].status == "disabled";
},
getBackups() {
var context = this;
Expand All @@ -276,7 +285,8 @@ export default {
].dates.sort(function(a, b) {
return b - a;
})[0];
context.isDisabled = context.backups[context.choosedBackup].status == 'disabled';
context.isDisabled =
context.backups[context.choosedBackup].status == "disabled";
},
function(error) {
console.error(error);
Expand Down Expand Up @@ -376,7 +386,7 @@ export default {

var restorable = [];
for (var n in nodes) {
if (nodes[n].children && nodes[n].children.length == 0) {
if (nodes[n].children) {
restorable.push(nodes[n]);
}
}
Expand Down