def backup(username:str, timeframe:str, backup_date:str):
"""
Route: /backup/username/timeframe/backup_date
This route returns the requested backup.
:param username the server username of the user needing their backup.
:param timeframe the timeframe of the requested backup. Can be either
"weekly", or "monthly".
:param backup_date the backup-date of the requested backup. Must be in the
form YYYY-MM-DD.
"""
if flask.request.method != "GET":
return flask.abort(400)
# make sure the arguments are valid
if not re.match(r"^[a-z]+$", username) or \
not re.match(r"^[0-9]{4}-[0-9]{2}-[0-9]{2}", backup_date) or \
timeframe not in ["weekly", "monthly"]:
app.logger.debug("backups(%s, %s, %s): invalid arguments"%(
username, timeframe, backup_date))
return flask.abort(400)
backups_base_dir = os.path.join(b.BACKUPS_DIR, username, timeframe)
return flask.send_from_directory(backups_base_dir, backup_date+".tgz")
评论列表
文章目录