37 lines
1.2 KiB
Python
37 lines
1.2 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
|
|
|
|
@shared_task
|
|
def backup_database():
|
|
"""
|
|
备份数据库
|
|
"""
|
|
import datetime
|
|
name = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
|
|
command = '''pg_dump "user=postgres password=zcDsj2021 dbname=hberp" > /home/lighthouse/backup/database/hberp_{}.sql'''.format(name)
|
|
completed = subprocess.run(command, shell=True, capture_output=True, text=True)
|
|
return completed
|
|
|
|
@shared_task
|
|
def reload_server():
|
|
command = 'bash /home/lighthouse/hberp/hb_server/git.sh'
|
|
completed = subprocess.run(command, shell=True, capture_output=True, text=True)
|
|
return completed
|
|
|
|
@shared_task
|
|
def reload_server_only():
|
|
command = 'sudo service supervisor reload'
|
|
completed = subprocess.run(command, shell=True, capture_output=True, text=True)
|
|
return completed
|
|
|
|
@shared_task
|
|
def backup_media():
|
|
command = 'rsync -avu /home/lighthouse/hberp/hb_server/media/ /home/lighthouse/backup/media/'
|
|
completed = subprocess.run(command, shell=True, capture_output=True, text=True)
|
|
return completed
|
|
|
|
|