maziggy 3 months ago
parent
commit
9787400935

+ 20 - 4
backend/app/api/routes/settings.py

@@ -1,4 +1,5 @@
 import io
+import logging
 import zipfile
 from datetime import datetime
 from pathlib import Path
@@ -16,6 +17,8 @@ from backend.app.models.settings import Settings
 from backend.app.models.user import User
 from backend.app.schemas.settings import AppSettings, AppSettingsUpdate
 
+logger = logging.getLogger(__name__)
+
 router = APIRouter(prefix="/settings", tags=["settings"])
 
 # Default settings
@@ -311,6 +314,7 @@ async def restore_backup(
     from fastapi import HTTPException
 
     from backend.app.core.database import close_all_connections
+    from backend.app.services.virtual_printer import virtual_printer_manager
 
     base_dir = app_settings.base_dir
     db_path = Path(app_settings.database_url.replace("sqlite+aiosqlite:///", ""))
@@ -336,13 +340,18 @@ async def restore_backup(
         if not backup_db.exists():
             raise HTTPException(400, "Invalid backup: missing bambuddy.db")
 
-        # 3. Close current database connections
+        # 3. Stop virtual printer if running (releases file locks)
+        vp_was_enabled = virtual_printer_manager.is_enabled
+        if vp_was_enabled:
+            await virtual_printer_manager.configure(enabled=False)
+
+        # 4. Close current database connections
         await close_all_connections()
 
-        # 4. Replace database
+        # 5. Replace database
         shutil.copy2(backup_db, db_path)
 
-        # 5. Replace data directories
+        # 6. Replace data directories
         dirs_to_restore = [
             ("archive", base_dir / "archive"),
             ("virtual_printer", base_dir / "virtual_printer"),
@@ -358,7 +367,14 @@ async def restore_backup(
                     shutil.rmtree(dest_dir)
                 shutil.copytree(src_dir, dest_dir)
 
-        # 6. Note: Database connection will be reinitialized on restart
+        # 7. Restart virtual printer if it was running before
+        if vp_was_enabled:
+            try:
+                await virtual_printer_manager.configure(enabled=True)
+            except Exception as e:
+                logger.warning(f"Failed to restart virtual printer after restore: {e}")
+
+        # 8. Note: Database connection will be reinitialized on restart
         # The application should be restarted after restore
 
         return {

+ 5 - 0
frontend/src/components/GitHubBackupSettings.tsx

@@ -1,4 +1,5 @@
 import { useState, useEffect, useRef, useCallback } from 'react';
+import { useTranslation } from 'react-i18next';
 import { useQuery, useQueries, useMutation, useQueryClient } from '@tanstack/react-query';
 import {
   Github,
@@ -96,6 +97,7 @@ function formatRelativeTime(dateStr: string | null): string {
 export function GitHubBackupSettings() {
   const queryClient = useQueryClient();
   const { showToast } = useToast();
+  const { t } = useTranslation();
 
   // Local state for form
   const [repoUrl, setRepoUrl] = useState('');
@@ -766,6 +768,9 @@ export function GitHubBackupSettings() {
                 <p className="text-sm text-bambu-gray">
                   Replace all data from a backup file
                 </p>
+                <p className="text-xs text-bambu-gray-light mt-1">
+                  {t('backup.restoreNote')}
+                </p>
               </div>
               <input
                 ref={fileInputRef}

+ 1 - 0
frontend/src/i18n/locales/de.ts

@@ -2252,6 +2252,7 @@ export default {
     restoreSuccess: 'Sicherung erfolgreich wiederhergestellt',
     backupFailed: 'Sicherung fehlgeschlagen',
     restoreFailed: 'Wiederherstellung fehlgeschlagen',
+    restoreNote: 'Virtueller Drucker wird nach der Wiederherstellung neu gestartet',
   },
 
   // Tags

+ 1 - 0
frontend/src/i18n/locales/en.ts

@@ -2252,6 +2252,7 @@ export default {
     restoreSuccess: 'Backup restored successfully',
     backupFailed: 'Backup failed',
     restoreFailed: 'Restore failed',
+    restoreNote: 'Virtual Printer will be restarted after restore',
   },
 
   // Tags

+ 1 - 0
frontend/src/i18n/locales/ja.ts

@@ -1784,6 +1784,7 @@ export default {
     projectsDescription: 'プロジェクト、BOMアイテム、添付ファイル',
     pendingUploadsDescription: 'レビュー待ちの仮想プリンターアップロード',
     apiKeysDescription: 'Webhook APIキー(インポート時に新しいキーが生成されます)',
+    restoreNote: '復元後、仮想プリンターが再起動されます',
   },
 
   // Restore modal

File diff suppressed because it is too large
+ 0 - 0
static/assets/index-Bye0cNCS.js


+ 1 - 1
static/index.html

@@ -23,7 +23,7 @@
 
     <!-- Splash screens for iOS -->
     <link rel="apple-touch-startup-image" href="/img/android-chrome-512x512.png" />
-    <script type="module" crossorigin src="/assets/index-DsWy8xQD.js"></script>
+    <script type="module" crossorigin src="/assets/index-Bye0cNCS.js"></script>
     <link rel="stylesheet" crossorigin href="/assets/index-DME4t7XG.css">
   </head>
   <body>

Some files were not shown because too many files changed in this diff