备份任务测试

This commit is contained in:
曹前明 2022-08-18 16:50:42 +08:00
parent c635b6b54a
commit ea510bee75
2 changed files with 12 additions and 12 deletions

View File

@ -19,7 +19,8 @@ def backup_database():
BACKUP_PATH + '/database', BACKUP_PATH + '/database',
name) name)
completed = subprocess.run(command, shell=True, capture_output=True, text=True) completed = subprocess.run(command, shell=True, capture_output=True, text=True)
return completed if completed.returncode != 0:
return completed.stderr
@shared_task @shared_task
@ -49,4 +50,5 @@ def reload_server_only():
def backup_media(): def backup_media():
command = 'bash {}/backup_media.sh'.format(SH_PATH) command = 'bash {}/backup_media.sh'.format(SH_PATH)
completed = subprocess.run(command, shell=True, capture_output=True, text=True) completed = subprocess.run(command, shell=True, capture_output=True, text=True)
return completed if completed.returncode != 0:
return completed.stderr

View File

@ -80,11 +80,10 @@ class BackupDatabase(APIView):
备份数据库到指定位置 备份数据库到指定位置
""" """
completed = backup_database() err_str = backup_database()
if completed.returncode == 0: if err_str:
return Response() raise APIException(err_str)
else: return Response()
raise APIException(completed.stdout)
class BackupMedia(APIView): class BackupMedia(APIView):
@ -96,11 +95,10 @@ class BackupMedia(APIView):
备份资源到指定位置 备份资源到指定位置
""" """
completed = backup_media() err_str = backup_database()
if completed.returncode == 0: if err_str:
return Response() raise APIException(err_str)
else: return Response()
raise APIException(completed.stdout)
class TestViewSet(CustomGenericViewSet): class TestViewSet(CustomGenericViewSet):