From 61c455dbae268c0f7cb40fc17697eb98b441b07d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Guerraz?= Date: Tue, 28 May 2024 12:05:44 +0100 Subject: [PATCH] Improve error handling (#6) * Handle errors happening in pipelines --- stream_backup.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/stream_backup.sh b/stream_backup.sh index a9dd7d2..546e8e0 100755 --- a/stream_backup.sh +++ b/stream_backup.sh @@ -131,7 +131,7 @@ else fi mkdir ${SUBV}/.stream_backup_${EPOCH}/ || true -btrfs subvolume snapshot -r ${SUBV} ${NEW_SNAPSHOT} +btrfs subvolume snapshot -r ${SUBV} ${NEW_SNAPSHOT} || exit 1 trap cleanup ERR trap cleanup INT @@ -140,7 +140,11 @@ eval ${BTRFS_COMMAND} \ | lz4 \ | mbuffer -m ${CHUNK_SIZE} -q \ | split -b ${CHUNK_SIZE} --suffix-length 4 --filter \ - "age -R ${RECIPIENTS_FILE} | aws s3 cp - s3://${BUCKET}/${PREFIX}/${EPOCH}/${SEQ_SALTED}/\$FILE --storage-class ${SCLASS}" + "age -R ${RECIPIENTS_FILE} | aws s3 cp - s3://${BUCKET}/${PREFIX}/${EPOCH}/${SEQ_SALTED}/\$FILE --storage-class ${SCLASS}; exit \${PIPESTATUS}" + +if [ "${PIPESTATUS}" != "0" ]; then + cleanup +fi # We only write the subvolume information to S3 at the end, as a marker of completion of the backup # having the subvolume information might help debuging tricky situations @@ -148,6 +152,10 @@ btrfs subvolume show ${NEW_SNAPSHOT} \ | age -R ${RECIPIENTS_FILE} \ | aws s3 cp - s3://${BUCKET}/${PREFIX}/${EPOCH}/${SEQ_SALTED}/snapshot_info.dat +if [ "${PIPESTATUS}" != "0" ]; then + cleanup +fi + # We delete the snapshot from which we made an incremental backup: # * If the user asked for it # * If there is a previous snapshot in the first place