Skip to content

A modern, self-hosted backup solution for secure, encrypted backups across local and cloud storage.

feat: add ability to update backup title and description

towfiqi47a919b06eed
diff --git a/backend/src/controllers/BackupController.ts b/backend/src/controllers/BackupController.ts
index 994f7e2..4fdecfb 100644
--- a/backend/src/controllers/BackupController.ts
+++ b/backend/src/controllers/BackupController.ts
@@ -165,4 +165,31 @@ export class BackupController {
return;
}
}
+
+ async updateBackup(req: Request, res: Response): Promise<void> {
+ if (!req.params.id) {
+ res.status(400).json({
+ success: false,
+ error: 'Backup ID is required',
+ });
+ return;
+ }
+
+ if (!req.body || Object.keys(req.body).length === 0) {
+ res.status(400).json({
+ success: false,
+ error: 'Update data is required',
+ });
+ return;
+ }
+ try {
+ const updatedBackup = await this.backupService.updateBackup(req.params.id, req.body);
+ res.status(200).json({ success: true, result: updatedBackup });
+ } catch (error: any) {
+ res.status(500).json({
+ success: false,
+ error: error?.message || 'Failed to update backup',
+ });
+ }
+ }
}
diff --git a/backend/src/db/schema/backups.ts b/backend/src/db/schema/backups.ts
index b210055..4e26534 100644
--- a/backend/src/db/schema/backups.ts
+++ b/backend/src/db/schema/backups.ts
@@ -1,4 +1,4 @@
-import { sql } from 'drizzle-orm/sql';
+import { desc, sql } from 'drizzle-orm/sql';
import { sqliteTable, text, integer, AnySQLiteColumn } from 'drizzle-orm/sqlite-core';
import { createInsertSchema, createSelectSchema, createUpdateSchema } from 'drizzle-zod';
import { storages } from './storages';
@@ -15,6 +15,8 @@ import { relations } from 'drizzle-orm';
export const backups = sqliteTable('backups', {
id: text('id').notNull().primaryKey(),
+ title: text('title'),
+ description: text('description'),
createdAt: integer('created_at', { mode: 'timestamp' })
.notNull()
.default(sql`(unixepoch())`),
diff --git a/backend/src/routes/backups.ts b/backend/src/routes/backups.ts
index de219d7..5c7dd87 100644
--- a/backend/src/routes/backups.ts
+++ b/backend/src/routes/backups.ts
@@ -7,6 +7,7 @@ export function createBackupRouter(
router: Router = Router()
): Router {
router.delete('/:id', authM, controller.deleteBackup.bind(controller));
+ router.post('/:id/', authM, controller.updateBackup.bind(controller));
router.get('/:id/files', authM, controller.getSnapshotFiles.bind(controller));
router.get('/:id/progress', authM, controller.getBackupProgress.bind(controller));
router.post('/:id/action/cancel', authM, controller.cancelBackup.bind(controller));
diff --git a/backend/src/services/BackupServices.ts b/backend/src/services/BackupServices.ts
index 09cdd82..a78da23 100644
--- a/backend/src/services/BackupServices.ts
+++ b/backend/src/services/BackupServices.ts
@@ -17,6 +17,7 @@ import {
import { BaseBackupManager } from '../managers';
import { jobQueue } from '../jobs/JobQueue';
import { SnapShotFile } from '../types/restic';
+import { Backup } from 'src/db/schema/backups';
export class BackupService {
protected broker: any;
@@ -213,6 +214,17 @@ export class BackupService {
return snapshotFilesResult.result;
}
+ async updateBackup(backupId: string, data: Partial<Backup>): Promise<any> {
+ const backup = await this.backupStore.getById(backupId);
+ if (!backup) {
+ throw new Error('Backup not found');
+ }
+ const title = data.title?.trim() || '';
+ const description = data.description?.trim() || '';
+ const updatedBackup = await this.backupStore.update(backupId, { title, description });
+ return updatedBackup;
+ }
+
async getStorageName(storageId: string): Promise<string> {
let storageName = '';
if (storageId !== 'local') {
diff --git a/backend/src/stores/PlanStore.ts b/backend/src/stores/PlanStore.ts
index 4652c65..d7c47ba 100644
--- a/backend/src/stores/PlanStore.ts
+++ b/backend/src/stores/PlanStore.ts
@@ -35,6 +35,8 @@ export class PlanStore {
orderBy: (backups, { desc }) => [desc(backups.ended)],
columns: {
id: true,
+ title: true,
+ description: true,
status: true,
errorMsg: true,
download: true,
@@ -102,6 +104,8 @@ export class PlanStore {
orderBy: (backups, { desc }) => [desc(backups.ended)],
columns: {
id: true,
+ title: true,
+ description: true,
status: true,
errorMsg: true,
download: true,
diff --git a/backend/src/types/plans.ts b/backend/src/types/plans.ts
index a81fd14..24dd79a 100644
--- a/backend/src/types/plans.ts
+++ b/backend/src/types/plans.ts
@@ -219,6 +219,8 @@ export type PlanChildItem = Pick<
export type PlanBackupItem = Pick<
Backup,
| 'id'
+ | 'title'
+ | 'description'
| 'status'
| 'inProgress'
| 'errorMsg'
diff --git a/frontend/src/@types/backups.ts b/frontend/src/@types/backups.ts
index e0eb944..45693b3 100644
--- a/frontend/src/@types/backups.ts
+++ b/frontend/src/@types/backups.ts
@@ -36,6 +36,8 @@ export interface BackupTaskStats {
export type Backup = {
id: string;
+ title?: string;
+ description?: string;
snapshotId: string;
started: number;
ended: number;
diff --git a/frontend/src/components/Plan/Backups/Backups.module.scss b/frontend/src/components/Plan/Backups/Backups.module.scss
index 18a6e94..6810142 100644
--- a/frontend/src/components/Plan/Backups/Backups.module.scss
+++ b/frontend/src/components/Plan/Backups/Backups.module.scss
@@ -39,12 +39,27 @@
display: flex;
justify-content: space-between;
position: relative;
+ .editIcon {
+ position: absolute;
+ z-index: 2;
+ visibility: hidden;
+ opacity: 0;
+ cursor: pointer;
+ transition: all 0.12s linear;
+ }
.backupTitle {
cursor: pointer;
+
&:hover {
color: var(--content-text-color);
}
}
+ .planDescription {
+ margin-left: 6px;
+ :global(.icon) {
+ color: var(--icon-color);
+ }
+ }
& > div {
padding: 15px 10px;
text-align: center;
@@ -155,10 +170,29 @@
&.backupsTableRowActive {
background-color: var(--background-color);
}
+
+ &:hover {
+ .backupTitle {
+ :global(.icon) {
+ opacity: 0;
+ visibility: hidden;
+ }
+ }
+ .editIcon {
+ visibility: visible;
+ opacity: 1;
+ }
+ }
}
}
}
+.updateModalContent {
+ .field {
+ margin-bottom: 15px;
+ }
+}
+
.removeModalContent {
position: relative;
.deleteLoader {
diff --git a/frontend/src/components/Plan/Backups/Backups.tsx b/frontend/src/components/Plan/Backups/Backups.tsx
index 7c62955..20cac6a 100644
--- a/frontend/src/components/Plan/Backups/Backups.tsx
+++ b/frontend/src/components/Plan/Backups/Backups.tsx
@@ -6,11 +6,12 @@ import { formatBytes, formatDateTime, formatDuration, formatNumberToK, timeAgo }
import Icon from '../../common/Icon/Icon';
import classes from './Backups.module.scss';
import ActionModal from '../../common/ActionModal/ActionModal';
-import { useCancelBackupDownload, useDeleteBackup, useDownloadBackup, useGetBackupDownload } from '../../../services/backups';
+import { useCancelBackupDownload, useDeleteBackup, useDownloadBackup, useGetBackupDownload, useUpdateBackup } from '../../../services/backups';
import { useQueryClient } from '@tanstack/react-query';
import RestoreWizard from '../../Restore/RestoreWizard/RestoreWizard';
import StatusLabel from '../../common/StatusLabel/StatusLabel';
import BackupEvents from '../BackupEvents/BackupEvents';
+import Input from '../../common/form/Input/Input';
const DownloadLabel = ({ download, downloadBackup }: { download: Backup['download']; downloadBackup: () => void }) => {
if (download?.status === 'started') {
@@ -79,8 +80,10 @@ const Backups = ({
const [showDeleteModal, setShowDeleteModal] = useState<Backup | false>(false);
const [showRestoreModal, setShowRestoreModal] = useState<Backup | false>(false);
const [showBackupEvents, setShowBackupEvents] = useState<false | string>(false);
+ const [showEditModal, setShowEditModal] = useState<Backup | false>(false);
const queryClient = useQueryClient();
const deleteBackupMutation = useDeleteBackup();
+ const updateBackupMutation = useUpdateBackup();
const downloadBackupMutation = useDownloadBackup();
const cancelDownloadMutation = useCancelBackupDownload();
const getDownloadMutation = useGetBackupDownload();
@@ -102,6 +105,30 @@ const Backups = ({
});
};
+ const updateBackup = (backup: Backup) => {
+ const payload = {
+ title: backup.title,
+ description: backup.description,
+ };
+ console.log('update :', backup.id, payload);
+ if (!payload.title && !payload.description) {
+ return;
+ }
+ updateBackupMutation.mutate(
+ { backupId: backup.id, updatePayload: payload },
+ {
+ onError: () => {
+ toast.error(`Failed to Update "backup-${backup.id}"`);
+ },
+ onSuccess: () => {
+ queryClient.invalidateQueries({ queryKey: ['plan', planId] });
+ toast.success(`Backup "backup-${backup.id}" Updated Successfully.`);
+ setShowEditModal(false);
+ },
+ },
+ );
+ };
+
const downloadBackup = (backupId: string) => {
toast.promise(downloadBackupMutation.mutateAsync({ backupId, planId }), {
pending: 'Sending Download Request...',
@@ -141,7 +168,8 @@ const Backups = ({
{backups
.filter((s) => !s.inProgress)
.map((snapshot) => {
- const { id, started, ended, download, status, errorMsg, duration, totalFiles, totalSize, changes, active } = snapshot;
+ const { id, title, description, started, ended, download, status, errorMsg, duration, totalFiles, totalSize, changes, active } =
+ snapshot;
const isDownloading = download && download.status === 'started';
return (
@@ -150,9 +178,22 @@ const Backups = ({
className={`${classes.backupsTableRow} ${showSnapOptions && showSnapOptions === id ? classes.backupsTableRowActive : ''}`}
>
<div>
+ <span
+ className={classes.editIcon}
+ onClick={() => setShowEditModal(snapshot)}
+ data-tooltip-id="htmlToolTip"
+ data-tooltip-html={`Edit Title & Description`}
+ >
+ <Icon type="edit" size={12} />
+ </span>
<span className={classes.backupTitle} onClick={() => !isSync && setShowBackupEvents(id)}>
- <Icon type={isSync ? 'sync' : 'box'} size={14} /> {isSync ? 'sync' : 'backup'}-{id}{' '}
+ <Icon type={isSync ? 'sync' : 'box'} size={14} /> {title ? title : isSync ? `sync-${id}` : `backup-${id}`}{' '}
</span>
+ {description && (
+ <span className={classes.backupDescription} data-tooltip-id="htmlToolTip" data-tooltip-content={description}>
+ <Icon type="note" size={13} />
+ </span>
+ )}
{!isSync && active && (
<span className={classes.activeBackup} data-tooltip-id="htmlToolTip" data-tooltip-html={`Active Snapshot`}>
<Icon type="bolt" size={14} />
@@ -288,6 +329,43 @@ const Backups = ({
close={() => setShowBackupEvents(false)}
/>
)}
+ {showEditModal && (
+ <ActionModal
+ title="Edit Backup Title & Description"
+ message={
+ <div className={classes.updateModalContent}>
+ <div className={classes.field}>
+ <Input
+ label="Title"
+ fieldValue={showEditModal.title || ''}
+ onUpdate={(val) => setShowEditModal({ ...showEditModal, title: val })}
+ placeholder="Enter Backup Title"
+ full={true}
+ inline={false}
+ />
+ </div>
+ <div className={classes.field}>
+ <Input
+ label="Description"
+ fieldValue={showEditModal.description || ''}
+ onUpdate={(val) => setShowEditModal({ ...showEditModal, description: val })}
+ placeholder="Enter Backup Description"
+ full={true}
+ inline={false}
+ />
+ </div>
+ </div>
+ }
+ closeModal={() => !updateBackupMutation.isPending && setShowEditModal(false)}
+ width="400px"
+ primaryAction={{
+ title: 'Update Backup',
+ type: 'default',
+ isPending: updateBackupMutation.isPending,
+ action: () => updateBackup(showEditModal),
+ }}
+ />
+ )}
</div>
);
};
diff --git a/frontend/src/services/backups.ts b/frontend/src/services/backups.ts
index c86913f..b5f1407 100644
--- a/frontend/src/services/backups.ts
+++ b/frontend/src/services/backups.ts
@@ -206,6 +206,32 @@ export function useCancelBackup() {
});
}
+// Update Backup Title and Description
+export async function updateBackup({ backupId, updatePayload }: { backupId: string; updatePayload: { title?: string; description?: string } }) {
+ console.log('updatePayload :', updatePayload);
+ const header = new Headers({ 'Content-Type': 'application/json', Accept: 'application/json' });
+ const res = await fetch(`${API_URL}/backups/${backupId}`, {
+ method: 'POST',
+ credentials: 'include',
+ body: JSON.stringify(updatePayload),
+ headers: header,
+ });
+ // Check if response is ok
+ const data = await res.json();
+ if (!data.success) {
+ throw new Error(data.error);
+ }
+ return data;
+}
+export function useUpdateBackup() {
+ return useMutation({
+ mutationFn: updateBackup,
+ onSuccess: (res, payload) => {
+ console.log('res :', payload, res);
+ },
+ });
+}
+
// Get Snapshot Files
export async function getSnapshotFiles({ backupId }: { backupId: string }) {
const res = await fetch(`${API_URL}/backups/${backupId}/files`, {