mirror of
https://github.com/sp-tarkov/server.git
synced 2025-02-13 09:50:43 -05:00
Here's a jumping off point for the profile backup feature. Included some basic configuration options. Currently backup runs on server start-up (before the profiles are loaded into memory) and on a configurable interval. I think it still needs work. - [x] The folder name dates should be used to detect which old backups should be removed - [x] Not sure about the interval implementation... - [x] Could make the clean method thinner - [x] Remove VFS; I don't believe it's needed for copy operations - [x] Save a list of active mods used by the backed up profiles --------- Co-authored-by: Chomp <27521899+chompDev@users.noreply.github.com> Co-authored-by: Chomp <dev@dev.sp-tarkov.com>
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { OnLoad } from "@spt/di/OnLoad";
|
|
import { OnUpdate } from "@spt/di/OnUpdate";
|
|
import { ConfigTypes } from "@spt/models/enums/ConfigTypes";
|
|
import { ICoreConfig } from "@spt/models/spt/config/ICoreConfig";
|
|
import { ConfigServer } from "@spt/servers/ConfigServer";
|
|
import { SaveServer } from "@spt/servers/SaveServer";
|
|
import { BackupService } from "@spt/services/BackupService";
|
|
import { inject, injectable } from "tsyringe";
|
|
|
|
@injectable()
|
|
export class SaveCallbacks implements OnLoad, OnUpdate {
|
|
protected coreConfig: ICoreConfig;
|
|
|
|
constructor(
|
|
@inject("SaveServer") protected saveServer: SaveServer,
|
|
@inject("ConfigServer") protected configServer: ConfigServer,
|
|
@inject("BackupService") protected backupService: BackupService,
|
|
) {
|
|
this.coreConfig = this.configServer.getConfig(ConfigTypes.CORE);
|
|
}
|
|
|
|
public async onLoad(): Promise<void> {
|
|
this.backupService.init();
|
|
this.saveServer.load();
|
|
}
|
|
|
|
public getRoute(): string {
|
|
return "spt-save";
|
|
}
|
|
|
|
public async onUpdate(secondsSinceLastRun: number): Promise<boolean> {
|
|
// run every 15 seconds
|
|
if (secondsSinceLastRun > this.coreConfig.profileSaveIntervalSeconds) {
|
|
this.saveServer.save();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|