Skip to content

Commit befe219

Browse files
authored
Merge pull request #1581 from Dokploy/709-back-ups-for-dokploy
709 back ups for dokploy
2 parents 930a03d + f20c73c commit befe219

File tree

19 files changed

+11061
-182
lines changed

19 files changed

+11061
-182
lines changed

apps/dokploy/components/dashboard/database/backups/add-backup.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type AddPostgresBackup = z.infer<typeof AddPostgresBackup1Schema>;
6161

6262
interface Props {
6363
databaseId: string;
64-
databaseType: "postgres" | "mariadb" | "mysql" | "mongo";
64+
databaseType: "postgres" | "mariadb" | "mysql" | "mongo" | "web-server";
6565
refetch: () => void;
6666
}
6767

@@ -85,7 +85,7 @@ export const AddBackup = ({ databaseId, databaseType, refetch }: Props) => {
8585

8686
useEffect(() => {
8787
form.reset({
88-
database: "",
88+
database: databaseType === "web-server" ? "dokploy" : "",
8989
destinationId: "",
9090
enabled: true,
9191
prefix: "/",
@@ -112,7 +112,11 @@ export const AddBackup = ({ databaseId, databaseType, refetch }: Props) => {
112112
? {
113113
mongoId: databaseId,
114114
}
115-
: undefined;
115+
: databaseType === "web-server"
116+
? {
117+
userId: databaseId,
118+
}
119+
: undefined;
116120

117121
await createBackup({
118122
destinationId: data.destinationId,
@@ -236,7 +240,11 @@ export const AddBackup = ({ databaseId, databaseType, refetch }: Props) => {
236240
<FormItem>
237241
<FormLabel>Database</FormLabel>
238242
<FormControl>
239-
<Input placeholder={"dokploy"} {...field} />
243+
<Input
244+
disabled={databaseType === "web-server"}
245+
placeholder={"dokploy"}
246+
{...field}
247+
/>
240248
</FormControl>
241249
<FormMessage />
242250
</FormItem>

apps/dokploy/components/dashboard/database/backups/restore-backup.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ import { type LogLine, parseLogs } from "../../docker/logs/utils";
4747

4848
interface Props {
4949
databaseId: string;
50-
databaseType: Exclude<ServiceType, "application" | "redis">;
51-
serverId: string | null;
50+
databaseType: Exclude<ServiceType, "application" | "redis"> | "web-server";
51+
serverId?: string | null;
5252
}
5353

5454
const RestoreBackupSchema = z.object({
@@ -91,7 +91,7 @@ export const RestoreBackup = ({
9191
defaultValues: {
9292
destinationId: "",
9393
backupFile: "",
94-
databaseName: "",
94+
databaseName: databaseType === "web-server" ? "dokploy" : "",
9595
},
9696
resolver: zodResolver(RestoreBackupSchema),
9797
});
@@ -340,7 +340,11 @@ export const RestoreBackup = ({
340340
<FormItem className="">
341341
<FormLabel>Database Name</FormLabel>
342342
<FormControl>
343-
<Input {...field} placeholder="Enter database name" />
343+
<Input
344+
disabled={databaseType === "web-server"}
345+
{...field}
346+
placeholder="Enter database name"
347+
/>
344348
</FormControl>
345349
<FormMessage />
346350
</FormItem>

apps/dokploy/components/dashboard/database/backups/show-backups.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
TooltipTrigger,
1515
} from "@/components/ui/tooltip";
1616
import { api } from "@/utils/api";
17-
import { DatabaseBackup, Play, Trash2 } from "lucide-react";
17+
import { Database, DatabaseBackup, Play, Trash2 } from "lucide-react";
1818
import Link from "next/link";
1919
import { useState } from "react";
2020
import { toast } from "sonner";
@@ -25,7 +25,7 @@ import { UpdateBackup } from "./update-backup";
2525

2626
interface Props {
2727
id: string;
28-
type: Exclude<ServiceType, "application" | "redis">;
28+
type: Exclude<ServiceType, "application" | "redis"> | "web-server";
2929
}
3030
export const ShowBackups = ({ id, type }: Props) => {
3131
const [activeManualBackup, setActiveManualBackup] = useState<
@@ -38,6 +38,7 @@ export const ShowBackups = ({ id, type }: Props) => {
3838
mariadb: () =>
3939
api.mariadb.one.useQuery({ mariadbId: id }, { enabled: !!id }),
4040
mongo: () => api.mongo.one.useQuery({ mongoId: id }, { enabled: !!id }),
41+
"web-server": () => api.user.getBackups.useQuery(),
4142
};
4243
const { data } = api.destination.all.useQuery();
4344
const { data: postgres, refetch } = queryMap[type]
@@ -49,6 +50,7 @@ export const ShowBackups = ({ id, type }: Props) => {
4950
mysql: () => api.backup.manualBackupMySql.useMutation(),
5051
mariadb: () => api.backup.manualBackupMariadb.useMutation(),
5152
mongo: () => api.backup.manualBackupMongo.useMutation(),
53+
"web-server": () => api.backup.manualBackupWebServer.useMutation(),
5254
};
5355

5456
const { mutateAsync: manualBackup, isLoading: isManualBackup } = mutationMap[
@@ -64,7 +66,10 @@ export const ShowBackups = ({ id, type }: Props) => {
6466
<Card className="bg-background">
6567
<CardHeader className="flex flex-row justify-between gap-4 flex-wrap">
6668
<div className="flex flex-col gap-0.5">
67-
<CardTitle className="text-xl">Backups</CardTitle>
69+
<CardTitle className="text-xl flex flex-row gap-2">
70+
<Database className="size-6 text-muted-foreground" />
71+
Backups
72+
</CardTitle>
6873
<CardDescription>
6974
Add backups to your database to save the data to a different
7075
provider.
@@ -73,11 +78,17 @@ export const ShowBackups = ({ id, type }: Props) => {
7378

7479
{postgres && postgres?.backups?.length > 0 && (
7580
<div className="flex flex-col lg:flex-row gap-4 w-full lg:w-auto">
76-
<AddBackup databaseId={id} databaseType={type} refetch={refetch} />
81+
{type !== "web-server" && (
82+
<AddBackup
83+
databaseId={id}
84+
databaseType={type}
85+
refetch={refetch}
86+
/>
87+
)}
7788
<RestoreBackup
7889
databaseId={id}
7990
databaseType={type}
80-
serverId={postgres.serverId}
91+
serverId={"serverId" in postgres ? postgres.serverId : undefined}
8192
/>
8293
</div>
8394
)}
@@ -115,7 +126,9 @@ export const ShowBackups = ({ id, type }: Props) => {
115126
<RestoreBackup
116127
databaseId={id}
117128
databaseType={type}
118-
serverId={postgres.serverId}
129+
serverId={
130+
"serverId" in postgres ? postgres.serverId : undefined
131+
}
119132
/>
120133
</div>
121134
</div>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE "backup" ADD COLUMN "userId" text;--> statement-breakpoint
2+
ALTER TABLE "backup" ADD CONSTRAINT "backup_userId_user_temp_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user_temp"("id") ON DELETE no action ON UPDATE no action;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TYPE "public"."databaseType" ADD VALUE 'web-server';

0 commit comments

Comments
 (0)