Added DB backup command
Added automated backup every 1 hour
This commit is contained in:
24
Services/HandleDbBackup.cs
Executable file
24
Services/HandleDbBackup.cs
Executable file
@@ -0,0 +1,24 @@
|
||||
using JsonFlatFileDataStore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using mstdnCats.Models;
|
||||
using Telegram.Bot;
|
||||
using Telegram.Bot.Types;
|
||||
using Telegram.Bot.Types.Enums;
|
||||
|
||||
namespace mstdnCats.Services;
|
||||
|
||||
public class HandleDbBackup
|
||||
{
|
||||
public static async Task HandleDbBackupAsync(TelegramBotClient _bot, ILogger<MastodonBot>? logger, string dbname, string adminId,IDocumentCollection<Post> _db)
|
||||
{
|
||||
logger?.LogInformation("Backup requested");
|
||||
|
||||
await using Stream stream = System.IO.File.OpenRead("./" + dbname);
|
||||
var message = await _bot.SendDocumentAsync(adminId, document: InputFile.FromStream(stream, dbname+".json"),
|
||||
caption: "Backup of " + dbname + "\nCreated at " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss" + "\nCurrent post count: " + _db.AsQueryable().Count()), parseMode: ParseMode.Html);
|
||||
|
||||
logger?.LogInformation("Backup sent");
|
||||
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user