Roger Federer survived a second set scare to overcome Roberto Bautista Agut to reach the Halle Open semi-finals with a 6-3, 4-6, 6-4.