def backup_app(appid):
	# get app
	try:
		app = app_module.get_app(appid)
	except OSError:
		logging.info('Could not get app with id: {}'.format(appid))
		return
	
	# check this app is on this server
	if 'serverid' in os.environ and app['serverid'] != os.environ['serverid'] :
		logging.info('App not on this server: {}'.format(appid))
		return
	
	# get user
	try:
		user = app_module.get_sysuser(app['sysuserid'])
		app['sysuser'] = user
	except OSError:
		logging.info('Could not get user with id: {}'.format(app['sysuserid']))
		return
	
	# get databases
	try:
		databases = app_module.get_databases(appid)
		app['databases'] = databases
	except OSError:
		logging.info('Could not get databases for app {}'.format(appid))
		return
		
	_backup_app(app)
def backup_all():
	users = app_module.get_sysusers()
	apps = app_module.get_apps()
	databases = app_module.get_databases()
	
	for app in apps:
		if 'serverid' in os.environ and app['serverid'] == os.environ['serverid'] :
			# attach the user
			for user in users:
				if(user['id'] == app['sysuserid']):
					app['sysuser'] = user
			
			# attach the databases
			app['databases'] = []
			for database in databases:
				if(database['appid'] == app['id']):
					app['databases'].append(database)
			
			# do backupy things here
			_backup_app(app)