Skip to content

Commit

Permalink
feat: ability to run and delete mirror backup
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuRA committed May 26, 2023
1 parent dd78b6b commit e4152ac
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
13 changes: 11 additions & 2 deletions packages/xo-web/src/common/xo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2350,8 +2350,8 @@ export const createBackupNgJob = props => _call('backupNg.createJob', props)::ta

export const getSuggestedExcludedTags = () => _call('backupNg.getSuggestedExcludedTags')

export const deleteBackupJobs = async ({ backupIds = [], metadataBackupIds = [] }) => {
const nJobs = backupIds.length + metadataBackupIds.length
export const deleteBackupJobs = async ({ backupIds = [], metadataBackupIds = [], mirrorBackupIds = [] }) => {
const nJobs = backupIds.length + metadataBackupIds.length + mirrorBackupIds.length
if (nJobs === 0) {
return
}
Expand Down Expand Up @@ -2380,6 +2380,13 @@ export const deleteBackupJobs = async ({ backupIds = [], metadataBackupIds = []
)
)
}
if (mirrorBackupIds.length !== 0) {
promises.push(
Promise.all(mirrorBackupIds.map(id => _call('mirrorBackup.deleteJob', { id: resolveId(id) })))::tap(
subscribeMirrorBackupJobs.forceRefresh
)
)
}

return Promise.all(promises)::tap(subscribeSchedules.forceRefresh)
}
Expand Down Expand Up @@ -2472,6 +2479,8 @@ export const subscribeMirrorBackupJobs = createSubscription(() => _call('mirrorB
export const createMirrorBackupJob = props =>
_call('mirrorBackup.createJob', props)::tap(subscribeMirrorBackupJobs.forceRefresh)

export const runMirrorBackupJob = props => _call('mirrorBackup.runJob', props)

// Plugins -----------------------------------------------------------

export const loadPlugin = async id =>
Expand Down
17 changes: 13 additions & 4 deletions packages/xo-web/src/xo-app/backup/overview/tab-jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
enableSchedule,
runBackupNgJob,
runMetadataBackupJob,
runMirrorBackupJob,
subscribeBackupNgJobs,
subscribeBackupNgLogs,
subscribeMetadataBackupJobs,
Expand All @@ -50,10 +51,12 @@ const Li = props => (
/>
)

const isMirrorBackup = item => item?.type === 'mirrorBackup'

const MODES = [
{
label: 'mirrorBackup',
test: job => job?.type === 'mirrorBackup',
test: isMirrorBackup,
},
{
label: 'rollingSnapshot',
Expand Down Expand Up @@ -86,8 +89,8 @@ const MODES = [
]

const _deleteBackupJobs = items => {
const { backup: backupIds, metadataBackup: metadataBackupIds } = groupBy(items, 'type')
return deleteBackupJobs({ backupIds, metadataBackupIds })
const { backup: backupIds, metadataBackup: metadataBackupIds, mirrorBackup: mirrorBackupIds } = groupBy(items, 'type')
return deleteBackupJobs({ backupIds, metadataBackupIds, mirrorBackupIds })
}

const _runBackupJob = ({ id, name, nVms, schedule, type }) =>
Expand All @@ -104,7 +107,13 @@ const _runBackupJob = ({ id, name, nVms, schedule, type }) =>
})}
</span>
),
}).then(() => (type === 'backup' ? runBackupNgJob({ id, schedule }) : runMetadataBackupJob({ id, schedule })))
}).then(() =>
type === 'backup'
? runBackupNgJob({ id, schedule })
: isMirrorBackup({ type })
? runMirrorBackupJob({ id, schedule })
: runMetadataBackupJob({ id, schedule })
)

const CURSOR_POINTER_STYLE = { cursor: 'pointer' }
const GoToLogs = decorate([
Expand Down

0 comments on commit e4152ac

Please sign in to comment.