Spain made futile attempts to regain its former colonies, such as the Battle of Callao (1866), and only in 1879 finally recognized Peruvian independence.