fix(backup): implement drag-and-drop restore, direct auto-download, and backup history log
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\AdminActivityLog;
|
||||
use App\Models\BackupLog;
|
||||
use App\Services\DatabaseBackupService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -29,11 +30,42 @@ class BackupController extends Controller
|
||||
$stats = $this->backupService->getSystemStats();
|
||||
$tableGroups = $this->backupService->getTableGroups();
|
||||
|
||||
return view('admin.backups.index', compact('backups', 'stats', 'tableGroups'));
|
||||
// Sinkronisasi file fisik di server ke riwayat BackupLog jika belum tercatat
|
||||
foreach ($backups as $b) {
|
||||
BackupLog::firstOrCreate(
|
||||
['filename' => $b['filename']],
|
||||
[
|
||||
'user_id' => auth()->id(),
|
||||
'user_name' => auth()->user()?->name ?? auth()->user()?->username ?? 'Super Admin',
|
||||
'scope' => $b['type'],
|
||||
'scope_label' => $b['type_label'],
|
||||
'table_count' => ($b['type'] === 'semua') ? count($this->backupService->getAllTableNames()) : 0,
|
||||
'tables_included' => null,
|
||||
'include_media' => ($b['type'] === 'semua'),
|
||||
'file_size' => $b['size_raw'],
|
||||
'file_size_human' => $b['size_human'],
|
||||
'status' => 'Tersimpan di Server',
|
||||
'created_at' => $b['created_at'],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// Ambil seluruh riwayat backup terurut dari yang terbaru
|
||||
$backupLogs = BackupLog::latest()->get();
|
||||
$backupDir = $this->backupService->getBackupDirectory();
|
||||
|
||||
// Tandai apakah file fisik masih ada di disk VPS server
|
||||
$backupLogs->each(function ($log) use ($backupDir) {
|
||||
$fullPath = $backupDir . DIRECTORY_SEPARATOR . $log->filename;
|
||||
$log->file_exists = File::exists($fullPath);
|
||||
});
|
||||
|
||||
return view('admin.backups.index', compact('backupLogs', 'backups', 'stats', 'tableGroups'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Buat file backup baru berekstensi khusus .kmh (Pilih Backup atau Backup Semua).
|
||||
* Otomatis memicu unduhan langsung ke komputer Super Admin demi menghemat disk VPS kecil.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
@@ -67,11 +99,30 @@ class BackupController extends Controller
|
||||
try {
|
||||
$filename = $this->backupService->createKmhBackup($selectedTables, $includeMedia);
|
||||
|
||||
$fullPath = $this->backupService->getBackupDirectory() . DIRECTORY_SEPARATOR . $filename;
|
||||
$sizeBytes = File::exists($fullPath) ? File::size($fullPath) : 0;
|
||||
$sizeHuman = $this->backupService->formatBytes($sizeBytes);
|
||||
|
||||
// Rekam ke Riwayat Aktivitas Backup
|
||||
BackupLog::create([
|
||||
'user_id' => $request->user()?->id,
|
||||
'user_name' => $request->user()?->name ?? $request->user()?->username ?? 'Super Admin',
|
||||
'filename' => $filename,
|
||||
'scope' => $scope,
|
||||
'scope_label' => $scopeLabel,
|
||||
'table_count' => is_array($selectedTables) ? count($selectedTables) : count($this->backupService->getAllTableNames()),
|
||||
'tables_included' => $selectedTables,
|
||||
'include_media' => $includeMedia,
|
||||
'file_size' => $sizeBytes,
|
||||
'file_size_human' => $sizeHuman,
|
||||
'status' => 'Berhasil Diunduh',
|
||||
]);
|
||||
|
||||
// Rekam ke Log Aktivitas Super Admin
|
||||
AdminActivityLog::record(
|
||||
actionType: 'create',
|
||||
module: 'Backup & Restore',
|
||||
description: "Membuat file backup terenkripsi .kmh: {$filename} [Cakupan: {$scopeLabel}].",
|
||||
description: "Membuat file backup terenkripsi .kmh: {$filename} [Cakupan: {$scopeLabel}]. File siap diunduh ke komputer lokal.",
|
||||
targetType: 'BackupFile',
|
||||
targetName: $filename,
|
||||
newValues: [
|
||||
@@ -79,10 +130,13 @@ class BackupController extends Controller
|
||||
'scope' => $scope,
|
||||
'table_count' => is_array($selectedTables) ? count($selectedTables) : 'all',
|
||||
'include_media' => $includeMedia,
|
||||
'size' => $sizeHuman,
|
||||
]
|
||||
);
|
||||
|
||||
return back()->with('success', "Arsip terenkripsi .kmh ({$filename}) berhasil dibuat dan diamankan di server.");
|
||||
return back()
|
||||
->with('success', "Arsip backup terenkripsi .kmh ({$filename}) berhasil dibuat dan langsung diunduh ke komputer Anda.")
|
||||
->with('auto_download', route('admin.backups.download', $filename));
|
||||
} catch (\Throwable $e) {
|
||||
return back()->with('error', 'Gagal membuat backup: ' . $e->getMessage());
|
||||
}
|
||||
@@ -97,7 +151,7 @@ class BackupController extends Controller
|
||||
$fullPath = $this->backupService->getBackupDirectory() . DIRECTORY_SEPARATOR . $filename;
|
||||
|
||||
if (!File::exists($fullPath)) {
|
||||
return back()->with('error', "File backup '{$filename}' tidak ditemukan di server.");
|
||||
return back()->with('error', "File backup '{$filename}' tidak ditemukan di server (kemungkinan telah dihapus untuk menghemat kapasitas disk VPS).");
|
||||
}
|
||||
|
||||
AdminActivityLog::record(
|
||||
@@ -120,6 +174,18 @@ class BackupController extends Controller
|
||||
*/
|
||||
public function upload(Request $request): RedirectResponse
|
||||
{
|
||||
// Validasi ketersediaan file dan deteksi error PHP upload limit
|
||||
if (!$request->hasFile('backup_file')) {
|
||||
$iniMax = ini_get('upload_max_filesize') ?: '2M';
|
||||
$postMax = ini_get('post_max_size') ?: '8M';
|
||||
return back()->with('error', "Gagal mengunggah file. Server tidak menerima berkas file (kemungkinan ukuran file melebihi batas konfigurasi PHP server: upload_max_filesize={$iniMax}, post_max_size={$postMax}).");
|
||||
}
|
||||
|
||||
$file = $request->file('backup_file');
|
||||
if (!$file->isValid()) {
|
||||
return back()->with('error', 'File yang diunggah tidak valid atau gagal terkirim: ' . $file->getErrorMessage());
|
||||
}
|
||||
|
||||
$request->validate([
|
||||
'backup_file' => ['required', 'file', 'max:204800'], // Maks. 200 MB
|
||||
], [
|
||||
@@ -128,7 +194,6 @@ class BackupController extends Controller
|
||||
'backup_file.max' => 'Ukuran file backup maksimal 200 MB.',
|
||||
]);
|
||||
|
||||
$file = $request->file('backup_file');
|
||||
$originalName = basename($file->getClientOriginalName());
|
||||
$ext = strtolower($file->getClientOriginalExtension());
|
||||
|
||||
@@ -146,23 +211,43 @@ class BackupController extends Controller
|
||||
|
||||
try {
|
||||
$file->move($targetDir, $targetFilename);
|
||||
$storedPath = $targetDir . DIRECTORY_SEPARATOR . $targetFilename;
|
||||
$fileSize = File::exists($storedPath) ? File::size($storedPath) : 0;
|
||||
$fileSizeHuman = $this->backupService->formatBytes($fileSize);
|
||||
|
||||
// Rekam ke Riwayat Aktivitas Backup
|
||||
BackupLog::firstOrCreate(
|
||||
['filename' => $targetFilename],
|
||||
[
|
||||
'user_id' => $request->user()?->id,
|
||||
'user_name' => $request->user()?->name ?? $request->user()?->username ?? 'Super Admin',
|
||||
'scope' => str_contains($targetFilename, 'semua') ? 'semua' : 'pilihan',
|
||||
'scope_label' => 'Unggahan Eksternal (' . strtoupper($ext) . ')',
|
||||
'table_count' => 0,
|
||||
'tables_included' => null,
|
||||
'include_media' => false,
|
||||
'file_size' => $fileSize,
|
||||
'file_size_human' => $fileSizeHuman,
|
||||
'status' => 'Tersimpan di Server',
|
||||
]
|
||||
);
|
||||
|
||||
AdminActivityLog::record(
|
||||
actionType: 'create',
|
||||
module: 'Backup & Restore',
|
||||
description: "Mengunggah file backup eksternal: {$targetFilename}.",
|
||||
description: "Mengunggah file backup eksternal: {$targetFilename} ({$fileSizeHuman}).",
|
||||
targetType: 'BackupFile',
|
||||
targetName: $targetFilename
|
||||
);
|
||||
|
||||
return back()->with('success', "File backup '{$targetFilename}' berhasil diunggah ke server.");
|
||||
return back()->with('success', "File backup '{$targetFilename}' ({$fileSizeHuman}) berhasil diunggah ke server.");
|
||||
} catch (\Throwable $e) {
|
||||
return back()->with('error', 'Gagal menyimpan file backup yang diunggah: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pulihkan (Restore) database & aset sistem dari file backup (.kmh).
|
||||
* Pulihkan (Restore) database & aset sistem dari file backup (.kmh) yang sudah ada di server.
|
||||
*/
|
||||
public function restore(Request $request, string $filename): RedirectResponse
|
||||
{
|
||||
@@ -195,7 +280,7 @@ class BackupController extends Controller
|
||||
AdminActivityLog::record(
|
||||
actionType: 'update',
|
||||
module: 'Backup & Restore',
|
||||
description: "Melakukan pemulihan (restore) database dan aset sistem dari file backup: {$filename}.",
|
||||
description: "Melakukan pemulihan (restore) database dan aset sistem dari file backup server: {$filename}.",
|
||||
targetType: 'BackupFile',
|
||||
targetName: $filename
|
||||
);
|
||||
@@ -207,24 +292,88 @@ class BackupController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Hapus file backup dari penyimpanan server.
|
||||
* Pulihkan (Restore) database & aset sistem secara langsung dari file (.kmh) yang diunggah/didrag & drop.
|
||||
* Tidak meninggalkan file sampah di server sehingga sangat hemat disk VPS.
|
||||
*/
|
||||
public function restoreFromFile(Request $request): RedirectResponse
|
||||
{
|
||||
if (!$request->hasFile('backup_file')) {
|
||||
$iniMax = ini_get('upload_max_filesize') ?: '2M';
|
||||
$postMax = ini_get('post_max_size') ?: '8M';
|
||||
return back()->with('error', "File backup .kmh belum dipilih atau file melebihi batas upload PHP server (upload_max_filesize: {$iniMax}, post_max_size: {$postMax}).");
|
||||
}
|
||||
|
||||
$file = $request->file('backup_file');
|
||||
if (!$file->isValid()) {
|
||||
return back()->with('error', 'File yang diunggah tidak valid atau gagal dibaca: ' . $file->getErrorMessage());
|
||||
}
|
||||
|
||||
$ext = strtolower($file->getClientOriginalExtension());
|
||||
if (!in_array($ext, ['kmh', 'sql', 'zip'])) {
|
||||
return back()->with('error', 'Format file tidak didukung. File backup harus berekstensi .kmh, .sql, atau .zip.');
|
||||
}
|
||||
|
||||
// Verifikasi Keamanan: Ketik "PULIHKAN" atau masukkan password Super Admin
|
||||
$confirmed = false;
|
||||
if ($request->filled('confirmation') && trim($request->input('confirmation')) === 'PULIHKAN') {
|
||||
$confirmed = true;
|
||||
} elseif ($request->filled('password') && Hash::check($request->input('password'), $request->user()->password)) {
|
||||
$confirmed = true;
|
||||
}
|
||||
|
||||
if (!$confirmed) {
|
||||
return back()->with('error', 'Konfirmasi keamanan tidak sesuai. Silakan ketik kata "PULIHKAN" atau masukkan password akun Super Admin Anda untuk melanjutkan pemulihan.');
|
||||
}
|
||||
|
||||
$tempPath = $file->getRealPath();
|
||||
$originalName = $file->getClientOriginalName();
|
||||
|
||||
try {
|
||||
$this->backupService->restore($tempPath);
|
||||
|
||||
// Bersihkan cache aplikasi & permission registrar Spatie
|
||||
Artisan::call('cache:clear');
|
||||
app()[PermissionRegistrar::class]->forgetCachedPermissions();
|
||||
|
||||
AdminActivityLog::record(
|
||||
actionType: 'update',
|
||||
module: 'Backup & Restore',
|
||||
description: "Melakukan pemulihan (restore) langsung dari file lokal: {$originalName}.",
|
||||
targetType: 'BackupFile',
|
||||
targetName: $originalName
|
||||
);
|
||||
|
||||
return back()->with('success', "Sistem berhasil dipulihkan secara langsung dari file '{$originalName}'. Seluruh data tabel dan media telah disinkronkan kembali.");
|
||||
} catch (\Throwable $e) {
|
||||
return back()->with('error', 'Terjadi kesalahan saat memulihkan sistem: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hapus file backup dari penyimpanan server untuk menghemat kapasitas disk VPS.
|
||||
* Riwayat log backup tetap tersimpan di sistem.
|
||||
*/
|
||||
public function destroy(string $filename): RedirectResponse
|
||||
{
|
||||
$filename = basename($filename);
|
||||
|
||||
if ($this->backupService->deleteBackup($filename)) {
|
||||
// Update status log jika ada
|
||||
BackupLog::where('filename', $filename)->update([
|
||||
'status' => 'Tersimpan di Komputer Lokal (Dihapus dari Server)',
|
||||
]);
|
||||
|
||||
AdminActivityLog::record(
|
||||
actionType: 'delete',
|
||||
module: 'Backup & Restore',
|
||||
description: "Menghapus file backup: {$filename}.",
|
||||
description: "Menghapus file fisik backup dari disk server: {$filename}.",
|
||||
targetType: 'BackupFile',
|
||||
targetName: $filename
|
||||
);
|
||||
|
||||
return back()->with('success', "File backup '{$filename}' berhasil dihapus dari server.");
|
||||
return back()->with('success', "File fisik '{$filename}' berhasil dihapus dari penyimpanan server untuk menghemat kapasitas disk VPS. Riwayat pencadangan tetap tersimpan.");
|
||||
}
|
||||
|
||||
return back()->with('error', "File backup '{$filename}' tidak ditemukan atau gagal dihapus.");
|
||||
return back()->with('error', "File backup '{$filename}' tidak ditemukan di server atau sudah pernah dihapus.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class BackupLog extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'user_name',
|
||||
'filename',
|
||||
'scope',
|
||||
'scope_label',
|
||||
'table_count',
|
||||
'tables_included',
|
||||
'include_media',
|
||||
'file_size',
|
||||
'file_size_human',
|
||||
'status',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'tables_included' => 'array',
|
||||
'include_media' => 'boolean',
|
||||
'file_size' => 'integer',
|
||||
'table_count' => 'integer',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -728,7 +728,7 @@ class DatabaseBackupService
|
||||
/**
|
||||
* Format byte ke satuan yang mudah dibaca (KB, MB, GB).
|
||||
*/
|
||||
protected function formatBytes(int $bytes, int $precision = 2): string
|
||||
public function formatBytes(int $bytes, int $precision = 2): string
|
||||
{
|
||||
if ($bytes <= 0) return '0 B';
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('backup_logs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->string('user_name')->nullable();
|
||||
$table->string('filename');
|
||||
$table->string('scope')->default('semua'); // 'semua' atau 'pilihan'
|
||||
$table->string('scope_label');
|
||||
$table->integer('table_count')->default(0);
|
||||
$table->json('tables_included')->nullable();
|
||||
$table->boolean('include_media')->default(false);
|
||||
$table->unsignedBigInteger('file_size')->default(0);
|
||||
$table->string('file_size_human')->nullable();
|
||||
$table->string('status')->default('Berhasil Diunduh');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('backup_logs');
|
||||
}
|
||||
};
|
||||
@@ -11,14 +11,19 @@
|
||||
Backup & Restore Sistem
|
||||
</h1>
|
||||
<p class="text-xs text-slate-500 mt-0.5">
|
||||
Pencadangan terenkripsi berformat <code>.kmh</code> khusus untuk sistem RKM-KMH. File tidak dapat dibaca oleh sistem luar.
|
||||
Pencadangan terenkripsi berformat <code>.kmh</code> khusus untuk sistem RKM-KMH. Langsung unduh ke komputer lokal dan hemat kapasitas disk VPS server.
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-2.5">
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<button type="button"
|
||||
onclick="openDirectRestoreModal()"
|
||||
class="px-3.5 py-2 rounded-xl border border-amber-300 bg-amber-50 hover:bg-amber-100 text-amber-900 text-xs font-semibold transition shadow-2xs">
|
||||
Pulihkan dari File .kmh
|
||||
</button>
|
||||
<button type="button"
|
||||
onclick="openUploadBackupModal()"
|
||||
class="px-3.5 py-2 rounded-xl border border-slate-200 bg-white hover:bg-slate-50 text-slate-700 text-xs font-semibold transition shadow-2xs">
|
||||
Unggah File .kmh
|
||||
Unggah ke Server
|
||||
</button>
|
||||
<button type="button"
|
||||
onclick="openCreateBackupModal()"
|
||||
@@ -28,40 +33,75 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Alert Notifikasi Flash -->
|
||||
<!-- Alert Notifikasi Flash & Validasi Error -->
|
||||
@if(session('success'))
|
||||
<div class="p-3.5 bg-emerald-50 border border-emerald-200 rounded-xl flex items-center justify-between text-emerald-900 text-xs font-medium">
|
||||
<div class="p-3.5 bg-emerald-50 border border-emerald-200 rounded-xl flex items-center justify-between text-emerald-900 text-xs font-medium animate-fade-in">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="inline-block w-2 h-2 rounded-full bg-emerald-500"></span>
|
||||
<span>{{ session('success') }}</span>
|
||||
</div>
|
||||
<button type="button" onclick="this.parentElement.remove()" class="text-emerald-500 hover:text-emerald-700 ml-3 text-sm">×</button>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if(session('error'))
|
||||
<div class="p-3.5 bg-rose-50 border border-rose-200 rounded-xl flex items-center justify-between text-rose-900 text-xs font-medium">
|
||||
<div class="p-3.5 bg-rose-50 border border-rose-200 rounded-xl flex items-center justify-between text-rose-900 text-xs font-medium animate-fade-in">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="inline-block w-2 h-2 rounded-full bg-rose-500"></span>
|
||||
<span>{{ session('error') }}</span>
|
||||
</div>
|
||||
<button type="button" onclick="this.parentElement.remove()" class="text-rose-500 hover:text-rose-700 ml-3 text-sm">×</button>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<!-- Ringkasan Metrik (Clean & Tanpa Ikon Berlebihan) -->
|
||||
<div class="grid grid-cols-1 sm:grid-cols-3 gap-4">
|
||||
<div class="bg-white rounded-2xl border border-slate-200/80 p-4 shadow-2xs">
|
||||
<span class="text-[11px] font-semibold text-slate-400 uppercase tracking-wider block">Total File Backup</span>
|
||||
<div class="flex items-baseline gap-2 mt-1.5">
|
||||
<span class="text-2xl font-bold text-slate-900">{{ number_format($stats['total_backups']) }}</span>
|
||||
<span class="text-xs text-slate-500 font-medium">file (.kmh)</span>
|
||||
@if($errors->any())
|
||||
<div class="p-3.5 bg-rose-50 border border-rose-200 rounded-xl text-rose-900 text-xs font-medium animate-fade-in">
|
||||
<div class="flex items-center justify-between mb-1 font-bold">
|
||||
<span>Terdapat kesalahan validasi:</span>
|
||||
<button type="button" onclick="this.parentElement.parentElement.remove()" class="text-rose-500 hover:text-rose-700 text-sm">×</button>
|
||||
</div>
|
||||
<span class="text-[11px] text-slate-400 block mt-1">Total kapasitas: {{ $stats['total_size_human'] }}</span>
|
||||
<ul class="list-disc list-inside space-y-0.5 text-[11px] text-rose-700">
|
||||
@foreach($errors->all() as $err)
|
||||
<li>{{ $err }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<!-- Ringkasan Metrik (Clean & Tanpa Ikon Berlebihan) -->
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 gap-4">
|
||||
<div class="bg-white rounded-2xl border border-slate-200/80 p-4 shadow-2xs">
|
||||
<span class="text-[11px] font-semibold text-slate-400 uppercase tracking-wider block">Total Aktivitas Backup</span>
|
||||
<div class="flex items-baseline gap-2 mt-1.5">
|
||||
<span class="text-2xl font-bold text-slate-900">{{ number_format($backupLogs->count()) }}</span>
|
||||
<span class="text-xs text-slate-500 font-medium">kali dicadangkan</span>
|
||||
</div>
|
||||
<span class="text-[11px] text-slate-400 block mt-1">
|
||||
Tersedia di server: {{ $backups ? count($backups) : 0 }} file ({{ $stats['total_size_human'] ?? '0 B' }})
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="bg-white rounded-2xl border border-slate-200/80 p-4 shadow-2xs">
|
||||
<span class="text-[11px] font-semibold text-slate-400 uppercase tracking-wider block">Kapasitas Disk Server VPS</span>
|
||||
<div class="flex items-baseline gap-2 mt-1.5">
|
||||
<span class="text-2xl font-bold text-slate-900">{{ $stats['total_size_human'] ?? '0 B' }}</span>
|
||||
<span class="text-xs text-emerald-600 font-medium">Hemat Ruang</span>
|
||||
</div>
|
||||
<span class="text-[11px] text-slate-400 block mt-1">Unduhan langsung ke PC membebaskan storage VPS</span>
|
||||
</div>
|
||||
|
||||
<div class="bg-white rounded-2xl border border-slate-200/80 p-4 shadow-2xs">
|
||||
<span class="text-[11px] font-semibold text-slate-400 uppercase tracking-wider block">Backup Terakhir</span>
|
||||
<div class="mt-1.5">
|
||||
<span class="text-sm font-bold text-slate-900 block truncate">
|
||||
<span class="text-xs font-bold text-slate-900 block truncate">
|
||||
@if($backupLogs->isNotEmpty())
|
||||
{{ $backupLogs->first()->created_at?->translatedFormat('d M Y, H:i') }} WIB
|
||||
@else
|
||||
{{ $stats['last_backup']['created_at_human'] ?? 'Belum ada backup' }}
|
||||
@endif
|
||||
</span>
|
||||
<span class="text-[11px] text-slate-400 block mt-1 truncate font-mono">
|
||||
{{ $stats['last_backup']['filename'] ?? '-' }}
|
||||
{{ $backupLogs->first()->filename ?? ($stats['last_backup']['filename'] ?? '-') }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -76,97 +116,151 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tabel Daftar File Backup -->
|
||||
<!-- Tabel Riwayat Aktivitas Backup & Arsip -->
|
||||
<div class="bg-white border border-slate-200/80 rounded-2xl shadow-2xs overflow-hidden">
|
||||
<div class="px-5 py-3.5 border-b border-slate-100 flex items-center justify-between">
|
||||
<h2 class="text-xs font-bold uppercase tracking-wider text-slate-600">
|
||||
Daftar Arsip Backup
|
||||
<div class="px-5 py-3.5 border-b border-slate-100 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2">
|
||||
<div>
|
||||
<h2 class="text-xs font-bold uppercase tracking-wider text-slate-700">
|
||||
Riwayat Aktivitas Backup & Arsip
|
||||
</h2>
|
||||
<span class="text-[11px] text-slate-400 font-mono">
|
||||
storage/app/backups/
|
||||
<p class="text-[11px] text-slate-400 mt-0.5">
|
||||
Mencatat tanggal, jenis data yang dicadangkan, dan riwayat arsip terenkripsi .kmh.
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-2 text-[11px] text-slate-500">
|
||||
<span class="inline-flex items-center gap-1.5">
|
||||
<span class="w-2 h-2 rounded-full bg-emerald-500"></span>
|
||||
Tersedia di Server
|
||||
</span>
|
||||
<span class="text-slate-300">•</span>
|
||||
<span class="inline-flex items-center gap-1.5">
|
||||
<span class="w-2 h-2 rounded-full bg-slate-400"></span>
|
||||
Tersimpan di PC Lokal
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="overflow-x-auto">
|
||||
<table class="w-full text-left text-xs">
|
||||
<thead>
|
||||
<tr class="bg-slate-50/70 border-b border-slate-100 text-slate-400 font-bold uppercase tracking-wider text-[10px]">
|
||||
<th class="py-3 px-5">Nama File</th>
|
||||
<th class="py-3 px-4">Tipe Backup</th>
|
||||
<th class="py-3 px-5">Tanggal & Waktu</th>
|
||||
<th class="py-3 px-4">Nama File Arsip</th>
|
||||
<th class="py-3 px-4">Jenis / Cakupan Backup</th>
|
||||
<th class="py-3 px-4">Ukuran</th>
|
||||
<th class="py-3 px-4">Tanggal Dibuat</th>
|
||||
<th class="py-3 px-4">Status & Lokasi</th>
|
||||
<th class="py-3 px-5 text-right">Aksi</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-slate-100 font-medium">
|
||||
@forelse($backups as $b)
|
||||
@forelse($backupLogs as $log)
|
||||
@php
|
||||
$isFull = ($b['type'] === 'semua');
|
||||
$isFull = ($log->scope === 'semua');
|
||||
$hasServerFile = (bool) $log->file_exists;
|
||||
@endphp
|
||||
<tr class="hover:bg-slate-50/50 transition">
|
||||
<!-- Tanggal & Waktu -->
|
||||
<td class="py-3 px-5 whitespace-nowrap">
|
||||
<span class="font-semibold text-slate-900 block">
|
||||
{{ $log->created_at?->translatedFormat('d M Y, H:i') }} WIB
|
||||
</span>
|
||||
<span class="text-[11px] text-slate-400 block">
|
||||
{{ $log->created_at?->diffForHumans() }}
|
||||
</span>
|
||||
</td>
|
||||
|
||||
<!-- Nama File -->
|
||||
<td class="py-3 px-5">
|
||||
<td class="py-3 px-4">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="font-mono font-semibold text-slate-800 text-xs">
|
||||
{{ $b['filename'] }}
|
||||
{{ $log->filename }}
|
||||
</span>
|
||||
@if($b['is_kmh'])
|
||||
<span class="px-1.5 py-0.2 rounded text-[9px] font-bold bg-indigo-50 text-indigo-700 border border-indigo-200">
|
||||
.kmh
|
||||
</span>
|
||||
@endif
|
||||
</div>
|
||||
<span class="text-[11px] text-slate-400 block mt-0.5">
|
||||
Oleh: {{ $log->user_name ?? 'Super Admin' }}
|
||||
</span>
|
||||
</td>
|
||||
|
||||
<!-- Tipe Backup -->
|
||||
<td class="py-3 px-4 whitespace-nowrap">
|
||||
<!-- Jenis / Cakupan Backup -->
|
||||
<td class="py-3 px-4">
|
||||
@if($isFull)
|
||||
<span class="inline-block px-2 py-0.5 rounded text-[11px] font-semibold bg-emerald-50 text-emerald-800 border border-emerald-200">
|
||||
Backup Semua
|
||||
</span>
|
||||
<span class="text-[11px] text-slate-500 block mt-0.5">
|
||||
29 Tabel + Media Upload
|
||||
</span>
|
||||
@else
|
||||
<span class="inline-block px-2 py-0.5 rounded text-[11px] font-semibold bg-slate-100 text-slate-700 border border-slate-200">
|
||||
<span class="inline-block px-2 py-0.5 rounded text-[11px] font-semibold bg-indigo-50 text-indigo-800 border border-indigo-200">
|
||||
Pilih Backup
|
||||
</span>
|
||||
<span class="text-[11px] text-slate-500 block mt-0.5">
|
||||
{{ $log->table_count > 0 ? $log->table_count . ' Tabel Terpilih' : ($log->scope_label ?? 'Tabel Terpilih') }}
|
||||
@if($log->include_media)
|
||||
+ Media
|
||||
@endif
|
||||
</span>
|
||||
@endif
|
||||
</td>
|
||||
|
||||
<!-- Ukuran File -->
|
||||
<td class="py-3 px-4 whitespace-nowrap font-mono text-slate-600">
|
||||
{{ $b['size_human'] }}
|
||||
{{ $log->file_size_human ?: '-' }}
|
||||
</td>
|
||||
|
||||
<!-- Tanggal Dibuat -->
|
||||
<td class="py-3 px-4 whitespace-nowrap text-slate-600">
|
||||
<span>{{ $b['created_at_human'] }}</span>
|
||||
<!-- Status & Lokasi -->
|
||||
<td class="py-3 px-4 whitespace-nowrap">
|
||||
@if($hasServerFile)
|
||||
<span class="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-[11px] font-semibold bg-emerald-50 text-emerald-700 border border-emerald-200">
|
||||
<span class="w-1.5 h-1.5 rounded-full bg-emerald-500"></span>
|
||||
Tersedia di Server
|
||||
</span>
|
||||
@else
|
||||
<span class="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-[11px] font-semibold bg-slate-100 text-slate-600 border border-slate-200">
|
||||
<span class="w-1.5 h-1.5 rounded-full bg-slate-400"></span>
|
||||
Tersimpan di PC Lokal
|
||||
</span>
|
||||
@endif
|
||||
</td>
|
||||
|
||||
<!-- Aksi (Clean text buttons) -->
|
||||
<td class="py-3 px-5 text-right whitespace-nowrap">
|
||||
<div class="inline-flex items-center gap-1.5">
|
||||
<a href="{{ route('admin.backups.download', $b['filename']) }}"
|
||||
@if($hasServerFile)
|
||||
<a href="{{ route('admin.backups.download', $log->filename) }}"
|
||||
class="px-2.5 py-1 rounded-lg border border-slate-200 bg-white hover:bg-slate-50 text-slate-700 font-semibold text-[11px] transition">
|
||||
Unduh
|
||||
</a>
|
||||
|
||||
<button type="button"
|
||||
onclick="openRestoreModal('{{ $b['filename'] }}', '{{ $b['type_label'] }}', '{{ $b['size_human'] }}')"
|
||||
onclick="openRestoreModal('{{ $log->filename }}', '{{ $log->scope_label }}', '{{ $log->file_size_human }}')"
|
||||
class="px-2.5 py-1 rounded-lg border border-amber-300 bg-amber-50 hover:bg-amber-100 text-amber-900 font-semibold text-[11px] transition">
|
||||
Pulihkan
|
||||
</button>
|
||||
|
||||
<button type="button"
|
||||
onclick="openDeleteBackupModal('{{ $b['filename'] }}')"
|
||||
onclick="openDeleteBackupModal('{{ $log->filename }}')"
|
||||
title="Hapus file fisik dari VPS untuk menghemat kapasitas disk"
|
||||
class="px-2.5 py-1 rounded-lg border border-rose-200 bg-white hover:bg-rose-50 text-rose-700 font-semibold text-[11px] transition">
|
||||
Hapus
|
||||
Hapus dari Server
|
||||
</button>
|
||||
@else
|
||||
<button type="button"
|
||||
onclick="openDirectRestoreModal()"
|
||||
class="px-2.5 py-1 rounded-lg border border-amber-300 bg-amber-50 hover:bg-amber-100 text-amber-900 font-semibold text-[11px] transition">
|
||||
Pulihkan dari File PC
|
||||
</button>
|
||||
@endif
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="5" class="py-10 text-center">
|
||||
<p class="text-xs text-slate-500 font-medium">Belum ada file backup yang tersimpan di server.</p>
|
||||
<td colspan="6" class="py-10 text-center">
|
||||
<p class="text-xs text-slate-500 font-medium">Belum ada riwayat pencadangan data sistem.</p>
|
||||
<button type="button"
|
||||
onclick="openCreateBackupModal()"
|
||||
class="mt-2.5 px-3.5 py-1.5 bg-indigo-600 hover:bg-indigo-700 text-white rounded-xl text-xs font-semibold transition">
|
||||
@@ -190,7 +284,7 @@
|
||||
<div class="px-5 py-4 border-b border-slate-100 flex items-center justify-between flex-shrink-0">
|
||||
<div>
|
||||
<h3 class="text-base font-bold text-slate-900">Buat Backup Baru</h3>
|
||||
<p class="text-xs text-slate-400 mt-0.5">Pilih mode pencadangan terenkripsi berformat .kmh.</p>
|
||||
<p class="text-xs text-slate-400 mt-0.5">Pilih mode pencadangan terenkripsi berformat .kmh (Otomatis langsung diunduh ke komputer Anda).</p>
|
||||
</div>
|
||||
<button type="button" onclick="closeCreateBackupModal()" class="text-slate-400 hover:text-slate-600 text-lg p-1">×</button>
|
||||
</div>
|
||||
@@ -199,6 +293,11 @@
|
||||
@csrf
|
||||
|
||||
<div class="p-5 space-y-4 overflow-y-auto flex-1">
|
||||
<!-- Banner info VPS Ramah Disk -->
|
||||
<div class="p-3 bg-indigo-50/60 border border-indigo-100 rounded-xl text-xs text-indigo-900 leading-relaxed">
|
||||
<strong>Pemberitahuan Penyimpanan VPS:</strong> Setelah pencadangan selesai, file <code>.kmh</code> akan <strong>langsung otomatis diunduh ke komputer Anda</strong>. Anda tidak perlu khawatir server VPS penuh karena file fisik di server dapat dihapus sewaktu-waktu.
|
||||
</div>
|
||||
|
||||
<!-- Dua Pilihan Utama -->
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3">
|
||||
<!-- Opsi 1: Pilih Backup (Tabel Tertentu) -->
|
||||
@@ -232,7 +331,7 @@
|
||||
<div>
|
||||
<span class="block text-xs font-bold text-slate-900">Backup Semua</span>
|
||||
<span class="block text-[11px] text-slate-500 mt-0.5 leading-relaxed">
|
||||
Cadangkan seluruh tabel database (29 tabel) + seluruh file media upload.
|
||||
Cadangkan seluruh tabel database ({{ $stats['table_count'] ?? 29 }} tabel) + seluruh file media upload.
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -307,7 +406,7 @@
|
||||
Batal
|
||||
</button>
|
||||
<button type="submit" id="createBackupSubmitBtn" class="px-4 py-2 rounded-xl bg-indigo-600 hover:bg-indigo-700 text-white font-semibold text-xs transition shadow-xs">
|
||||
<span id="createBackupBtnText">Mulai Pencadangan (.kmh)</span>
|
||||
<span id="createBackupBtnText">Mulai Pencadangan (.kmh) & Unduh Langsung</span>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
@@ -315,24 +414,135 @@
|
||||
</div>
|
||||
|
||||
<!-- ========================================================================= -->
|
||||
<!-- MODAL: UNGGAH FILE BACKUP (.KMH) -->
|
||||
<!-- MODAL: PULIHKAN LANGSUNG DARI FILE .KMH LOKAL (DRAG & DROP 1-STEP RESTORE) -->
|
||||
<!-- ========================================================================= -->
|
||||
<div id="directRestoreModal" data-backdrop="static" class="fixed inset-0 z-50 hidden bg-slate-900/50 backdrop-blur-xs flex items-center justify-center p-4">
|
||||
<div class="bg-white rounded-2xl max-w-lg w-full shadow-xl overflow-hidden animate-scale-in border border-slate-100">
|
||||
<div class="px-5 py-4 bg-amber-50/70 border-b border-amber-100 flex items-center justify-between">
|
||||
<div>
|
||||
<h3 class="text-base font-bold text-amber-900">Pulihkan Sistem dari File .kmh</h3>
|
||||
<p class="text-xs text-amber-700 mt-0.5">Restore langsung dari file backup di komputer lokal Anda (Drag & Drop).</p>
|
||||
</div>
|
||||
<button type="button" onclick="closeDirectRestoreModal()" class="text-slate-400 hover:text-slate-600 text-lg p-1">×</button>
|
||||
</div>
|
||||
|
||||
<form id="directRestoreForm" method="POST" action="{{ route('admin.backups.restore_file') }}" enctype="multipart/form-data" onsubmit="handleDirectRestoreSubmit(this)" class="p-5 space-y-4">
|
||||
@csrf
|
||||
|
||||
<div class="p-3 rounded-xl bg-rose-50 border border-rose-200 text-xs text-rose-900 leading-relaxed">
|
||||
<strong>Perhatian:</strong> Proses ini akan menggantikan dan menyinkronkan data sistem saat ini dengan arsip <code>.kmh</code> yang Anda pulihkan.
|
||||
</div>
|
||||
|
||||
<!-- Dropzone Area Interaktif dengan Drag & Drop -->
|
||||
<div>
|
||||
<label class="block text-xs font-semibold text-slate-700 mb-1.5">Pilih atau Drag & Drop File .kmh</label>
|
||||
<div id="directRestoreDropzone"
|
||||
class="border-2 border-dashed border-slate-300 hover:border-amber-500 rounded-2xl p-6 text-center bg-slate-50 hover:bg-white transition cursor-pointer select-none"
|
||||
onclick="document.getElementById('directRestoreFileInput').click()"
|
||||
ondragover="handleDropzoneDragOver(event, this)"
|
||||
ondragleave="handleDropzoneDragLeave(event, this)"
|
||||
ondrop="handleDropzoneDrop(event, this, 'directRestoreFileInput', 'directRestoreFileDisplay')">
|
||||
|
||||
<div id="directRestorePrompt">
|
||||
<div class="w-10 h-10 rounded-full bg-amber-100 text-amber-700 mx-auto flex items-center justify-center mb-2 font-bold text-sm">
|
||||
KMH
|
||||
</div>
|
||||
<p class="text-xs font-bold text-slate-800" id="directRestoreFileName">Tarik & Letakkan file .kmh di sini</p>
|
||||
<p class="text-[11px] text-slate-400 mt-1">atau <span class="text-amber-700 font-semibold underline">klik untuk memilih dari komputer Anda</span></p>
|
||||
<p class="text-[10px] text-slate-400 mt-1.5">Format didukung: .kmh terenkripsi (Maks. 200 MB)</p>
|
||||
</div>
|
||||
|
||||
<div id="directRestoreFileDisplay" class="hidden mt-1 p-3 rounded-xl bg-amber-50 border border-amber-200 text-left">
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<span class="font-mono font-bold text-xs text-amber-950 block" id="directRestorePillName">file.kmh</span>
|
||||
<span class="text-[11px] text-amber-700 block mt-0.5" id="directRestorePillSize">0 MB</span>
|
||||
</div>
|
||||
<span class="px-2 py-0.5 rounded text-[10px] font-bold bg-amber-200 text-amber-900">
|
||||
File Siap
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input type="file"
|
||||
name="backup_file"
|
||||
id="directRestoreFileInput"
|
||||
accept=".kmh,.sql,.zip"
|
||||
required
|
||||
class="hidden"
|
||||
onchange="handleDirectRestoreFileChange(this)">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Konfirmasi Keamanan -->
|
||||
<div>
|
||||
<label class="block text-xs font-semibold text-slate-800 mb-1">
|
||||
Ketik kata <span class="font-mono font-bold text-slate-900 bg-slate-100 px-1 py-0.5 rounded">PULIHKAN</span> atau masukkan password Anda:
|
||||
</label>
|
||||
<input type="text"
|
||||
name="confirmation"
|
||||
id="directRestoreConfirmationInput"
|
||||
placeholder="PULIHKAN atau password..."
|
||||
required
|
||||
autocomplete="off"
|
||||
class="w-full text-xs px-3 py-2 rounded-xl border border-slate-200 focus:outline-none focus:border-amber-500 font-semibold">
|
||||
</div>
|
||||
|
||||
<div class="pt-3 border-t border-slate-100 flex items-center justify-end gap-2.5">
|
||||
<button type="button" onclick="closeDirectRestoreModal()" class="px-3.5 py-2 rounded-xl border border-slate-200 bg-white text-slate-600 font-semibold text-xs transition">
|
||||
Batal
|
||||
</button>
|
||||
<button type="submit" id="directRestoreSubmitBtn" class="px-4 py-2 rounded-xl bg-amber-600 hover:bg-amber-700 text-white font-semibold text-xs transition shadow-xs">
|
||||
<span id="directRestoreBtnText">Mulai Pemulihan Sistem</span>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ========================================================================= -->
|
||||
<!-- MODAL: UNGGAH FILE BACKUP (.KMH) KE SERVER -->
|
||||
<!-- ========================================================================= -->
|
||||
<div id="uploadBackupModal" data-backdrop="static" class="fixed inset-0 z-50 hidden bg-slate-900/50 backdrop-blur-xs flex items-center justify-center p-4">
|
||||
<div class="bg-white rounded-2xl max-w-md w-full shadow-xl overflow-hidden animate-scale-in border border-slate-100">
|
||||
<div class="px-5 py-4 border-b border-slate-100 flex items-center justify-between">
|
||||
<div>
|
||||
<h3 class="text-base font-bold text-slate-900">Unggah File Backup (.kmh)</h3>
|
||||
<p class="text-xs text-slate-400 mt-0.5">Simpan salinan file arsip .kmh ke storage server.</p>
|
||||
</div>
|
||||
<button type="button" onclick="closeUploadBackupModal()" class="text-slate-400 hover:text-slate-600 text-lg p-1">×</button>
|
||||
</div>
|
||||
|
||||
<form id="uploadBackupForm" method="POST" action="{{ route('admin.backups.upload') }}" enctype="multipart/form-data" class="p-5 space-y-4">
|
||||
<form id="uploadBackupForm" method="POST" action="{{ route('admin.backups.upload') }}" enctype="multipart/form-data" onsubmit="handleUploadSubmit(this)" class="p-5 space-y-4">
|
||||
@csrf
|
||||
|
||||
<div>
|
||||
<label class="block text-xs font-semibold text-slate-700 mb-2">Pilih File .kmh</label>
|
||||
<div class="border-2 border-dashed border-slate-300 hover:border-indigo-500 rounded-xl p-5 text-center bg-slate-50 hover:bg-white transition cursor-pointer"
|
||||
onclick="document.getElementById('backupFileInput').click()">
|
||||
<p class="text-xs font-bold text-slate-800" id="uploadFileName">Klik untuk memilih file</p>
|
||||
<p class="text-[11px] text-slate-400 mt-1">Format arsip terenkripsi: .kmh (Maks. 200 MB)</p>
|
||||
<label class="block text-xs font-semibold text-slate-700 mb-1.5">Pilih atau Drag & Drop File .kmh</label>
|
||||
<div id="uploadDropzone"
|
||||
class="border-2 border-dashed border-slate-300 hover:border-indigo-500 rounded-2xl p-6 text-center bg-slate-50 hover:bg-white transition cursor-pointer select-none"
|
||||
onclick="document.getElementById('backupFileInput').click()"
|
||||
ondragover="handleDropzoneDragOver(event, this)"
|
||||
ondragleave="handleDropzoneDragLeave(event, this)"
|
||||
ondrop="handleDropzoneDrop(event, this, 'backupFileInput', 'uploadFileDisplay')">
|
||||
|
||||
<div id="uploadPrompt">
|
||||
<p class="text-xs font-bold text-slate-800" id="uploadFileName">Tarik & Letakkan file .kmh di sini</p>
|
||||
<p class="text-[11px] text-slate-400 mt-1">atau <span class="text-indigo-600 font-semibold underline">klik untuk memilih file</span></p>
|
||||
<p class="text-[10px] text-slate-400 mt-1.5">Format arsip: .kmh (Maks. 200 MB)</p>
|
||||
</div>
|
||||
|
||||
<div id="uploadFileDisplay" class="hidden mt-1 p-3 rounded-xl bg-indigo-50 border border-indigo-200 text-left">
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<span class="font-mono font-bold text-xs text-indigo-950 block" id="uploadPillName">file.kmh</span>
|
||||
<span class="text-[11px] text-indigo-700 block mt-0.5" id="uploadPillSize">0 MB</span>
|
||||
</div>
|
||||
<span class="px-2 py-0.5 rounded text-[10px] font-bold bg-indigo-200 text-indigo-900">
|
||||
Siap Diunggah
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input type="file"
|
||||
name="backup_file"
|
||||
id="backupFileInput"
|
||||
@@ -347,8 +557,8 @@
|
||||
<button type="button" onclick="closeUploadBackupModal()" class="px-3.5 py-2 rounded-xl border border-slate-200 bg-white text-slate-600 font-semibold text-xs transition">
|
||||
Batal
|
||||
</button>
|
||||
<button type="submit" class="px-4 py-2 rounded-xl bg-indigo-600 hover:bg-indigo-700 text-white font-semibold text-xs transition shadow-xs">
|
||||
Unggah File
|
||||
<button type="submit" id="uploadSubmitBtn" class="px-4 py-2 rounded-xl bg-indigo-600 hover:bg-indigo-700 text-white font-semibold text-xs transition shadow-xs">
|
||||
<span id="uploadBtnText">Unggah ke Server</span>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
@@ -356,7 +566,7 @@
|
||||
</div>
|
||||
|
||||
<!-- ========================================================================= -->
|
||||
<!-- MODAL: KONFIRMASI PEMULIHAN (RESTORE) -->
|
||||
<!-- MODAL: KONFIRMASI PEMULIHAN (RESTORE DARI FILE SERVER) -->
|
||||
<!-- ========================================================================= -->
|
||||
<div id="restoreModal" data-backdrop="static" class="fixed inset-0 z-50 hidden bg-slate-900/50 backdrop-blur-xs flex items-center justify-center p-4">
|
||||
<div class="bg-white rounded-2xl max-w-md w-full shadow-xl overflow-hidden animate-scale-in border border-slate-100">
|
||||
@@ -405,13 +615,13 @@
|
||||
</div>
|
||||
|
||||
<!-- ========================================================================= -->
|
||||
<!-- MODAL: KONFIRMASI HAPUS -->
|
||||
<!-- MODAL: KONFIRMASI HAPUS DARI SERVER -->
|
||||
<!-- ========================================================================= -->
|
||||
<div id="deleteBackupModal" data-backdrop="static" class="fixed inset-0 z-50 hidden bg-slate-900/50 backdrop-blur-xs flex items-center justify-center p-4">
|
||||
<div class="bg-white rounded-2xl max-w-sm w-full p-5 shadow-xl border border-slate-100 text-center">
|
||||
<h3 class="text-sm font-bold text-slate-900">Hapus File Backup?</h3>
|
||||
<h3 class="text-sm font-bold text-slate-900">Hapus File dari Server?</h3>
|
||||
<p class="text-xs text-slate-500 mt-1">
|
||||
File <span id="deleteBackupFilename" class="font-mono font-semibold text-slate-800"></span> akan dihapus permanen dari server.
|
||||
File fisik <span id="deleteBackupFilename" class="font-mono font-semibold text-slate-800"></span> akan dihapus dari disk VPS untuk menghemat kapasitas server. Riwayat aktivitas backup tetap tercatat.
|
||||
</p>
|
||||
|
||||
<form id="deleteBackupForm" method="POST" action="" class="mt-5 flex items-center justify-center gap-2">
|
||||
@@ -421,14 +631,33 @@
|
||||
Batal
|
||||
</button>
|
||||
<button type="submit" class="flex-1 px-3 py-2 bg-rose-600 hover:bg-rose-700 text-white rounded-xl text-xs font-semibold transition">
|
||||
Hapus
|
||||
Hapus dari Server
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Auto-Download Script jika ada sesi auto_download -->
|
||||
@if(session('auto_download'))
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const downloadUrl = @json(session('auto_download'));
|
||||
if (downloadUrl) {
|
||||
const a = document.createElement('a');
|
||||
a.href = downloadUrl;
|
||||
a.setAttribute('download', '');
|
||||
document.body.appendChild(a);
|
||||
setTimeout(() => {
|
||||
a.click();
|
||||
a.remove();
|
||||
}, 300);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@endif
|
||||
|
||||
<!-- ========================================================================= -->
|
||||
<!-- JAVASCRIPT LOGIC INTERAKTIF -->
|
||||
<!-- JAVASCRIPT LOGIC INTERAKTIF LENGKAP -->
|
||||
<!-- ========================================================================= -->
|
||||
<script>
|
||||
function toggleBackupScopeUI(scope) {
|
||||
@@ -479,9 +708,10 @@
|
||||
btn.disabled = true;
|
||||
btn.classList.add('opacity-75', 'cursor-not-allowed');
|
||||
}
|
||||
if (text) text.textContent = 'Memproses Arsip .kmh...';
|
||||
if (text) text.textContent = 'Membuat Arsip & Menyiapkan Unduhan...';
|
||||
}
|
||||
|
||||
/* Modal Unggah Backup */
|
||||
function openUploadBackupModal() {
|
||||
document.getElementById('uploadBackupModal').classList.remove('hidden');
|
||||
document.documentElement.classList.add('modal-open');
|
||||
@@ -493,12 +723,108 @@
|
||||
}
|
||||
|
||||
function handleUploadFileChange(input) {
|
||||
const nameDisplay = document.getElementById('uploadFileName');
|
||||
if (input.files && input.files[0]) {
|
||||
nameDisplay.textContent = input.files[0].name + ' (' + (input.files[0].size / 1024 / 1024).toFixed(2) + ' MB)';
|
||||
const file = input.files[0];
|
||||
const sizeHuman = (file.size / (1024 * 1024)).toFixed(2) + ' MB';
|
||||
document.getElementById('uploadPillName').textContent = file.name;
|
||||
document.getElementById('uploadPillSize').textContent = sizeHuman;
|
||||
document.getElementById('uploadPrompt').classList.add('hidden');
|
||||
document.getElementById('uploadFileDisplay').classList.remove('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
function handleUploadSubmit(form) {
|
||||
const btn = document.getElementById('uploadSubmitBtn');
|
||||
const text = document.getElementById('uploadBtnText');
|
||||
if (btn) {
|
||||
btn.disabled = true;
|
||||
btn.classList.add('opacity-75', 'cursor-not-allowed');
|
||||
}
|
||||
if (text) text.textContent = 'Mengunggah Berkas ke Server...';
|
||||
}
|
||||
|
||||
/* Modal Pulihkan Langsung dari File .kmh */
|
||||
function openDirectRestoreModal() {
|
||||
document.getElementById('directRestoreModal').classList.remove('hidden');
|
||||
document.documentElement.classList.add('modal-open');
|
||||
}
|
||||
|
||||
function closeDirectRestoreModal() {
|
||||
document.getElementById('directRestoreModal').classList.add('hidden');
|
||||
document.documentElement.classList.remove('modal-open');
|
||||
}
|
||||
|
||||
function handleDirectRestoreFileChange(input) {
|
||||
if (input.files && input.files[0]) {
|
||||
const file = input.files[0];
|
||||
const sizeHuman = (file.size / (1024 * 1024)).toFixed(2) + ' MB';
|
||||
document.getElementById('directRestorePillName').textContent = file.name;
|
||||
document.getElementById('directRestorePillSize').textContent = sizeHuman;
|
||||
document.getElementById('directRestorePrompt').classList.add('hidden');
|
||||
document.getElementById('directRestoreFileDisplay').classList.remove('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
function handleDirectRestoreSubmit(form) {
|
||||
const fileInput = document.getElementById('directRestoreFileInput');
|
||||
if (!fileInput.files || fileInput.files.length === 0) {
|
||||
alert('Silakan pilih atau seret file .kmh terlebih dahulu.');
|
||||
return false;
|
||||
}
|
||||
|
||||
const btn = document.getElementById('directRestoreSubmitBtn');
|
||||
const text = document.getElementById('directRestoreBtnText');
|
||||
if (btn) {
|
||||
btn.disabled = true;
|
||||
btn.classList.add('opacity-75', 'cursor-not-allowed');
|
||||
}
|
||||
if (text) text.textContent = 'Memvalidasi & Memulihkan Sistem...';
|
||||
}
|
||||
|
||||
/* Drag and Drop Handlers (Universal) */
|
||||
function handleDropzoneDragOver(e, dropzone) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
dropzone.classList.add('border-indigo-500', 'bg-indigo-50/30', 'scale-[1.01]');
|
||||
}
|
||||
|
||||
function handleDropzoneDragLeave(e, dropzone) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
dropzone.classList.remove('border-indigo-500', 'bg-indigo-50/30', 'scale-[1.01]');
|
||||
}
|
||||
|
||||
function handleDropzoneDrop(e, dropzone, inputId, displayId) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
dropzone.classList.remove('border-indigo-500', 'bg-indigo-50/30', 'scale-[1.01]');
|
||||
|
||||
if (e.dataTransfer && e.dataTransfer.files && e.dataTransfer.files.length > 0) {
|
||||
const file = e.dataTransfer.files[0];
|
||||
const input = document.getElementById(inputId);
|
||||
|
||||
// Validasi ekstensi
|
||||
const filename = file.name.toLowerCase();
|
||||
if (!filename.endsWith('.kmh') && !filename.endsWith('.sql') && !filename.endsWith('.zip')) {
|
||||
alert('File yang diunggah harus berformat arsip terenkripsi .kmh (atau .sql / .zip). File Anda: ' + file.name);
|
||||
return;
|
||||
}
|
||||
|
||||
// Lampirkan file ke input form menggunakan DataTransfer
|
||||
const dataTransfer = new DataTransfer();
|
||||
dataTransfer.items.add(file);
|
||||
input.files = dataTransfer.files;
|
||||
|
||||
// Trigger handler tampilan
|
||||
if (inputId === 'directRestoreFileInput') {
|
||||
handleDirectRestoreFileChange(input);
|
||||
} else if (inputId === 'backupFileInput') {
|
||||
handleUploadFileChange(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Modal Restore Server File */
|
||||
function openRestoreModal(filename, typeLabel, sizeHuman) {
|
||||
document.getElementById('restoreForm').action = `/admin/backups/${encodeURIComponent(filename)}/restore`;
|
||||
document.getElementById('restoreTargetFilename').textContent = filename;
|
||||
@@ -522,6 +848,7 @@
|
||||
if (text) text.textContent = 'Memulihkan Sistem...';
|
||||
}
|
||||
|
||||
/* Modal Delete Backup File */
|
||||
function openDeleteBackupModal(filename) {
|
||||
document.getElementById('deleteBackupForm').action = `/admin/backups/${encodeURIComponent(filename)}`;
|
||||
document.getElementById('deleteBackupFilename').textContent = filename;
|
||||
|
||||
@@ -221,6 +221,7 @@ Route::middleware('auth')->group(function () {
|
||||
// Backup & Restore Sistem (Database & Media)
|
||||
Route::get('/backups', [BackupController::class, 'index'])->name('backups.index');
|
||||
Route::post('/backups', [BackupController::class, 'store'])->name('backups.store');
|
||||
Route::post('/backups/restore-file', [BackupController::class, 'restoreFromFile'])->name('backups.restore_file');
|
||||
Route::get('/backups/{filename}/download', [BackupController::class, 'download'])->name('backups.download');
|
||||
Route::post('/backups/upload', [BackupController::class, 'upload'])->name('backups.upload');
|
||||
Route::post('/backups/{filename}/restore', [BackupController::class, 'restore'])->name('backups.restore');
|
||||
|
||||
@@ -269,4 +269,45 @@ class BackupAndRestoreTest extends TestCase
|
||||
$this->assertStringContainsString('[email protected]', $sqlContent);
|
||||
$this->assertStringNotContainsString('[email protected]', $sqlContent);
|
||||
}
|
||||
|
||||
public function test_backup_creation_records_to_backup_logs_and_sets_auto_download(): void
|
||||
{
|
||||
$response = $this->actingAs($this->superAdmin)
|
||||
->post(route('admin.backups.store'), [
|
||||
'backup_scope' => 'pilihan',
|
||||
'selected_tables' => ['users'],
|
||||
]);
|
||||
|
||||
$response->assertSessionHas('success');
|
||||
$response->assertSessionHas('auto_download');
|
||||
|
||||
$this->assertDatabaseHas('backup_logs', [
|
||||
'user_id' => $this->superAdmin->id,
|
||||
'scope' => 'pilihan',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_super_admin_can_restore_directly_from_uploaded_kmh_file(): void
|
||||
{
|
||||
$filename = $this->backupService->createKmhBackup(['users'], false, 'test_direct_restore.kmh');
|
||||
$fullPath = $this->backupService->getBackupDirectory() . DIRECTORY_SEPARATOR . $filename;
|
||||
$kmhContent = file_get_contents($fullPath);
|
||||
|
||||
$uploadedFile = UploadedFile::fake()->createWithContent('backup_dari_pc.kmh', $kmhContent);
|
||||
|
||||
$response = $this->actingAs($this->superAdmin)
|
||||
->post(route('admin.backups.restore_file'), [
|
||||
'backup_file' => $uploadedFile,
|
||||
'confirmation' => 'PULIHKAN',
|
||||
]);
|
||||
|
||||
$response->assertSessionHas('success');
|
||||
$response->assertSessionMissing('error');
|
||||
|
||||
$this->assertDatabaseHas('admin_activity_logs', [
|
||||
'action_type' => 'update',
|
||||
'module' => 'Backup & Restore',
|
||||
'target_name' => 'backup_dari_pc.kmh',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user