interval protection: exit with error status code (3)
In many use cases I wrap the ./backup-everything.sh script inside a parent Bash script,
to then call the 'rotate.sh' just after that.
The problem is, when the parent script is called twice "recently" (e.g. due to time change),
the 'backup-everything.sh' was successfully detecting this duplicated execution,
but was exiting with a success status code (0), so, the parent script was considering
the backup as concluded, so, the parent script was proceeding with the usual 'rotate.sh',
causing the loss of the oldest rotated data, and causing a duplicated last rotated data.
So, if the backup script cannot run because it was already running recently,
then it's safer to just quit with an error code (3), so any further logic can stop too.
So, now you can do this:
if /root/micro-backup-script/backup-everything.sh; then
# Do something only if backup was really executed.
fiOr, also just this:
set -e /root/micro-backup-script/backup-everything.sh # Do something only if backup was really executed.