22 lines
638 B
Python
22 lines
638 B
Python
import os
|
|
import time
|
|
|
|
from django.http import HttpResponse
|
|
from django.shortcuts import render
|
|
|
|
# Create your views here.
|
|
def database_backup(request):
|
|
host = '210.77.68.250'
|
|
db_user = 'drought'
|
|
db_pwd = 'g214G214'
|
|
db_port = '5432'
|
|
db_name = 'drought'
|
|
backup_path = '/datag214/data/drought/'
|
|
cmd_path = '/etc/postgresql/10/main/'
|
|
today = time.strftime('%Y-%m-%d')
|
|
cmd = cmd_path+"sudo pg_dump -h "+host+" -p "+db_port+" -U "+db_user+" -W "+db_pwd+ " -F c --no-owner --no-privileges -d "+db_name +" > " + backup_path +today+".dump"
|
|
print(str(cmd))
|
|
os.system(cmd)
|
|
return HttpResponse("OK")
|
|
|