feat: add timestamp function
This commit is contained in:
		
					parent
					
						
							
								4d544d0b3e
							
						
					
				
			
			
				commit
				
					
						3f678f78bc
					
				
			
		
					 1 changed files with 8 additions and 6 deletions
				
			
		
							
								
								
									
										14
									
								
								backup.sh
									
										
									
									
									
								
							
							
						
						
									
										14
									
								
								backup.sh
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -15,7 +15,6 @@ LOG_KEEP=14
 | 
			
		|||
 | 
			
		||||
BACKUP_TAG=$(hostname -s)
 | 
			
		||||
 | 
			
		||||
STARTTIME=$(date "+%Y-%m-%d %H:%M:%S")
 | 
			
		||||
 | 
			
		||||
# How many backups to keep.
 | 
			
		||||
RETENTION_DAYS=7
 | 
			
		||||
| 
						 | 
				
			
			@ -37,9 +36,13 @@ ECHO="/usr/bin/echo"
 | 
			
		|||
HOST=$(hostname -s)
 | 
			
		||||
 | 
			
		||||
# define functions
 | 
			
		||||
timestamp () {
 | 
			
		||||
   date "+%Y-%m-%d %H:%M:%S"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
run_backup () {
 | 
			
		||||
#Do the backup
 | 
			
		||||
	${ECHO} "Starting backup on $HOST at $STARTTIME"
 | 
			
		||||
    ${ECHO} "Starting backup on $HOST at $(timestamp)"
 | 
			
		||||
	${RESTIC} backup \
 | 
			
		||||
		--tag "$BACKUP_TAG" \
 | 
			
		||||
		--exclude-file $BACKUP_EXCLUDES \
 | 
			
		||||
| 
						 | 
				
			
			@ -96,13 +99,12 @@ notify () {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
# Do the actual work
 | 
			
		||||
if run_backup && restic unlock && run_forget && cleanup; then
 | 
			
		||||
if run_backup && ${RESTIC} unlock && run_forget && cleanup; then
 | 
			
		||||
# run_check
 | 
			
		||||
#cleanup
 | 
			
		||||
	ENDTIME=$(date "+%Y-%m-%d %H:%M:%S")
 | 
			
		||||
#status_total=$(( check_status + backup_status + forget_status ))
 | 
			
		||||
#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
 | 
			
		||||
	${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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue