mirror of
https://github.com/andwati/dokploy.git
synced 2026-10-18 03:02:56 +00:00
fix: run database dump once per backup and clean up partial uploads on failure
This commit is contained in:
@@ -37,11 +37,10 @@ export const runComposeBackup = async (
|
|||||||
try {
|
try {
|
||||||
const rcloneFlags = getS3Credentials(destination);
|
const rcloneFlags = getS3Credentials(destination);
|
||||||
const rcloneDestination = `:s3:${destination.bucket}/${bucketDestination}`;
|
const rcloneDestination = `:s3:${destination.bucket}/${bucketDestination}`;
|
||||||
const rcloneCommand = `rclone rcat ${rcloneFlags.join(" ")} "${rcloneDestination}"`;
|
|
||||||
|
|
||||||
const backupCommand = getBackupCommand(
|
const backupCommand = getBackupCommand(
|
||||||
backup,
|
backup,
|
||||||
rcloneCommand,
|
rcloneFlags,
|
||||||
|
rcloneDestination,
|
||||||
deployment.logPath,
|
deployment.logPath,
|
||||||
);
|
);
|
||||||
if (compose.serverId) {
|
if (compose.serverId) {
|
||||||
|
|||||||
@@ -36,12 +36,10 @@ export const runLibsqlBackup = async (
|
|||||||
try {
|
try {
|
||||||
const rcloneFlags = getS3Credentials(destination);
|
const rcloneFlags = getS3Credentials(destination);
|
||||||
const rcloneDestination = `:s3:${destination.bucket}/${bucketDestination}`;
|
const rcloneDestination = `:s3:${destination.bucket}/${bucketDestination}`;
|
||||||
|
|
||||||
const rcloneCommand = `rclone rcat ${rcloneFlags.join(" ")} "${rcloneDestination}"`;
|
|
||||||
|
|
||||||
const backupCommand = getBackupCommand(
|
const backupCommand = getBackupCommand(
|
||||||
backup,
|
backup,
|
||||||
rcloneCommand,
|
rcloneFlags,
|
||||||
|
rcloneDestination,
|
||||||
deployment.logPath,
|
deployment.logPath,
|
||||||
);
|
);
|
||||||
if (libsql.serverId) {
|
if (libsql.serverId) {
|
||||||
|
|||||||
@@ -35,11 +35,10 @@ export const runMariadbBackup = async (
|
|||||||
try {
|
try {
|
||||||
const rcloneFlags = getS3Credentials(destination);
|
const rcloneFlags = getS3Credentials(destination);
|
||||||
const rcloneDestination = `:s3:${destination.bucket}/${bucketDestination}`;
|
const rcloneDestination = `:s3:${destination.bucket}/${bucketDestination}`;
|
||||||
const rcloneCommand = `rclone rcat ${rcloneFlags.join(" ")} "${rcloneDestination}"`;
|
|
||||||
|
|
||||||
const backupCommand = getBackupCommand(
|
const backupCommand = getBackupCommand(
|
||||||
backup,
|
backup,
|
||||||
rcloneCommand,
|
rcloneFlags,
|
||||||
|
rcloneDestination,
|
||||||
deployment.logPath,
|
deployment.logPath,
|
||||||
);
|
);
|
||||||
if (mariadb.serverId) {
|
if (mariadb.serverId) {
|
||||||
|
|||||||
@@ -32,11 +32,10 @@ export const runMongoBackup = async (mongo: Mongo, backup: BackupSchedule) => {
|
|||||||
try {
|
try {
|
||||||
const rcloneFlags = getS3Credentials(destination);
|
const rcloneFlags = getS3Credentials(destination);
|
||||||
const rcloneDestination = `:s3:${destination.bucket}/${bucketDestination}`;
|
const rcloneDestination = `:s3:${destination.bucket}/${bucketDestination}`;
|
||||||
const rcloneCommand = `rclone rcat ${rcloneFlags.join(" ")} "${rcloneDestination}"`;
|
|
||||||
|
|
||||||
const backupCommand = getBackupCommand(
|
const backupCommand = getBackupCommand(
|
||||||
backup,
|
backup,
|
||||||
rcloneCommand,
|
rcloneFlags,
|
||||||
|
rcloneDestination,
|
||||||
deployment.logPath,
|
deployment.logPath,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -33,12 +33,10 @@ export const runMySqlBackup = async (mysql: MySql, backup: BackupSchedule) => {
|
|||||||
try {
|
try {
|
||||||
const rcloneFlags = getS3Credentials(destination);
|
const rcloneFlags = getS3Credentials(destination);
|
||||||
const rcloneDestination = `:s3:${destination.bucket}/${bucketDestination}`;
|
const rcloneDestination = `:s3:${destination.bucket}/${bucketDestination}`;
|
||||||
|
|
||||||
const rcloneCommand = `rclone rcat ${rcloneFlags.join(" ")} "${rcloneDestination}"`;
|
|
||||||
|
|
||||||
const backupCommand = getBackupCommand(
|
const backupCommand = getBackupCommand(
|
||||||
backup,
|
backup,
|
||||||
rcloneCommand,
|
rcloneFlags,
|
||||||
|
rcloneDestination,
|
||||||
deployment.logPath,
|
deployment.logPath,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -36,12 +36,10 @@ export const runPostgresBackup = async (
|
|||||||
try {
|
try {
|
||||||
const rcloneFlags = getS3Credentials(destination);
|
const rcloneFlags = getS3Credentials(destination);
|
||||||
const rcloneDestination = `:s3:${destination.bucket}/${bucketDestination}`;
|
const rcloneDestination = `:s3:${destination.bucket}/${bucketDestination}`;
|
||||||
|
|
||||||
const rcloneCommand = `rclone rcat ${rcloneFlags.join(" ")} "${rcloneDestination}"`;
|
|
||||||
|
|
||||||
const backupCommand = getBackupCommand(
|
const backupCommand = getBackupCommand(
|
||||||
backup,
|
backup,
|
||||||
rcloneCommand,
|
rcloneFlags,
|
||||||
|
rcloneDestination,
|
||||||
deployment.logPath,
|
deployment.logPath,
|
||||||
);
|
);
|
||||||
if (postgres.serverId) {
|
if (postgres.serverId) {
|
||||||
|
|||||||
@@ -259,11 +259,14 @@ export const generateBackupCommand = (backup: BackupSchedule) => {
|
|||||||
|
|
||||||
export const getBackupCommand = (
|
export const getBackupCommand = (
|
||||||
backup: BackupSchedule,
|
backup: BackupSchedule,
|
||||||
rcloneCommand: string,
|
rcloneFlags: string[],
|
||||||
|
rcloneDestination: string,
|
||||||
logPath: string,
|
logPath: string,
|
||||||
) => {
|
) => {
|
||||||
const containerSearch = getContainerSearchCommand(backup);
|
const containerSearch = getContainerSearchCommand(backup);
|
||||||
const backupCommand = generateBackupCommand(backup);
|
const backupCommand = generateBackupCommand(backup);
|
||||||
|
const rcloneCommand = `rclone rcat ${rcloneFlags.join(" ")} "${rcloneDestination}"`;
|
||||||
|
const rcloneDeleteCommand = `rclone deletefile ${rcloneFlags.join(" ")} "${rcloneDestination}"`;
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
{
|
{
|
||||||
@@ -279,33 +282,24 @@ export const getBackupCommand = (
|
|||||||
set -eo pipefail;
|
set -eo pipefail;
|
||||||
echo "[$(date)] Starting backup process..." >> ${logPath};
|
echo "[$(date)] Starting backup process..." >> ${logPath};
|
||||||
echo "[$(date)] Executing backup command..." >> ${logPath};
|
echo "[$(date)] Executing backup command..." >> ${logPath};
|
||||||
CONTAINER_ID=$(${containerSearch})
|
CONTAINER_ID=$(${containerSearch});
|
||||||
|
|
||||||
if [ -z "$CONTAINER_ID" ]; then
|
if [ -z "$CONTAINER_ID" ]; then
|
||||||
echo "[$(date)] ❌ Error: Container not found" >> ${logPath};
|
echo "[$(date)] ❌ Error: Container not found" >> ${logPath};
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi;
|
||||||
|
|
||||||
echo "[$(date)] Container Up: $CONTAINER_ID" >> ${logPath};
|
echo "[$(date)] Container Up: $CONTAINER_ID" >> ${logPath};
|
||||||
|
echo "[$(date)] Starting backup and upload to S3..." >> ${logPath};
|
||||||
|
|
||||||
# Run the backup command and capture the exit status
|
UPLOAD_OUTPUT=$({ ${backupCommand} | ${rcloneCommand}; } 2>&1 >/dev/null) || {
|
||||||
BACKUP_OUTPUT=$(${backupCommand} 2>&1 >/dev/null) || {
|
|
||||||
echo "[$(date)] ❌ Error: Backup failed" >> ${logPath};
|
echo "[$(date)] ❌ Error: Backup failed" >> ${logPath};
|
||||||
echo "Error: $BACKUP_OUTPUT" >> ${logPath};
|
|
||||||
exit 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
echo "[$(date)] ✅ backup completed successfully" >> ${logPath};
|
|
||||||
echo "[$(date)] Starting upload to S3..." >> ${logPath};
|
|
||||||
|
|
||||||
# Run the upload command and capture the exit status
|
|
||||||
UPLOAD_OUTPUT=$(${backupCommand} | ${rcloneCommand} 2>&1 >/dev/null) || {
|
|
||||||
echo "[$(date)] ❌ Error: Upload to S3 failed" >> ${logPath};
|
|
||||||
echo "Error: $UPLOAD_OUTPUT" >> ${logPath};
|
echo "Error: $UPLOAD_OUTPUT" >> ${logPath};
|
||||||
|
${rcloneDeleteCommand} >/dev/null 2>&1 || true;
|
||||||
exit 1;
|
exit 1;
|
||||||
}
|
};
|
||||||
|
|
||||||
echo "[$(date)] ✅ Upload to S3 completed successfully" >> ${logPath};
|
echo "[$(date)] ✅ Backup uploaded to S3 successfully" >> ${logPath};
|
||||||
echo "Backup done ✅" >> ${logPath};
|
echo "Backup done ✅" >> ${logPath};
|
||||||
`;
|
`;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user