India set South Africa 308 to win, Sri Lanka survive Afghanistan scare