Spaces:
Running
Running
Update app.js
Browse files
app.js
CHANGED
|
@@ -85,19 +85,32 @@ app.delete("/delete", async (req, res) => {
|
|
| 85 |
|
| 86 |
app.get("/do-all", async (_, res) => {
|
| 87 |
const data = await getAllRedisData();
|
|
|
|
| 88 |
res.json(data);
|
| 89 |
});
|
| 90 |
|
| 91 |
-
app.get("/do-backup", async (
|
| 92 |
try {
|
|
|
|
| 93 |
const data = await getAllRedisData();
|
| 94 |
-
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
const fileId = await uploadToDrive(filename);
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
} catch (err) {
|
| 99 |
-
console.error(err);
|
| 100 |
-
res.status(500).send("Backup failed");
|
| 101 |
}
|
| 102 |
});
|
| 103 |
|
|
|
|
| 85 |
|
| 86 |
app.get("/do-all", async (_, res) => {
|
| 87 |
const data = await getAllRedisData();
|
| 88 |
+
console.error("all data: ", data);
|
| 89 |
res.json(data);
|
| 90 |
});
|
| 91 |
|
| 92 |
+
app.get("/do-backup", async (_req, res) => {
|
| 93 |
try {
|
| 94 |
+
// 1. Fetch all Redis data
|
| 95 |
const data = await getAllRedisData();
|
| 96 |
+
|
| 97 |
+
// 2. Write to a temp file (no EACCES)
|
| 98 |
+
const filename = `/tmp/redis_backup_${Date.now()}.json`;
|
| 99 |
+
fs.writeFileSync(filename, JSON.stringify(data, null, 2), { mode: 0o600 });
|
| 100 |
+
console.log(`Wrote backup file: ${filename}`);
|
| 101 |
+
|
| 102 |
+
// 3. Upload via your existing `uploadToDrive` (uses service account)
|
| 103 |
const fileId = await uploadToDrive(filename);
|
| 104 |
+
console.log(`Uploaded to Drive, fileId=${fileId}`);
|
| 105 |
+
|
| 106 |
+
// 4. Clean up temp file
|
| 107 |
+
fs.unlinkSync(filename);
|
| 108 |
+
|
| 109 |
+
// 5. Return the Drive file ID
|
| 110 |
+
res.send(`✅ Backup successful. File ID: ${fileId}`);
|
| 111 |
} catch (err) {
|
| 112 |
+
console.error("Backup error:", err);
|
| 113 |
+
res.status(500).send("❌ Backup failed");
|
| 114 |
}
|
| 115 |
});
|
| 116 |
|