mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
feat: run backup now
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { Database, Pencil } from "lucide-react";
|
import { Database, Pencil, Play } from "lucide-react";
|
||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import { listSnapshotsOptions } from "~/api-client/@tanstack/react-query.gen";
|
import { listSnapshotsOptions } from "~/api-client/@tanstack/react-query.gen";
|
||||||
import { ByteSize } from "~/components/bytes-size";
|
import { ByteSize } from "~/components/bytes-size";
|
||||||
@@ -14,11 +14,12 @@ type Props = {
|
|||||||
schedule: BackupSchedule;
|
schedule: BackupSchedule;
|
||||||
repository: Repository;
|
repository: Repository;
|
||||||
handleToggleEnabled: (enabled: boolean) => void;
|
handleToggleEnabled: (enabled: boolean) => void;
|
||||||
|
handleRunBackupNow: () => void;
|
||||||
setIsEditMode: (isEdit: boolean) => void;
|
setIsEditMode: (isEdit: boolean) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const ScheduleSummary = (props: Props) => {
|
export const ScheduleSummary = (props: Props) => {
|
||||||
const { volume, schedule, repository, handleToggleEnabled, setIsEditMode } = props;
|
const { volume, schedule, repository, handleToggleEnabled, handleRunBackupNow, setIsEditMode } = props;
|
||||||
|
|
||||||
const { data: snapshots, isLoading: loadingSnapshots } = useQuery({
|
const { data: snapshots, isLoading: loadingSnapshots } = useQuery({
|
||||||
...listSnapshotsOptions({
|
...listSnapshotsOptions({
|
||||||
@@ -61,6 +62,10 @@ export const ScheduleSummary = (props: Props) => {
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<OnOff isOn={schedule.enabled} toggle={handleToggleEnabled} enabledLabel="Enabled" disabledLabel="Paused" />
|
<OnOff isOn={schedule.enabled} toggle={handleToggleEnabled} enabledLabel="Enabled" disabledLabel="Paused" />
|
||||||
|
<Button variant="default" size="sm" onClick={handleRunBackupNow}>
|
||||||
|
<Play className="h-4 w-4 mr-2" />
|
||||||
|
Backup Now
|
||||||
|
</Button>
|
||||||
<Button variant="outline" size="sm" onClick={() => setIsEditMode(true)}>
|
<Button variant="outline" size="sm" onClick={() => setIsEditMode(true)}>
|
||||||
<Pencil className="h-4 w-4 mr-2" />
|
<Pencil className="h-4 w-4 mr-2" />
|
||||||
Edit schedule
|
Edit schedule
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
listRepositoriesOptions,
|
listRepositoriesOptions,
|
||||||
upsertBackupScheduleMutation,
|
upsertBackupScheduleMutation,
|
||||||
getBackupScheduleForVolumeOptions,
|
getBackupScheduleForVolumeOptions,
|
||||||
|
runBackupNowMutation,
|
||||||
} from "~/api-client/@tanstack/react-query.gen";
|
} from "~/api-client/@tanstack/react-query.gen";
|
||||||
import { parseError } from "~/lib/errors";
|
import { parseError } from "~/lib/errors";
|
||||||
import { CreateScheduleForm, type BackupScheduleFormValues } from "../components/create-schedule-form";
|
import { CreateScheduleForm, type BackupScheduleFormValues } from "../components/create-schedule-form";
|
||||||
@@ -65,6 +66,19 @@ export const VolumeBackupsTabContent = ({ volume }: Props) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const runBackupNow = useMutation({
|
||||||
|
...runBackupNowMutation(),
|
||||||
|
onSuccess: () => {
|
||||||
|
toast.success("Backup started successfully");
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["getBackupScheduleForVolume", volume.id.toString()] });
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
toast.error("Failed to start backup", {
|
||||||
|
description: parseError(error)?.message,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const handleSubmit = (formValues: BackupScheduleFormValues) => {
|
const handleSubmit = (formValues: BackupScheduleFormValues) => {
|
||||||
const cronExpression = getCronExpression(formValues.frequency, formValues.dailyTime, formValues.weeklyDay);
|
const cronExpression = getCronExpression(formValues.frequency, formValues.dailyTime, formValues.weeklyDay);
|
||||||
|
|
||||||
@@ -145,12 +159,23 @@ export const VolumeBackupsTabContent = ({ volume }: Props) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleRunBackupNow = () => {
|
||||||
|
if (!existingSchedule) return;
|
||||||
|
|
||||||
|
runBackupNow.mutate({
|
||||||
|
path: {
|
||||||
|
scheduleId: existingSchedule.id.toString(),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const repository = repositories.find((repo) => repo.id === existingSchedule?.repositoryId);
|
const repository = repositories.find((repo) => repo.id === existingSchedule?.repositoryId);
|
||||||
|
|
||||||
if (existingSchedule && repository && !isEditMode) {
|
if (existingSchedule && repository && !isEditMode) {
|
||||||
return (
|
return (
|
||||||
<ScheduleSummary
|
<ScheduleSummary
|
||||||
handleToggleEnabled={handleToggleEnabled}
|
handleToggleEnabled={handleToggleEnabled}
|
||||||
|
handleRunBackupNow={handleRunBackupNow}
|
||||||
repository={repository}
|
repository={repository}
|
||||||
setIsEditMode={setIsEditMode}
|
setIsEditMode={setIsEditMode}
|
||||||
schedule={existingSchedule}
|
schedule={existingSchedule}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
export const OPERATION_TIMEOUT = 5000;
|
export const OPERATION_TIMEOUT = 5000;
|
||||||
export const VOLUME_MOUNT_BASE = "/var/lib/ironmount/volumes";
|
export const VOLUME_MOUNT_BASE = "/volumes";
|
||||||
export const DATABASE_URL = "/data/ironmount.db";
|
export const DATABASE_URL = "/data/ironmount.db";
|
||||||
export const RESTIC_PASS_FILE = "/data/secrets/restic.pass";
|
export const RESTIC_PASS_FILE = "/data/secrets/restic.pass";
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
- /run/docker/plugins:/run/docker/plugins
|
- /run/docker/plugins:/run/docker/plugins
|
||||||
- ./data/volumes/:/var/lib/ironmount/volumes
|
- ./data/volumes/:/volumes
|
||||||
- /var/lib/repositories/:/var/lib/repositories
|
|
||||||
# - /proc:/host/proc:ro
|
# - /proc:/host/proc:ro
|
||||||
- ./data:/data
|
- ./data:/data
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user