maybe something to backup mealie data idk
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

58 lines
1.6 KiB

import { envVars } from './config.js';
import { environmentVariableValidation } from './validation.js';
import { validationErrorCheck, logger } from './utils.js';
import { backupsToDelete, haveSomeCoffee } from './utils.js';
import {
getBackupsRequest,
exportDatabaseRequest,
getFileTokenRequest,
downloadBackupRequest,
backupDeleteRequest,
} from './apiHelper.js';
// check the env vars asap n complain if there's errors
const { error } = environmentVariableValidation({
...envVars,
});
validationErrorCheck(error);
/**
* get a list of backups
* find the time difference since the last backup then decide to do stuff
* if there's a big enough difference download the last backup on mealie to local fs
* if there's a max backup var remove all the old remote backup files it finds
* probably also export the current db
*/
const Main = async () => {
const response = await exportDatabaseRequest('mealieDb');
if (response) {
const backups = await getBackupsRequest();
const [lastBackup, ...rest] = backups ? backups?.imports : [];
const backupsToRemove = envVars.REMOTE_BACKUPS_MAX
? await backupsToDelete(rest.splice(envVars.REMOTE_BACKUPS_MAX))
: null;
const { fileToken } = await getFileTokenRequest(lastBackup?.name);
if (fileToken) await downloadBackupRequest(fileToken, lastBackup?.name);
if (backupsToRemove)
for (const file of backupsToRemove) {
await backupDeleteRequest(file);
await new Promise((resolve) => setTimeout(resolve, 300));
}
await haveSomeCoffee();
await Main();
}
if (!response) {
await haveSomeCoffee();
await Main();
}
};
Main();