@@ -259,11 +259,14 @@ export const generateBackupCommand = (backup: BackupSchedule) => {
259259
260260export const getBackupCommand = (
261261 backup : BackupSchedule ,
262- rcloneCommand : string ,
262+ rcloneFlags : string [ ] ,
263+ rcloneDestination : string ,
263264 logPath : string ,
264265) => {
265266 const containerSearch = getContainerSearchCommand ( backup ) ;
266267 const backupCommand = generateBackupCommand ( backup ) ;
268+ const rcloneCommand = `rclone rcat ${ rcloneFlags . join ( " " ) } "${ rcloneDestination } "` ;
269+ const rcloneDeleteCommand = `rclone deletefile ${ rcloneFlags . join ( " " ) } "${ rcloneDestination } "` ;
267270
268271 logger . info (
269272 {
@@ -279,33 +282,24 @@ export const getBackupCommand = (
279282 set -eo pipefail;
280283 echo "[$(date)] Starting backup process..." >> ${ logPath } ;
281284 echo "[$(date)] Executing backup command..." >> ${ logPath } ;
282- CONTAINER_ID=$(${ containerSearch } )
285+ CONTAINER_ID=$(${ containerSearch } );
283286
284287 if [ -z "$CONTAINER_ID" ]; then
285288 echo "[$(date)] ❌ Error: Container not found" >> ${ logPath } ;
286289 exit 1;
287- fi
290+ fi;
288291
289292 echo "[$(date)] Container Up: $CONTAINER_ID" >> ${ logPath } ;
293+ echo "[$(date)] Starting backup and upload to S3..." >> ${ logPath } ;
290294
291- # Run the backup command and capture the exit status
292- BACKUP_OUTPUT=$(${ backupCommand } 2>&1 >/dev/null) || {
295+ UPLOAD_OUTPUT=$({ ${ backupCommand } | ${ rcloneCommand } ; } 2>&1 >/dev/null) || {
293296 echo "[$(date)] ❌ Error: Backup failed" >> ${ logPath } ;
294- echo "Error: $BACKUP_OUTPUT" >> ${ logPath } ;
295- exit 1;
296- }
297-
298- echo "[$(date)] ✅ backup completed successfully" >> ${ logPath } ;
299- echo "[$(date)] Starting upload to S3..." >> ${ logPath } ;
300-
301- # Run the upload command and capture the exit status
302- UPLOAD_OUTPUT=$(${ backupCommand } | ${ rcloneCommand } 2>&1 >/dev/null) || {
303- echo "[$(date)] ❌ Error: Upload to S3 failed" >> ${ logPath } ;
304297 echo "Error: $UPLOAD_OUTPUT" >> ${ logPath } ;
298+ ${ rcloneDeleteCommand } >/dev/null 2>&1 || true;
305299 exit 1;
306- }
300+ };
307301
308- echo "[$(date)] ✅ Upload to S3 completed successfully" >> ${ logPath } ;
302+ echo "[$(date)] ✅ Backup uploaded to S3 successfully" >> ${ logPath } ;
309303 echo "Backup done ✅" >> ${ logPath } ;
310304 ` ;
311305} ;
0 commit comments