Skip to content

Commit 172694b

Browse files
authored
Merge pull request #1530 from Dokploy/feat/add-date-to-restore-item
feat(backup): enhance RestoreBackup component and API to include serv…
2 parents 4fa5e10 + ea6cfc9 commit 172694b

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import { toast } from "sonner";
4848
interface Props {
4949
databaseId: string;
5050
databaseType: Exclude<ServiceType, "application" | "redis">;
51+
serverId: string | null;
5152
}
5253

5354
const RestoreBackupSchema = z.object({
@@ -76,7 +77,11 @@ const RestoreBackupSchema = z.object({
7677

7778
type RestoreBackup = z.infer<typeof RestoreBackupSchema>;
7879

79-
export const RestoreBackup = ({ databaseId, databaseType }: Props) => {
80+
export const RestoreBackup = ({
81+
databaseId,
82+
databaseType,
83+
serverId,
84+
}: Props) => {
8085
const [isOpen, setIsOpen] = useState(false);
8186
const [search, setSearch] = useState("");
8287

@@ -101,6 +106,7 @@ export const RestoreBackup = ({ databaseId, databaseType }: Props) => {
101106
{
102107
destinationId: destionationId,
103108
search,
109+
serverId: serverId ?? "",
104110
},
105111
{
106112
enabled: isOpen && !!destionationId,
@@ -304,7 +310,9 @@ export const RestoreBackup = ({ databaseId, databaseType }: Props) => {
304310
form.setValue("backupFile", file);
305311
}}
306312
>
307-
{file}
313+
<div className="flex w-full justify-between">
314+
<span>{file}</span>
315+
</div>
308316
<CheckIcon
309317
className={cn(
310318
"ml-auto h-4 w-4",

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ export const ShowBackups = ({ id, type }: Props) => {
7474
{postgres && postgres?.backups?.length > 0 && (
7575
<div className="flex flex-col lg:flex-row gap-4 w-full lg:w-auto">
7676
<AddBackup databaseId={id} databaseType={type} refetch={refetch} />
77-
<RestoreBackup databaseId={id} databaseType={type} />
77+
<RestoreBackup
78+
databaseId={id}
79+
databaseType={type}
80+
serverId={postgres.serverId}
81+
/>
7882
</div>
7983
)}
8084
</CardHeader>
@@ -108,7 +112,11 @@ export const ShowBackups = ({ id, type }: Props) => {
108112
databaseType={type}
109113
refetch={refetch}
110114
/>
111-
<RestoreBackup databaseId={id} databaseType={type} />
115+
<RestoreBackup
116+
databaseId={id}
117+
databaseType={type}
118+
serverId={postgres.serverId}
119+
/>
112120
</div>
113121
</div>
114122
) : (

apps/dokploy/server/api/routers/backup.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ import {
3131

3232
import { TRPCError } from "@trpc/server";
3333
import { z } from "zod";
34-
import { execAsync } from "@dokploy/server/utils/process/execAsync";
34+
import {
35+
execAsync,
36+
execAsyncRemote,
37+
} from "@dokploy/server/utils/process/execAsync";
3538
import { getS3Credentials } from "@dokploy/server/utils/backups/utils";
3639
import { findDestinationById } from "@dokploy/server/services/destination";
3740
import {
@@ -229,6 +232,7 @@ export const backupRouter = createTRPCRouter({
229232
z.object({
230233
destinationId: z.string(),
231234
search: z.string(),
235+
serverId: z.string().optional(),
232236
}),
233237
)
234238
.query(async ({ input }) => {
@@ -250,7 +254,16 @@ export const backupRouter = createTRPCRouter({
250254
const searchPath = baseDir ? `${bucketPath}/${baseDir}` : bucketPath;
251255
const listCommand = `rclone lsf ${rcloneFlags.join(" ")} "${searchPath}" | head -n 100`;
252256

253-
const { stdout } = await execAsync(listCommand);
257+
let stdout = "";
258+
259+
if (input.serverId) {
260+
const result = await execAsyncRemote(listCommand, input.serverId);
261+
stdout = result.stdout;
262+
} else {
263+
const result = await execAsync(listCommand);
264+
stdout = result.stdout;
265+
}
266+
254267
const files = stdout.split("\n").filter(Boolean);
255268

256269
const results = baseDir

0 commit comments

Comments
 (0)