One feature that enables some bacteria to survive in hostile or adverse conditions is the ability to form endospores. An endospore is a tough , non reproductive structure produced or formed by some bacteria from the Firmicute family.
The primary or main function of most endospores is to ensure the bacteria survives during periods of environmental stress. Endospores are resistant to starvation, chemical disinfectants, high or low temperatures, ultraviolet and gamma radiation. Endospores are commonly found in soil and water, where they may survive for lengthy periods of time.
Other bacteria when faced with decline or exhaustion of favored nutrients will become motile to seek out nutrients or they will produce new enzymes to enable them use alternative resources.