refactor(backups): wip postgres remote backups

This commit is contained in:
Mauricio Siu
2024-09-19 00:50:26 -06:00
parent 79f39db502
commit 54f855e738

View File

@@ -82,29 +82,38 @@ export const runRemotePostgresBackup = async (
postgres.serverId,
appName,
);
const pgDumpCommand = `pg_dump -Fc --no-acl --no-owner -h localhost -U ${databaseUser} --no-password '${database}' | gzip`;
const rcloneCommand = `rclone rcat --s3-provider AWS \
--s3-access-key-id ${accessKey} \
--s3-secret-access-key ${secretAccessKey} \
--s3-region ${region} \
--s3-endpoint ${endpoint} \
--buffer-size 16M ${rcloneDestination}`;
const pgDumpCommand = `docker exec ${containerId} sh -c "pg_dump -Fc --no-acl --no-owner -h localhost -U ${databaseUser} --no-password '${database}' | gzip"`;
// const rcloneConfig = `:s3,provider=Cloudflare,access_key_id=${accessKey},secret_access_key=${secretAccessKey},endpoint=${endpoint},acl=private,region=${region},bucket_name=${bucket},force_path_style=true`;
const rcloneFlags = [
// `--s3-provider=Cloudflare`,
`--s3-access-key-id=${accessKey}`,
`--s3-secret-access-key=${secretAccessKey}`,
`--s3-region=${region}`,
`--s3-endpoint=${endpoint}`, // Aquí puedes incluir 'https://'
"--s3-no-check-bucket",
"--s3-force-path-style",
];
const rcloneDestination = `:s3:${bucket}/jinza/${backupFileName}`;
const rcloneCommand = `rclone rcat ${rcloneFlags.join(" ")} "${rcloneDestination}"`;
// const pgDumpCommand = `pg_dump -Fc --no-acl --no-owner -h localhost -U ${databaseUser} --no-password '${database}' | gzip`;
// const rcloneCommand = `rclone rcat --s3-provider Other \
// --s3-access-key-id ${accessKey} \
// --s3-secret-access-key ${secretAccessKey} \
// --s3-region ${region} \
// --s3-endpoint ${endpoint} \
// --buffer-size 16M ${rcloneDestination}`;
// const rcloneCommand = `rclone rcat --buffer-size 16M ${rcloneDestination}`;
// const command = `
// // docker exec ${containerId} /bin/bash -c "${pgDumpCommand} | ${rcloneCommand}"
// `;
console.log(`${pgDumpCommand} | ${rcloneCommand}`);
await execAsyncRemote(
postgres.serverId,
`docker exec ${containerId} /bin/bash -c "${pgDumpCommand} | ${rcloneCommand}"`,
`${pgDumpCommand} | ${rcloneCommand}`,
);
// await execAsync(
// `docker exec ${containerId} sh -c "pg_dump -Fc --no-acl --no-owner -h localhost -U ${databaseUser} --no-password '${database}' | gzip > ${containerPath}"`,
// );
// await execAsync(`docker cp ${containerId}:${containerPath} ${hostPath}`);
// await uploadToS3(destination, bucketDestination, hostPath);
await sendDatabaseBackupNotifications({
applicationName: name,
projectName: project.name,