Women's world number one VictoriAzarenka survived a scare to reach the last four of the Porsche Tennis Grand Prix in Stuttgart.