save database every 120 seconds or when entering background