mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
Merge pull request #90 from Portabase/fix/add-backup-cleanup
fix/add-backup-cleanup
This commit is contained in:
+2
-2
@@ -26,5 +26,5 @@ keywords:
|
||||
- web-ui
|
||||
- agent
|
||||
license: Apache-2.0
|
||||
version: 1.2.7
|
||||
date-released: "2026-02-16"
|
||||
version: 1.2.8-rc.1
|
||||
date-released: "2026-02-17"
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "portabase",
|
||||
"version": "1.2.7",
|
||||
"version": "1.2.8-rc.1",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev --turbopack -p 8887",
|
||||
|
||||
@@ -19,8 +19,6 @@ export const useUpdateCheck = () => {
|
||||
staleTime: 1000 * 60 * 60,
|
||||
});
|
||||
|
||||
console.log("newRelease", newRelease);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (!newRelease) return;
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import {db} from "@/db";
|
||||
import {and, eq, isNotNull, isNull} from "drizzle-orm";
|
||||
import * as drizzleDb from "@/db";
|
||||
import {withUpdatedAt} from "@/db/utils";
|
||||
|
||||
export const backupCleanTask = async () => {
|
||||
try {
|
||||
const backups = await db.query.backup.findMany({
|
||||
where: and(
|
||||
isNotNull(drizzleDb.schemas.backup.deletedAt),
|
||||
eq(drizzleDb.schemas.backup.status, "ongoing")
|
||||
)
|
||||
});
|
||||
|
||||
console.log(`Backups to clean: ${backups.length}`);
|
||||
|
||||
for (const backup of backups) {
|
||||
await db.update(drizzleDb.schemas.backup).set(withUpdatedAt({
|
||||
status: "failed",
|
||||
}))
|
||||
.where(eq(drizzleDb.schemas.backup.id, backup.id));
|
||||
}
|
||||
|
||||
} catch (e: any) {
|
||||
console.error("Backup cleanup failed:", e);
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
@@ -1,6 +1,7 @@
|
||||
import cron from "node-cron";
|
||||
import {retentionCleanTask} from "@/lib/tasks/database";
|
||||
import {env} from "@/env.mjs";
|
||||
import {backupCleanTask} from "@/lib/tasks/cleaning";
|
||||
|
||||
|
||||
export const retentionJob = cron.schedule(env.RETENTION_CRON, async () => {
|
||||
@@ -10,4 +11,13 @@ export const retentionJob = cron.schedule(env.RETENTION_CRON, async () => {
|
||||
} catch (err) {
|
||||
console.error(`[CRON] Error:`, err);
|
||||
}
|
||||
});
|
||||
|
||||
export const cleaningJob = cron.schedule("* * * * *", async () => {
|
||||
try {
|
||||
console.log("Cleaning Job : Starting task");
|
||||
await backupCleanTask();
|
||||
} catch (err) {
|
||||
console.error(`[CRON] Error:`, err);
|
||||
}
|
||||
});
|
||||
@@ -3,7 +3,6 @@ import {getMasterServerKeyContent} from "@/features/keys/keys.action";
|
||||
|
||||
export async function generateEdgeKey(serverUrl: string, agentId: string): Promise<string> {
|
||||
const masterKey = getMasterServerKeyContent()
|
||||
console.log("Master server key: ", masterKey)
|
||||
const edgeKeyData = {
|
||||
serverUrl,
|
||||
agentId,
|
||||
|
||||
+8
-1
@@ -2,7 +2,7 @@ import {env} from "@/env.mjs";
|
||||
import {db, makeMigration} from "@/db";
|
||||
import {eq} from "drizzle-orm";
|
||||
import * as drizzleDb from "@/db";
|
||||
import {retentionJob} from "@/lib/tasks";
|
||||
import {cleaningJob, retentionJob} from "@/lib/tasks";
|
||||
import {generateRSAKeys, getOrCreateMasterKey} from "@/utils/rsa-keys";
|
||||
import {StorageProviderKind} from "@/features/storages/types";
|
||||
|
||||
@@ -17,6 +17,7 @@ export async function init() {
|
||||
await createSettingsIfNotExist()
|
||||
console.log("====Initialization completed====");
|
||||
await setupCronJobs()
|
||||
await setupCleaningJobs()
|
||||
}
|
||||
|
||||
async function setupCronJobs() {
|
||||
@@ -25,6 +26,12 @@ async function setupCronJobs() {
|
||||
console.log("==== Cron job started ====");
|
||||
}
|
||||
|
||||
async function setupCleaningJobs() {
|
||||
console.log("==== Setting up Cleaning Jobs ====");
|
||||
cleaningJob.start();
|
||||
console.log("==== Cleaning job started ====");
|
||||
}
|
||||
|
||||
async function createSettingsIfNotExist() {
|
||||
await db.transaction(async (tx) => {
|
||||
const systemSettingsValues = {
|
||||
|
||||
Reference in New Issue
Block a user