feat: add timestamp function

This commit is contained in:
Alex Kelly 2023-01-16 19:35:40 -05:00
parent 4d544d0b3e
commit 3f678f78bc

View file

@ -15,7 +15,6 @@ LOG_KEEP=14
BACKUP_TAG=$(hostname -s) BACKUP_TAG=$(hostname -s)
STARTTIME=$(date "+%Y-%m-%d %H:%M:%S")
# How many backups to keep. # How many backups to keep.
RETENTION_DAYS=7 RETENTION_DAYS=7
@ -37,9 +36,13 @@ ECHO="/usr/bin/echo"
HOST=$(hostname -s) HOST=$(hostname -s)
# define functions # define functions
timestamp () {
date "+%Y-%m-%d %H:%M:%S"
}
run_backup () { run_backup () {
#Do the backup #Do the backup
${ECHO} "Starting backup on $HOST at $STARTTIME" ${ECHO} "Starting backup on $HOST at $(timestamp)"
${RESTIC} backup \ ${RESTIC} backup \
--tag "$BACKUP_TAG" \ --tag "$BACKUP_TAG" \
--exclude-file $BACKUP_EXCLUDES \ --exclude-file $BACKUP_EXCLUDES \
@ -96,13 +99,12 @@ notify () {
} }
# Do the actual work # Do the actual work
if run_backup && restic unlock && run_forget && cleanup; then if run_backup && ${RESTIC} unlock && run_forget && cleanup; then
# run_check # run_check
#cleanup #cleanup
ENDTIME=$(date "+%Y-%m-%d %H:%M:%S")
#status_total=$(( check_status + backup_status + forget_status )) #status_total=$(( check_status + backup_status + forget_status ))
#if (( status_total == 0 ));then #if (( status_total == 0 ));then
${ECHO} "Backup on $HOST completed successfully at $ENDTIME" | ${TEE} -a "$LOG_FILE" >(notify) ${ECHO} "Backup on $HOST completed successfully at $(timestamp)" | ${TEE} -a "$LOG_FILE" >(notify)
else else
${ECHO} "Backup on $HOST completed at $ENDTIME with issues (see $LOG_FILE)" | ${TEE} -a "$LOG_FILE" >(notify) ${ECHO} "Backup on $HOST completed at $(timestamp) with issues (see $LOG_FILE)" | ${TEE} -a "$LOG_FILE" >(notify)
fi fi