44 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Python
		
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Python
		
	
	
	
| from __future__ import absolute_import, unicode_literals
 | |
| from distutils import command
 | |
| from rest_framework.response import Response
 | |
| from celery import shared_task
 | |
| import os
 | |
| import subprocess
 | |
| from server.settings_pro import DATABASES, BACKUP_PATH, SH_PATH, SD_PWD
 | |
| 
 | |
| @shared_task
 | |
| def backup_database():
 | |
|     """
 | |
|     备份数据库
 | |
|     """
 | |
|     import datetime
 | |
|     name = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
 | |
|     command = 'echo "{}" | sudo -S pg_dump "user={} password={} dbname={}" > {}/hberp_{}.sql'.format(
 | |
|         SD_PWD,
 | |
|         DATABASES['default']['USER'],
 | |
|         DATABASES['default']['PASSWORD'],
 | |
|         DATABASES['default']['NAME'],
 | |
|         BACKUP_PATH + '/database',
 | |
|         name)
 | |
|     completed = subprocess.run(command, shell=True, capture_output=True, text=True)
 | |
|     return completed
 | |
| 
 | |
| @shared_task
 | |
| def reload_server():
 | |
|     command = 'bash {}/git.sh'.format(SH_PATH)
 | |
|     completed = subprocess.run(command, shell=True, capture_output=True, text=True)
 | |
|     return completed
 | |
| 
 | |
| @shared_task
 | |
| def reload_server_only():
 | |
|     command = 'echo "{}" | sudo -S service supervisor reload'.format(SD_PWD)
 | |
|     completed = subprocess.run(command, shell=True, capture_output=True, text=True)
 | |
|     return completed
 | |
| 
 | |
| @shared_task
 | |
| def backup_media():
 | |
|     command = 'bash {}/backup_media.sh'.format(SH_PATH)
 | |
|     completed = subprocess.run(command, shell=True, capture_output=True, text=True)
 | |
|     return completed
 | |
| 
 | |
|      |