[Borgbackup] Obtaining borg exit codes when using `timeout`

Bruce Givens givens at cipsoft.com
Thu Sep 5 04:57:12 EDT 2019


Hi Gordon,

looks to me like you'll be capturing the exit status of tee in backup_exit.
I'd suggest looking into the bash variable PIPESTATUS.

Regards,
Bruce


On 9/5/19 9:20 AM, Gordon Marinovich wrote:
> Hi all
> 
> I've been using Borg for some months now and it's working well.  
> Recently I've tried to smarten up the daily backup checks by using email 
> subject lines based on the exit code of the borg backup.
> So I've written a simple script in bash which is run from cron.  Here is 
> an extract of it:
> |
> 
> |
> |
> timeout --preserve-status 12h borg create \
> ||
> --stats \
> ||
> --show-rc \
> ||
> ||
> $REPO::fs1-{now:%Y-%m-%d} /mnt/nfs-fs1-data/ 2>&1 \
> ||
> | tee -a $LOGFILE $MONTHLY_REPORT \
> ||
> |
> |
> ||
> backup_exit=$?
> ||
> ||
> echo "BORG backup finished with exit code: $backup_exit.">> $LOGFILE
> |
> |
> 
> |timeout is used so that the job doesn't run into business hours, but 
> the problem I'm having is that when timeout invokes and kills the 
> backup, the exit code captured by *$backup_exit* is always 0.
> 
> But if I browse the $LOGFILE, the output there shows the following:
> Received SIGTERM
> terminating with error status, rc 2
> BORG backup finished at Thu 2019-Sep-05 06:00 with exit code: 0.
> 
> Initially I didn't have the timeout option --preserve-status, which I 
> thought would solve my problem, and allow the capture of borg's actual 
> exit code, which should be "2", but alas not, it's still always zero.
> 
> Has anyone used timeout --preserve status with borg, and could you 
> obtain the exit code similar to what I am trying to do?  If so, I would 
> be grateful for some direction on how to solve this.
> 
> Regards
> 
> --
> Gordon
> 
> 
> _______________________________________________
> Borgbackup mailing list
> Borgbackup at python.org
> https://mail.python.org/mailman/listinfo/borgbackup
> 



More information about the Borgbackup mailing list