Create a gist now

Instantly share code, notes, and snippets.

example data dump with retry on failure
while true ; do
# 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 immediately after
# node returns
# as it stands, it will be very difficult to terminate this script
# using Ctrl-C (SIGINT).
if node dump-data.js > backup.json ; then
echo -e "\nbackup failed. retrying..."
echo "backup complete. $(date)"
echo "transferring to permanent storage..."
scp "backup.json" "$(date +%Y%m%d).json"
echo "transfer complete. $(date)"
process.stderr.write("simulating backup action (sleep for 20 seconds). "+
"Press Ctrl-C.. see what happens.");
setTimeout(function() {
process.stderr.write('ok - success!\n');
}, 20000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment