Doc timascale backup and restore.

This commit is contained in:
Фролов 2021-12-03 17:34:24 +05:00
parent eac44db77f
commit fa3e47493b
3 changed files with 46 additions and 18 deletions

View File

@ -1,28 +1,53 @@
создать миграцию
# Миграции
## создать миграцию
```
dotnet ef migrations add <MigrationName> --project AsbCloudDb
```
создать миграцию
## откатить миграцию
```
dotnet ef migrations remvoe <MigrationName> --project AsbCloudDb
```
<MigrationName> - Name of migration class
После создания миграции обязательно прочитать сгенерированый код.
Применить миграции
## Применить миграции
При старте проекта применяются автоматически
```
dotnet ef database update --project .\AsbCloudDb
```
```
#backup
```
sudo -u postgres pg_dump -Fc -U postgres postgres -W | gzip > 2021-09-27_dump.sql.gz
sudo -u postgres pg_dump -Fc -U postgres postgres -W > 2021-11-26_dump.sql
```
# Backup
Terminal:
```
sudo -u postgres pg_dump -Fc -U postgres postgres -W > dump_2021-11-26.bak
```
#restore
```
psql postgres < dump_file_name
```
sudo -u postgres psql -p 5499 -U postgres postgres -W < 2021-11-16_dump.sql.gz
# Restore backup
## Step 1. (Re)Create DB and schema IF needeed.
psql:
```
--drop schema public cascade;
CREATE DATABASE postgres;
\c postgres
create schema public;
```
## Step 2. Innit timescaledb and prepare DB to restore
```
CREATE EXTENSION IF NOT EXISTS timescaledb;
SELECT timescaledb_pre_restore();
```
## Step 3. Restore DB, then 'exit resore mode'. [Longest operation]
Terminal:
```
sudo -u postgres psql -p 5499 -U postgres postgres -W < dump_2021-11-26.bak
```
OR psql:
```
\! pg_restore -Fc -d postgres dump_2021-11-26.bak
```
Then psql:
```
SELECT timescaledb_post_restore();
```

View File

@ -89,6 +89,7 @@ namespace AsbCloudInfrastructure.Services
var idTelemetry = well?.IdTelemetry ?? default;
var filterByDateEnd = dateBegin != default;
if (dateBegin == default)
{
dateBegin = telemetryService.GetLastTelemetryDate(idTelemetry);
@ -113,8 +114,10 @@ namespace AsbCloudInfrastructure.Services
var query = dbSet
.Where(d => d.IdTelemetry == idTelemetry
&& d.Date >= dateBegin
&& d.Date < dateEnd);
&& d.Date >= dateBegin);
if (filterByDateEnd)
query = query.Where(d => d.Date < dateEnd);
var fullDataCount = await query.CountAsync(token)
.ConfigureAwait(false);

View File

@ -8,7 +8,7 @@ namespace AsbCloudWebApi.Controllers
[Route("api/admin/role")]
[ApiController]
[Authorize]
public class AdminUserRoleController : CrudController<UserRoleDto, ICrudService<UserRoleDto>>
public class AdminUserRoleController : CrudController<UserRoleDto, IUserRoleService>
{
public AdminUserRoleController(IUserRoleService service)
:base(service)