public
Created

example data dump with retry on failure

  • Download Gist
backup.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#!/bin/bash
 
result=
while (( $result )) || [ -z "$result" ]; do
node dump_data_for_backup.js > backup.json
 
result=$?
# there is no way to distinguish node's (1) exit code on SIGINT (and SIGTERM)
# from a (1) exit code due to normal exit call in userland.
# if node preserved SIGINT/SIGTERM, then the shell would detect node's
# "abnormal exit" status, and the script would terminate right here.
# as it stands, it will be very difficult to terminate this script
# using Ctrl-C (SIGINT) or SIGTERM.
 
if (( $result != 0 )) ; then
echo -e "\nbackup failed ($result). retrying..."
fi
done
echo ">> backup-$(date +%Y%m%d).json"

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.