Updates
This commit is contained in:
parent
97f5b6d7d9
commit
e090c57746
@ -1,6 +1,7 @@
|
|||||||
import datasquirel from "@moduletrace/datasquirel";
|
import datasquirel from "@moduletrace/datasquirel";
|
||||||
import { execSync, type ExecSyncOptions } from "child_process";
|
import { execSync, type ExecSyncOptions } from "child_process";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import s3DownloadFile from "../utils/s3-download";
|
||||||
|
|
||||||
const BACKUP_DIR = `/root/backups`;
|
const BACKUP_DIR = `/root/backups`;
|
||||||
const BACKUP_FILE_NAME = "backup.tar.xz";
|
const BACKUP_FILE_NAME = "backup.tar.xz";
|
||||||
@ -11,21 +12,16 @@ const DOCKER_VOLUMES_BACKUP_DIR = path.join(
|
|||||||
`docker`,
|
`docker`,
|
||||||
`volumes`,
|
`volumes`,
|
||||||
);
|
);
|
||||||
const BACKUP_FILE_TAR = path.join(BACKUP_DIR, BACKUP_FILE_NAME);
|
const R2_FILE_NAME = `${process.env.CODERANK_HOST_DOMAIN}.tar.xz`;
|
||||||
const RSYNC_IGNORE_FILE = `/root/.coderank/server/rsync-ignore.txt`;
|
const R2_FOLDER = `archives/servers`;
|
||||||
const DSQL_FOLDER = `/projects/coderank/archives/servers`;
|
const BACKUP_FILE_TAR = path.join(BACKUP_DIR, R2_FILE_NAME);
|
||||||
const DSQL_FILE_NAME = `${process.env.CODERANK_HOST_DOMAIN}.tar.xz`;
|
|
||||||
|
|
||||||
const execOpts: ExecSyncOptions = {
|
const execOpts: ExecSyncOptions = {
|
||||||
stdio: ["inherit", "inherit", "ignore"],
|
stdio: ["inherit", "inherit", "ignore"],
|
||||||
};
|
};
|
||||||
|
|
||||||
const dsqlFile = await datasquirel.api.media.get({
|
await s3DownloadFile({
|
||||||
// folder: DSQL_FOLDER,
|
downloadPath: BACKUP_FILE_TAR,
|
||||||
mediaName: DSQL_FILE_NAME,
|
downloadFileName: R2_FILE_NAME,
|
||||||
});
|
folder: R2_FOLDER,
|
||||||
|
|
||||||
datasquirel.utils.debugLog({
|
|
||||||
log: dsqlFile,
|
|
||||||
addTime: true,
|
|
||||||
});
|
});
|
||||||
|
|||||||
38
utils/s3-download.ts
Normal file
38
utils/s3-download.ts
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import { S3Client } from "bun";
|
||||||
|
import { createWriteStream } from "fs";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
|
type Params = {
|
||||||
|
downloadPath: string;
|
||||||
|
downloadFileName: string;
|
||||||
|
folder?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const client = new S3Client({
|
||||||
|
accessKeyId: process.env.CLOUDFLARE_R2_ACCESS_KEY_ID,
|
||||||
|
secretAccessKey: process.env.CLOUDFLARE_R2_SECRET,
|
||||||
|
bucket: "coderank",
|
||||||
|
endpoint: process.env.CLOUDFLARE_R2_ENDPOINT,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default async function s3DownloadFile({
|
||||||
|
downloadPath,
|
||||||
|
folder,
|
||||||
|
downloadFileName,
|
||||||
|
}: Params) {
|
||||||
|
let finalFileName = path.join(folder || "", downloadFileName);
|
||||||
|
|
||||||
|
const s3file = client.file(finalFileName);
|
||||||
|
|
||||||
|
const writable = createWriteStream(downloadPath);
|
||||||
|
const reader = s3file.stream().getReader();
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
const { done, value } = await reader.read();
|
||||||
|
if (done) break;
|
||||||
|
writable.write(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
writable.end();
|
||||||
|
console.log("Download complete!");
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user