import os import time 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 = '/databackup' today = time.strftime('%Y-%m-%d') today_dir = backup_path+today if not os.path.exists(today_dir): os.makedirs(today_dir) cmd = "pg_dump -h"+host+"-p"+db_port+"-U"+db_user+"-W -F c --no-owner --no-privileges -d "+db_name +"-f ./drought_"+today+".dump"