Add generic disk (partition) backup provider to replace ext4 and xfs

This commit is contained in:
Johannes Zellner
2023-08-08 13:21:56 +02:00
parent 5ef8d8d3b0
commit 10646e9e04
6 changed files with 58 additions and 9 deletions
+12 -5
View File
@@ -107,7 +107,7 @@
</div>
</div>
<!-- modal backup config -->
<!-- modal backup schedule config -->
<div class="modal fade" id="backupPolicyModal" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
@@ -207,10 +207,17 @@
<input type="password" class="form-control" ng-model="configureBackup.mountOptions.password" id="configureBackupPassword" name="cifsPassword" ng-disabled="configureBackup.busy" password-reveal>
</div>
<!-- EXT4 -->
<div class="form-group" ng-class="{ 'has-error': configureBackup.error.diskPath || !configureBackup.mountOptions.diskPath }" ng-show="configureBackup.provider === 'ext4' || configureBackup.provider === 'xfs'">
<!-- EXT4/XFS -->
<div class="form-group" ng-class="{ 'has-error': configureBackup.error.diskPath || !configureBackup.mountOptions.diskPath }" ng-show="configureBackup.provider === 'xfs' || configureBackup.provider === 'ext4'">
<label class="control-label" for="inputConfigureDiskPath">{{ 'backups.configureBackupStorage.diskPath' | tr }}</label>
<input type="text" class="form-control" ng-model="configureBackup.mountOptions.diskPath" id="inputConfigureDiskPath" name="diskPath" ng-disabled="configureBackup.busy" placeholder="/dev/disk/by-uuid/uuid" ng-required="configureBackup.provider === 'ext4' || configureBackup.provider === 'xfs'">
<input type="text" class="form-control" ng-model="configureBackup.mountOptions.diskPath" id="inputConfigureDiskPath" name="diskPath" ng-disabled="configureBackup.busy" placeholder="/dev/disk/by-uuid/uuid" ng-required="configureBackup.provider === 'xfs' || configureBackup.provider === 'ext4'">
</div>
<!-- Disk -->
<div class="form-group" ng-class="{ 'has-error': configureBackup.error.diskPath || !configureBackup.mountOptions.diskPath }" ng-show="configureBackup.provider === 'disk'">
<label class="control-label">{{ 'backups.configureBackupStorage.diskPath' | tr }}</label>
<select class="form-control" ng-model="configureBackup.disk" ng-options="item as item.label for item in configureBackup.blockDevices track by item.path" ng-required="configureBackup.provider === 'disk'"></select>
{{ configureBackup.mountOptions.diskPath }}
</div>
<!-- SSHFS -->
@@ -469,7 +476,7 @@
<span ng-show="backupConfig.provider === 'filesystem'">{{ backupConfig.backupFolder }}</span>
<span ng-show="mountlike(backupConfig.provider)">
<i class="fa fa-circle" ng-style="{ color: mountStatus.state === 'active' ? '#27CE65' : '#d9534f' }" ng-show="mountStatus" uib-tooltip="{{ mountStatus.message }}"></i>
<span ng-show="backupConfig.provider === 'filesystem' || backupConfig.provider === 'ext4' || backupConfig.provider === 'xfs' || backupConfig.provider === 'mountpoint'">{{ backupConfig.mountOptions.diskPath || backupConfig.mountPoint }}{{ (backupConfig.prefix ? '/' : '') + backupConfig.prefix }}</span>
<span ng-show="backupConfig.provider === 'disk' || backupConfig.provider === 'filesystem' || backupConfig.provider === 'ext4' || backupConfig.provider === 'xfs' || backupConfig.provider === 'mountpoint'">{{ backupConfig.mountOptions.diskPath || backupConfig.mountPoint }}{{ (backupConfig.prefix ? '/' : '') + backupConfig.prefix }}</span>
<span ng-show="backupConfig.provider === 'cifs' || backupConfig.provider === 'nfs' || backupConfig.provider === 'sshfs'">{{ backupConfig.mountOptions.host }}:{{ backupConfig.mountOptions.remoteDir }}{{ (backupConfig.prefix ? '/' : '') + backupConfig.prefix }}</span>
</span>
+34 -3
View File
@@ -273,7 +273,7 @@ angular.module('Application').controller('BackupsController', ['$scope', '$locat
};
$scope.mountlike = function (provider) {
return provider === 'sshfs' || provider === 'cifs' || provider === 'nfs' || provider === 'mountpoint' || provider === 'ext4' || provider === 'xfs';
return provider === 'sshfs' || provider === 'cifs' || provider === 'nfs' || provider === 'mountpoint' || provider === 'ext4' || provider === 'xfs' || provider === 'disk';
};
// https://stackoverflow.com/questions/3665115/how-to-create-a-file-in-memory-for-user-to-download-but-not-through-server#18197341
@@ -431,6 +431,11 @@ angular.module('Application').controller('BackupsController', ['$scope', '$locat
}
};
$scope.$watch('configureBackup.disk', function (newValue) {
if (!newValue) return;
$scope.configureBackup.mountOptions.diskPath = '/dev/disk/by-uuid/' + newValue.uuid;
});
$scope.configureBackup = {
busy: false,
error: {},
@@ -462,6 +467,8 @@ angular.module('Application').controller('BackupsController', ['$scope', '$locat
downloadConcurrency: '',
syncConcurrency: '', // sort of similar to upload
blockDevices: [],
disk: null,
mountOptions: {
host: '',
remoteDir: '',
@@ -496,6 +503,7 @@ angular.module('Application').controller('BackupsController', ['$scope', '$locat
$scope.configureBackup.syncConcurrency = $scope.configureBackup.provider === 's3' ? 20 : 10;
$scope.configureBackup.copyConcurrency = $scope.configureBackup.provider === 's3' ? 500 : 10;
$scope.configureBackup.disk = null;
$scope.configureBackup.mountOptions = { host: '', remoteDir: '', username: '', password: '', diskPath: '', seal: false, user: '', port: 22, privateKey: '' };
},
@@ -562,7 +570,30 @@ angular.module('Application').controller('BackupsController', ['$scope', '$locat
privateKey: mountOptions.privateKey || ''
};
$('#configureBackupModal').modal('show');
Client.getBlockDevices(function (error, result) {
if (error) return console.error('Failed to list blockdevices:', error);
console.log('all',result)
// only offer non /, /boot or /home disks
result = result.filter(function (d) { return d.mountpoint !== '/' && d.mountpoint !== '/home' && d.mountpoint !== '/boot'; });
// only offer xfs and ext4 disks
result = result.filter(function (d) { return d.type === 'xfs' || d.type === 'ext4'; });
console.log('filtered',result)
// amend label for UI
result.forEach(function (d) {
d.label = d.path;
// pre-select current if set
if (d.path === $scope.configureBackup.mountOptions.diskPath || ('/dev/disk/by-uuid/' + d.uuid) === $scope.configureBackup.mountOptions.diskPath) {
$scope.configureBackup.disk = d;
}
});
$scope.configureBackup.blockDevices = result;
$('#configureBackupModal').modal('show');
});
},
submit: function () {
@@ -666,7 +697,7 @@ angular.module('Application').controller('BackupsController', ['$scope', '$locat
backupConfig.mountOptions.port = $scope.configureBackup.mountOptions.port;
backupConfig.mountOptions.privateKey = $scope.configureBackup.mountOptions.privateKey;
}
} else if (backupConfig.provider === 'ext4' || backupConfig.provider === 'xfs') {
} else if (backupConfig.provider === 'ext4' || backupConfig.provider === 'xfs' || backupConfig.provider === 'disk') {
backupConfig.mountOptions.diskPath = $scope.configureBackup.mountOptions.diskPath;
} else if (backupConfig.provider === 'mountpoint') {
backupConfig.mountPoint = $scope.configureBackup.mountPoint;