feat: Add datetime on log
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
1f29978152
commit
67440a7f1f
29
watch
29
watch
|
@ -4,6 +4,11 @@
|
||||||
|
|
||||||
DEBUG=${DEBUG:-"Unknown Error"}
|
DEBUG=${DEBUG:-"Unknown Error"}
|
||||||
|
|
||||||
|
function log {
|
||||||
|
now=`date +"%Y-%m-%d %T"`
|
||||||
|
echo "[${now}] $1"
|
||||||
|
}
|
||||||
|
|
||||||
function usage {
|
function usage {
|
||||||
cat <<-EOF
|
cat <<-EOF
|
||||||
Usage: $PROGNAME [OPTIONS] <local-path> <remote-path>
|
Usage: $PROGNAME [OPTIONS] <local-path> <remote-path>
|
||||||
|
@ -16,7 +21,7 @@ EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
function error_exit {
|
function error_exit {
|
||||||
echo "${1:-"Unknown Error"}" 1>&2
|
log "${1:-"Unknown Error"}" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,49 +56,49 @@ function restore {
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "restoring $REMOTE => $LOCAL"
|
log "restoring $REMOTE => $LOCAL"
|
||||||
if ! $S3_PROG sync "$REMOTE/*" "$LOCAL"; then
|
if ! $S3_PROG sync "$REMOTE/*" "$LOCAL"; then
|
||||||
error_exit "restore failed"
|
error_exit "restore failed"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function backup {
|
function backup {
|
||||||
echo "backup $LOCAL => $REMOTE"
|
log "backup $LOCAL => $REMOTE"
|
||||||
if ! $S3_PROG sync "$LOCAL" "$REMOTE" $S3_SYNC_FLAGS; then
|
if ! $S3_PROG sync "$LOCAL" "$REMOTE" $S3_SYNC_FLAGS; then
|
||||||
echo "backup failed" 1>&2
|
log "backup failed" 1>&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function final_backup {
|
function final_backup {
|
||||||
echo "backup $LOCAL => $REMOTE"
|
log "backup $LOCAL => $REMOTE"
|
||||||
while ! $S3_PROG sync "$LOCAL" "$REMOTE" $S3_SYNC_FLAGS; do
|
while ! $S3_PROG sync "$LOCAL" "$REMOTE" $S3_SYNC_FLAGS; do
|
||||||
echo "backup failed, will retry" 1>&2
|
log "backup failed, will retry" 1>&2
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
function idle {
|
function idle {
|
||||||
echo "ready"
|
log "ready"
|
||||||
|
log "RESTORE_INTERVAL: ${RESTORE_INTERVAL}"
|
||||||
while true; do
|
while true; do
|
||||||
restore
|
restore
|
||||||
if [[ -v $RESTORE_INTERVAL ]]; then
|
if [[ -v RESTORE_INTERVAL ]]; then
|
||||||
backup
|
backup
|
||||||
timeout ${RESTORE_INTERVAL} inotifywait -m -e modify -e move -e create -e delete --timefmt '%Y-%m-%d %H:%M:%S' --format '%T %f' $LOCAL | while read date time file; do echo echo "The file '$file' appeared in directory '$path' via '$action'"; backup; done
|
timeout ${RESTORE_INTERVAL} inotifywait -m -e modify -e move -e create -e delete --timefmt '%Y-%m-%d %H:%M:%S' --format '%T %f' $LOCAL | while read date time file; do log "The file '$file' appeared in directory '$path' via '$action'"; backup; done
|
||||||
else
|
else
|
||||||
|
log "Without restore interval"
|
||||||
inotifywait -m -e modify -e move -e create -e delete --timefmt '%Y-%m-%d %H:%M:%S' --format '%T %f' $LOCAL |
|
inotifywait -m -e modify -e move -e create -e delete --timefmt '%Y-%m-%d %H:%M:%S' --format '%T %f' $LOCAL |
|
||||||
while read date time file
|
while read date time file
|
||||||
do
|
do
|
||||||
echo echo "The file '$file' appeared in directory '$path' via '$action'"
|
log "The file '$file' appeared in directory '$path' via '$action'"
|
||||||
backup
|
backup
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
restore
|
|
||||||
|
|
||||||
trap final_backup SIGHUP SIGINT SIGTERM
|
trap final_backup SIGHUP SIGINT SIGTERM
|
||||||
trap "backup; idle" USR1
|
trap "backup; idle" USR1
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue