import { execSync, type ExecSyncOptions } from "child_process"; import path from "path"; import s3DownloadFile from "../utils/s3-download"; const BACKUP_DIR = `/root/backups`; const DOCKER_DIR = "/var/lib/docker"; const R2_FILE_NAME = `${process.env.CODERANK_HOST_DOMAIN}.tar.xz`; const R2_FOLDER = `archives/servers`; const BACKUP_FILE_TAR = path.join(BACKUP_DIR, R2_FILE_NAME); const execOpts: ExecSyncOptions = { stdio: "inherit", }; await s3DownloadFile({ downloadPath: BACKUP_FILE_TAR, downloadFileName: R2_FILE_NAME, folder: R2_FOLDER, }); execSync(`[ -f "${R2_FILE_NAME}" ] && tar -xJvf "${R2_FILE_NAME}"`, { cwd: BACKUP_DIR, }); /** * # Restore Server Data */ const proxyBackupDir = `${BACKUP_DIR}/.backup/.coderank/proxy`; execSync( `[ -d "${proxyBackupDir}" ] && rsync -az --delete ${proxyBackupDir}/ /root/.coderank/proxy/ && rm -f /root/.coderank/proxy/servers-configs/*`, { ...execOpts, }, );