feat(backups): add one-click copy button for database restore commands

This commit is contained in:
Urvish Prajapati 2026-11-02 16:03:47 +05:30
parent 56cb400c19
commit a69b804a2a
1 changed files with 54 additions and 14 deletions

View File

@ -1,5 +1,5 @@
import React from 'react';
import { Database, BookOpen, Download, RefreshCw, CheckCircle, AlertCircle, ShieldCheck } from 'lucide-react';
import React, { useState } from 'react';
import { Database, BookOpen, Download, RefreshCw, CheckCircle, AlertCircle, ShieldCheck, Copy, Check } from 'lucide-react';
interface DatabaseBackupTabProps {
dbInfo: any | null;
@ -20,6 +20,20 @@ export const DatabaseBackupTab: React.FC<DatabaseBackupTabProps> = ({
onRefresh,
onDownloadBackup,
}) => {
const [copiedSnippet, setCopiedSnippet] = useState(false);
const restoreSnippetText = `# 1. Restore directly via pipeline into Docker or host database:
gunzip -c panaceadb_backup_full_latest.sql.gz | docker exec -i panacea-postgres psql -U postgres -d panaceadb
# 2. Or uncompress first and inspect the raw SQL statements:
gunzip panaceadb_backup_full_latest.sql.gz
head -n 40 panaceadb_backup_full_latest.sql`;
const handleCopySnippet = () => {
navigator.clipboard.writeText(restoreSnippetText);
setCopiedSnippet(true);
setTimeout(() => setCopiedSnippet(false), 2000);
};
return (
<div className="space-y-6">
{/* Top Header Card */}
@ -201,21 +215,47 @@ export const DatabaseBackupTab: React.FC<DatabaseBackupTabProps> = ({
In the event of a system rebuild or migration, you can restore any downloaded snapshot file directly using standard PostgreSQL CLI utilities:
</p>
<div className="bg-slate-900 rounded-2xl p-4 font-mono text-xs text-slate-200 space-y-2 overflow-x-auto shadow-inner">
<div className="text-slate-400 text-[11px] font-semibold"># 1. Restore directly via pipeline into Docker or host database:</div>
<div className="text-emerald-400 font-bold">
gunzip -c panaceadb_backup_full_latest.sql.gz | docker exec -i panacea-postgres psql -U postgres -d panaceadb
</div>
<div className="text-slate-400 text-[11px] font-semibold pt-1"># 2. Or uncompress first and inspect the raw SQL statements:</div>
<div className="text-indigo-300">
gunzip panaceadb_backup_full_latest.sql.gz
</div>
<div className="text-indigo-300">
head -n 40 panaceadb_backup_full_latest.sql
<div className="relative group bg-slate-900 rounded-2xl p-4 sm:p-5 font-mono text-xs text-slate-200 shadow-inner">
{/* Copy Button */}
<button
type="button"
onClick={handleCopySnippet}
className={`absolute top-3 right-3 flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-xs font-sans font-bold transition-all cursor-pointer shadow-xs border ${
copiedSnippet
? 'bg-emerald-500/20 border-emerald-500/40 text-emerald-400'
: 'bg-slate-800/90 hover:bg-slate-700 border-slate-700/80 text-slate-300 hover:text-white'
}`}
title="Copy restore commands to clipboard"
>
{copiedSnippet ? (
<>
<Check className="h-3.5 w-3.5 text-emerald-400" />
<span>Copied!</span>
</>
) : (
<>
<Copy className="h-3.5 w-3.5 text-slate-400" />
<span className="hidden sm:inline">Copy Snippet</span>
</>
)}
</button>
<div className="overflow-x-auto space-y-2 pr-12 sm:pr-28">
<div className="text-slate-400 text-[11px] font-semibold"># 1. Restore directly via pipeline into Docker or host database:</div>
<div className="text-emerald-400 font-bold whitespace-pre">
gunzip -c panaceadb_backup_full_latest.sql.gz | docker exec -i panacea-postgres psql -U postgres -d panaceadb
</div>
<div className="text-slate-400 text-[11px] font-semibold pt-1"># 2. Or uncompress first and inspect the raw SQL statements:</div>
<div className="text-indigo-300 whitespace-pre">
gunzip panaceadb_backup_full_latest.sql.gz
</div>
<div className="text-indigo-300 whitespace-pre">
head -n 40 panaceadb_backup_full_latest.sql
</div>
</div>
</div>
<div className="flex items-center justify-between text-[11px] text-slate-400 font-semibold pt-1">
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-1 text-[11px] text-slate-400 font-semibold pt-1">
<span>PostgreSQL Engine: {dbInfo?.postgres_version || '16.14'}</span>
<span>Internal Host: {dbInfo?.host || 'db'}:{dbInfo?.port || 5432}</span>
</div>