New: Backup drone's database and configuration from the UI
New: Download Backup files from the UI

Fixed: Run a database backup before upgrade
This commit is contained in:
Mark McDowall
2014-05-30 10:34:38 -07:00
parent d74e461aea
commit c5bd8b27fb
32 changed files with 552 additions and 27 deletions

View File

@@ -0,0 +1,19 @@
'use strict';
define(
[
'backbone.pageable',
'System/Backup/BackupModel'
], function (PageableCollection, BackupModel) {
return PageableCollection.extend({
url : window.NzbDrone.ApiRoot + '/system/backup',
model: BackupModel,
state: {
sortKey : 'time',
order : 1,
pageSize : 100000
},
mode: 'client'
});
});

View File

@@ -0,0 +1,10 @@
'use strict';
define(
[
'marionette'
], function (Marionette) {
return Marionette.ItemView.extend({
template: 'System/Backup/BackupEmptyViewTemplate'
});
});

View File

@@ -0,0 +1 @@
<div>No backups are available</div>

View File

@@ -0,0 +1,12 @@
'use strict';
define(
[
'Cells/TemplatedCell'
], function (TemplatedCell) {
return TemplatedCell.extend({
className: 'series-title',
template : 'System/Backup/BackupFilenameCellTemplate'
});
});

View File

@@ -0,0 +1,2 @@
<a href="{{urlBack}}/backup/{{type}}/{{name}}" class="no-router">{{name}}</a>

View File

@@ -0,0 +1,106 @@
'use strict';
define(
[
'vent',
'marionette',
'backgrid',
'System/Backup/BackupCollection',
'Cells/RelativeDateCell',
'System/Backup/BackupFilenameCell',
'System/Backup/BackupTypeCell',
'System/Backup/BackupEmptyView',
'Shared/LoadingView',
'Shared/Toolbar/ToolbarLayout'
], function (vent, Marionette, Backgrid, BackupCollection, RelativeDateCell, BackupFilenameCell, BackupTypeCell, EmptyView, LoadingView, ToolbarLayout) {
return Marionette.Layout.extend({
template: 'System/Backup/BackupLayoutTemplate',
regions: {
backups : '#x-backups',
toolbar : '#x-backup-toolbar'
},
columns: [
{
name : 'type',
label : '',
sortable : false,
cell : BackupTypeCell
},
{
name : 'this',
label : 'Name',
sortable : false,
cell : BackupFilenameCell
},
{
name : 'time',
label : 'Time',
sortable : false,
cell : RelativeDateCell
}
],
leftSideButtons: {
type : 'default',
storeState: false,
collapse : false,
items :
[
{
title : 'Backup',
icon : 'icon-file-text',
command : 'backup',
properties : { type: 'manual' },
successMessage: 'Database and settings were backed up successfully',
errorMessage : 'Backup Failed!'
}
]
},
initialize: function () {
this.backupCollection = new BackupCollection();
this.listenTo(this.backupCollection, 'sync', this._showBackups);
this.listenTo(vent, vent.Events.CommandComplete, this._commandComplete);
},
onRender: function () {
this._showToolbar();
this.backups.show(new LoadingView());
this.backupCollection.fetch();
},
_showBackups: function () {
if (this.backupCollection.length === 0) {
this.backups.show(new EmptyView());
}
else {
this.backups.show(new Backgrid.Grid({
columns : this.columns,
collection: this.backupCollection,
className : 'table table-hover'
}));
}
},
_showToolbar : function () {
this.toolbar.show(new ToolbarLayout({
left :
[
this.leftSideButtons
],
context: this
}));
},
_commandComplete: function (options) {
if (options.command.get('name') === 'backup') {
this.backupCollection.fetch();
}
}
});
});

View File

@@ -0,0 +1,10 @@
<div class="row">
<div class="col-md-12">
<div id="x-backup-toolbar"/>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div id="x-backups" class="table-responsive"/>
</div>
</div>

View File

@@ -0,0 +1,9 @@
'use strict';
define(
[
'backbone'
], function (Backbone) {
return Backbone.Model.extend({
});
});

View File

@@ -0,0 +1,33 @@
'use strict';
define(
[
'Cells/NzbDroneCell'
], function (NzbDroneCell) {
return NzbDroneCell.extend({
className: 'backup-type-cell',
render: function () {
this.$el.empty();
var icon = 'icon-time';
var title = 'Scheduled';
var type = this.model.get(this.column.get('name'));
if (type === 'manual') {
icon = 'icon-book';
title = 'Manual';
}
else if (type === 'update') {
icon = 'icon-retweet';
title = 'Before update';
}
this.$el.html('<i class="{0}" title="{1}"></i>'.format(icon, title));
return this;
}
});
});

View File

@@ -7,6 +7,7 @@ define(
'System/Info/SystemInfoLayout',
'System/Logs/LogsLayout',
'System/Update/UpdateLayout',
'System/Backup/BackupLayout',
'Shared/Messenger'
], function ($,
Backbone,
@@ -14,26 +15,30 @@ define(
SystemInfoLayout,
LogsLayout,
UpdateLayout,
BackupLayout,
Messenger) {
return Marionette.Layout.extend({
template: 'System/SystemLayoutTemplate',
regions: {
info : '#info',
info : '#info',
logs : '#logs',
updates: '#updates'
updates : '#updates',
backup : '#backup'
},
ui: {
infoTab : '.x-info-tab',
logsTab : '.x-logs-tab',
updatesTab: '.x-updates-tab'
infoTab : '.x-info-tab',
logsTab : '.x-logs-tab',
updatesTab : '.x-updates-tab',
backupTab : '.x-backup-tab'
},
events: {
'click .x-info-tab' : '_showInfo',
'click .x-logs-tab' : '_showLogs',
'click .x-updates-tab': '_showUpdates',
'click .x-backup-tab': '_showBackup',
'click .x-shutdown' : '_shutdown',
'click .x-restart' : '_restart'
},
@@ -52,6 +57,9 @@ define(
case 'updates':
this._showUpdates();
break;
case 'backup':
this._showBackup();
break;
default:
this._showInfo();
}
@@ -91,6 +99,16 @@ define(
this._navigate('system/updates');
},
_showBackup: function (e) {
if (e) {
e.preventDefault();
}
this.backup.show(new BackupLayout());
this.ui.backupTab.tab('show');
this._navigate('system/backup');
},
_shutdown: function () {
$.ajax({
url: window.NzbDrone.ApiRoot + '/system/shutdown',

View File

@@ -2,6 +2,7 @@
<li><a href="#info" class="x-info-tab no-router">Info</a></li>
<li><a href="#logs" class="x-logs-tab no-router">Logs</a></li>
<li><a href="#updates" class="x-updates-tab no-router">Updates</a></li>
<li><a href="#backup" class="x-backup-tab no-router">Backup</a></li>
<li class="lifecycle-controls pull-right">
<div class="btn-group">
<button class="btn btn-default btn-icon-only x-shutdown" title="Shutdown" data-container="body">
@@ -18,4 +19,5 @@
<div class="tab-pane" id="info"></div>
<div class="tab-pane" id="logs"></div>
<div class="tab-pane" id="updates"></div>
<div class="tab-pane" id="backup"></div>
</div>