Added ability to backup remote DB

Added ability to restore DB
This commit is contained in:
Isaac Abadi
2022-04-21 19:29:50 -04:00
parent 091f81bb38
commit a288163644
19 changed files with 420 additions and 29 deletions

View File

@@ -0,0 +1,29 @@
<h4 mat-dialog-title><ng-container i18n="Restore DB from backup">Restore DB from backup</ng-container></h4>
<mat-dialog-content>
<mat-selection-list [multiple]="false" [(ngModel)]="selected_backup">
<mat-list-option *ngFor="let db_backup of db_backups" [value]="db_backup.name" [matTooltip]="db_backup.name">
<div class="container-fluid">
<div class="row">
<div class="col-4">
{{db_backup.timestamp*1000 | date: 'short'}}
</div>
<div class="col-4">
{{(db_backup.size/1000).toFixed(2)}} kB
</div>
<div class="col-4" style="text-transform: capitalize;">
{{db_backup.source}}
</div>
</div>
</div>
</mat-list-option>
</mat-selection-list>
</mat-dialog-content>
<mat-dialog-actions>
<button mat-button mat-dialog-close><ng-container i18n="Restore DB cancel button">Cancel</ng-container></button>
<button mat-button [disabled]="restoring" (click)="restoreClicked()" [disabled]="!selected_backup || selected_backup.length !== 1"><ng-container i18n="Restore button">Restore</ng-container></button>
<div class="mat-spinner" *ngIf="restoring">
<mat-spinner [diameter]="25"></mat-spinner>
</div>
</mat-dialog-actions>

View File

@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RestoreDbDialogComponent } from './restore-db-dialog.component';
describe('RestoreDbDialogComponent', () => {
let component: RestoreDbDialogComponent;
let fixture: ComponentFixture<RestoreDbDialogComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ RestoreDbDialogComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(RestoreDbDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,47 @@
import { Component, Inject, OnInit } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { PostsService } from 'app/posts.services';
@Component({
selector: 'app-restore-db-dialog',
templateUrl: './restore-db-dialog.component.html',
styleUrls: ['./restore-db-dialog.component.scss']
})
export class RestoreDbDialogComponent implements OnInit {
db_backups = [];
selected_backup = null;
restoring = false;
constructor(@Inject(MAT_DIALOG_DATA) public data: any, private dialogRef: MatDialogRef<RestoreDbDialogComponent>, private postsService: PostsService) {
if (this.data?.db_backups) {
this.db_backups = this.data.db_backups;
}
this.getDBBackups();
}
ngOnInit(): void {
}
getDBBackups(): void {
this.postsService.getDBBackups().subscribe(res => {
this.db_backups = res['db_backups'];
});
}
restoreClicked(): void {
if (this.selected_backup.length !== 1) return;
this.postsService.restoreDBBackup(this.selected_backup[0]).subscribe(res => {
if (res['success']) {
this.postsService.openSnackBar('Database successfully restored!');
} else {
this.postsService.openSnackBar('Failed to restore database! See logs for more info.');
}
}, err => {
this.postsService.openSnackBar('Failed to restore database! See browser console for more info.');
console.error(err);
});
}
}