Compare commits
No commits in common. "master" and "style-app" have entirely different histories.
1
backend/.gitignore
vendored
1
backend/.gitignore
vendored
@ -1 +0,0 @@
|
|||||||
__pycache__
|
|
||||||
Binary file not shown.
Binary file not shown.
@ -1,6 +1,5 @@
|
|||||||
import subprocess
|
import subprocess
|
||||||
import json
|
import json
|
||||||
import re
|
|
||||||
|
|
||||||
def get_namespaces():
|
def get_namespaces():
|
||||||
output = subprocess.check_output(["kubectl", "get", "ns", "-o", "json"])
|
output = subprocess.check_output(["kubectl", "get", "ns", "-o", "json"])
|
||||||
@ -11,18 +10,3 @@ def get_pvcs(namespace: str):
|
|||||||
output = subprocess.check_output(["kubectl", "get", "pvc", "-n", namespace, "-o", "json"])
|
output = subprocess.check_output(["kubectl", "get", "pvc", "-n", namespace, "-o", "json"])
|
||||||
data = json.loads(output)
|
data = json.loads(output)
|
||||||
return [item["metadata"]["name"] for item in data["items"]]
|
return [item["metadata"]["name"] for item in data["items"]]
|
||||||
|
|
||||||
def get_all_backup_pvcs():
|
|
||||||
output = subprocess.check_output(["kubectl", "get", "pvc", "-A", "-o", "json"])
|
|
||||||
data = json.loads(output)
|
|
||||||
|
|
||||||
backup_pvcs = []
|
|
||||||
for item in data["items"]:
|
|
||||||
name = item["metadata"]["name"]
|
|
||||||
namespace = item["metadata"]["namespace"]
|
|
||||||
if re.match(r"^snapix-bkp-temp-", name):
|
|
||||||
backup_pvcs.append({
|
|
||||||
"name": name,
|
|
||||||
"namespace": namespace
|
|
||||||
})
|
|
||||||
return backup_pvcs
|
|
||||||
@ -1,7 +1,7 @@
|
|||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from models import BackupRequest, RestoreRequest
|
from models import BackupRequest, RestoreRequest
|
||||||
from k8s_utils import get_namespaces, get_pvcs, get_all_backup_pvcs
|
from k8s_utils import get_namespaces, get_pvcs
|
||||||
from backup_manager import create_backup, restore_backup
|
from backup_manager import create_backup, restore_backup
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
@ -33,11 +33,6 @@ def restore_pvc(request: RestoreRequest):
|
|||||||
return {"message": "Restore job created."}
|
return {"message": "Restore job created."}
|
||||||
|
|
||||||
|
|
||||||
@app.get("/backup-pvcs")
|
|
||||||
def list_backup_pvcs():
|
|
||||||
return get_all_backup_pvcs()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import uvicorn
|
import uvicorn
|
||||||
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)
|
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)
|
||||||
@ -8,5 +8,3 @@ export const getNamespaces = () => api.get('/namespaces');
|
|||||||
export const getPVCs = (namespace) => api.get(`/pvcs/${namespace}`);
|
export const getPVCs = (namespace) => api.get(`/pvcs/${namespace}`);
|
||||||
export const createBackup = (payload) => api.post('/backup', payload);
|
export const createBackup = (payload) => api.post('/backup', payload);
|
||||||
export const restoreBackup = (payload) => api.post('/restore', payload);
|
export const restoreBackup = (payload) => api.post('/restore', payload);
|
||||||
export const getBackupPVCs = () => api.get('/backup-pvcs');
|
|
||||||
|
|
||||||
|
|||||||
@ -1,30 +1,12 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { restoreBackup, getNamespaces, getBackupPVCs } from '../api/snapix';
|
import { restoreBackup } from '../api/snapix';
|
||||||
import { Button } from '@mui/base';
|
import { Button, Input } from '@mui/base'
|
||||||
import '../style/RestoreForm.css';
|
import '../style/RestoreForm.css'; // Assuming you have some styles for the form
|
||||||
|
|
||||||
export default function RestoreForm() {
|
export default function RestoreForm() {
|
||||||
const [backupName, setBackupName] = useState('');
|
const [backupName, setBackupName] = useState('');
|
||||||
const [targetNs, setTargetNs] = useState('');
|
const [targetNs, setTargetNs] = useState('');
|
||||||
const [targetPvc, setTargetPvc] = useState('');
|
const [targetPvc, setTargetPvc] = useState('');
|
||||||
const [namespaces, setNamespaces] = useState([]);
|
|
||||||
const [backupPvcs, setBackupPvcs] = useState([]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
getNamespaces().then(res => setNamespaces(res.data));
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (targetNs) {
|
|
||||||
getBackupPVCs().then(res => {
|
|
||||||
// Filter backup PVCs only for the selected namespace
|
|
||||||
const filtered = res.data.filter(pvc => pvc.namespace === targetNs);
|
|
||||||
setBackupPvcs(filtered);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
setBackupPvcs([]);
|
|
||||||
}
|
|
||||||
}, [targetNs]);
|
|
||||||
|
|
||||||
const handleRestore = () => {
|
const handleRestore = () => {
|
||||||
if (backupName && targetNs && targetPvc) {
|
if (backupName && targetNs && targetPvc) {
|
||||||
@ -33,52 +15,45 @@ export default function RestoreForm() {
|
|||||||
target_namespace: targetNs,
|
target_namespace: targetNs,
|
||||||
target_pvc: targetPvc,
|
target_pvc: targetPvc,
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
alert('Restore started!');
|
alert("Restore started!");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="form-group">
|
<div className='form-group'>
|
||||||
<h2>🔁 Restore PVC</h2>
|
<h2>🔁 Restore PVC</h2>
|
||||||
|
<div className='form-content'>
|
||||||
<div className="form-content">
|
<label>Backup Name:</label>
|
||||||
<label>Target Namespace:</label>
|
<Input
|
||||||
<select value={targetNs} onChange={e => setTargetNs(e.target.value)}>
|
type="text"
|
||||||
<option value="">-- Select Namespace --</option>
|
|
||||||
{namespaces.map(ns => (
|
|
||||||
<option key={ns} value={ns}>{ns}</option>
|
|
||||||
))}
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="form-content">
|
|
||||||
<label>Backup PVC:</label>
|
|
||||||
<select
|
|
||||||
value={backupName}
|
value={backupName}
|
||||||
onChange={e => setBackupName(e.target.value)}
|
onChange={e => setBackupName(e.target.value)}
|
||||||
disabled={!targetNs}
|
className='restore-input'
|
||||||
>
|
|
||||||
<option value="">-- Select Backup PVC --</option>
|
|
||||||
{backupPvcs.map(({ name }) => (
|
|
||||||
<option key={name} value={name}>{name}</option>
|
|
||||||
))}
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="form-content">
|
|
||||||
<label>Target PVC:</label>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
value={targetPvc}
|
|
||||||
onChange={e => setTargetPvc(e.target.value)}
|
|
||||||
placeholder="the exact name of the pvc of your app"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Button id="restore-btn" className="btn" onClick={handleRestore}>
|
<div className='form-content'>
|
||||||
Restore
|
<label>Target Namespace:</label>
|
||||||
</Button>
|
<Input
|
||||||
|
type="text"
|
||||||
|
value={targetNs}
|
||||||
|
onChange={e => setTargetNs(e.target.value)}
|
||||||
|
className='restore-input'
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='form-content'>
|
||||||
|
<label>Target PVC:</label>
|
||||||
|
<Input
|
||||||
|
type="text"
|
||||||
|
value={targetPvc}
|
||||||
|
onChange={e => setTargetPvc(e.target.value)}
|
||||||
|
className='restore-input'
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Button id='restore-btn' className='btn' onClick={handleRestore}>Restore</Button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user