fix(backup): Add error handling and logging for backup and restore scripts
tar has exit code 2 for fatal errors, this was completely ignored. See also: https://www.man7.org/linux/man-pages/man1/tar.1.html#RETURN_VALUE
This commit is contained in:
		
							parent
							
								
									8a66d658eb
								
							
						
					
					
						commit
						4ca65a1a0f
					
				|  | @ -51,6 +51,10 @@ if [[ "$ret" -eq 0 ]]; then | ||||||
|   _log "INFO" "[backup] backup ${BACKUP_NUMBER} was completed without warnings" |   _log "INFO" "[backup] backup ${BACKUP_NUMBER} was completed without warnings" | ||||||
| elif [[ "$ret" -eq 1 ]]; then | elif [[ "$ret" -eq 1 ]]; then | ||||||
|   _log "INFO" "[backup] backup ${BACKUP_NUMBER} was completed with some warnings" |   _log "INFO" "[backup] backup ${BACKUP_NUMBER} was completed with some warnings" | ||||||
|  | else | ||||||
|  |   _log "ERROR" "[backup] backup ${BACKUP_NUMBER} failed with error code: $ret" | ||||||
|  |   _clean | ||||||
|  |   exit "$ret" | ||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
| mv "${BACKUP_TMP_DIR}/${BACKUP_NUMBER}.tar.zstd" "${BACKUP_DIR}/${BACKUP_NUMBER}.tar.zstd" | mv "${BACKUP_TMP_DIR}/${BACKUP_NUMBER}.tar.zstd" "${BACKUP_DIR}/${BACKUP_NUMBER}.tar.zstd" | ||||||
|  |  | ||||||
|  | @ -39,7 +39,17 @@ else | ||||||
|   exit 1 |   exit 1 | ||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
| tar $OPTS -C "${JENKINS_HOME}" -xf "${BACKUP_DIR}/${BACKUP_NUMBER}.${EXT}" | tar $OPTS -C "${JENKINS_HOME}" -xf "${BACKUP_DIR}/${BACKUP_NUMBER}.${EXT}" || ret=$? | ||||||
|  | 
 | ||||||
|  | if [[ "$ret" -eq 0 ]]; then | ||||||
|  |   _log "INFO" "[backup] backup ${BACKUP_NUMBER} was completed without warnings" | ||||||
|  | elif [[ "$ret" -eq 1 ]]; then | ||||||
|  |   _log "INFO" "[backup] backup ${BACKUP_NUMBER} was completed with some warnings" | ||||||
|  | else | ||||||
|  |   _log "ERROR" "[backup] backup ${BACKUP_NUMBER} failed with error code: $ret" | ||||||
|  |   exit "$ret" | ||||||
|  | fi | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| _log "INFO" "[restore] deleting lock file ${TRAP_FILE}" | _log "INFO" "[restore] deleting lock file ${TRAP_FILE}" | ||||||
| test -f "${TRAP_FILE}" && rm -f "${TRAP_FILE}" | test -f "${TRAP_FILE}" && rm -f "${TRAP_FILE}" | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue