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 { Database, Pencil } from "lucide-react";
|
||||
import { Database, Pencil, Play } from "lucide-react";
|
||||
import { useMemo } from "react";
|
||||
import { listSnapshotsOptions } from "~/api-client/@tanstack/react-query.gen";
|
||||
import { ByteSize } from "~/components/bytes-size";
|
||||
@@ -14,11 +14,12 @@ type Props = {
|
||||
schedule: BackupSchedule;
|
||||
repository: Repository;
|
||||
handleToggleEnabled: (enabled: boolean) => void;
|
||||
handleRunBackupNow: () => void;
|
||||
setIsEditMode: (isEdit: boolean) => void;
|
||||
};
|
||||
|
||||
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({
|
||||
...listSnapshotsOptions({
|
||||
@@ -61,6 +62,10 @@ export const ScheduleSummary = (props: Props) => {
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<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)}>
|
||||
<Pencil className="h-4 w-4 mr-2" />
|
||||
Edit schedule
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
listRepositoriesOptions,
|
||||
upsertBackupScheduleMutation,
|
||||
getBackupScheduleForVolumeOptions,
|
||||
runBackupNowMutation,
|
||||
} from "~/api-client/@tanstack/react-query.gen";
|
||||
import { parseError } from "~/lib/errors";
|
||||
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 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);
|
||||
|
||||
if (existingSchedule && repository && !isEditMode) {
|
||||
return (
|
||||
<ScheduleSummary
|
||||
handleToggleEnabled={handleToggleEnabled}
|
||||
handleRunBackupNow={handleRunBackupNow}
|
||||
repository={repository}
|
||||
setIsEditMode={setIsEditMode}
|
||||
schedule={existingSchedule}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
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 RESTIC_PASS_FILE = "/data/secrets/restic.pass";
|
||||
|
||||
@@ -14,8 +14,7 @@ services:
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
- /run/docker/plugins:/run/docker/plugins
|
||||
- ./data/volumes/:/var/lib/ironmount/volumes
|
||||
- /var/lib/repositories/:/var/lib/repositories
|
||||
- ./data/volumes/:/volumes
|
||||
# - /proc:/host/proc:ro
|
||||
- ./data:/data
|
||||
|
||||
|
||||
Reference in New Issue
Block a user