Browse Source

site backup module added

bugfixes
harshadyeola 10 years ago
parent
commit
f189c8d175
  1. 33
      ee/cli/plugins/site_functions.py
  2. 51
      ee/core/fileutils.py
  3. 3
      ee/core/variables.py

33
ee/cli/plugins/site_functions.py

@ -8,6 +8,7 @@ from ee.core.mysql import EEMysql
from ee.core.shellexec import EEShellExec
from ee.core.variables import EEVariables
from ee.core.logging import Log
import glob
def SetupDomain(self, data):
@ -141,6 +142,7 @@ def SetupWordpress(self, data):
EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
EEShellExec.cmd_exec(self, "wp --allow-root core download")
if not (data['ee_db_name'] and data['ee_db_user'] and data['ee_db_pass']):
data = SetupDatabase(self, data)
if prompt_wpprefix == 'True' or prompt_wpprefix == 'true':
try:
@ -247,7 +249,9 @@ def SetupWordpressNetwork(self, data):
ee_site_webroot = data['webroot']
EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
EEShellExec.cmd_exec(self, 'wp --allow-root core multisite-convert'
'--title=')
'--title={0} {subdomains}'
.format(data['www_domain'], subdomains='--subdomains'
if not data['wpsubdir'] else ''))
def InstallWP_Plugin(self, plugin_name, data):
@ -271,3 +275,30 @@ def SetWebrootPermissions(self, webroot):
self.app.log.debug("Setting Up Permissions...")
EEFileUtils.chown(self, webroot, EEVariables.ee_php_user,
EEVariables.ee_php_user, recursive=True)
def siteBackup(self, data):
ee_site_webroot = data['webroot']
backup_path = ee_site_webroot + '/backup/{0}'.format(EEVariables.ee_date)
if not EEFileUtils.isexist(self, backup_path):
EEFileUtils.mkdir(self, backup_path)
Log.info(self, "Backup Location : {0}".format(backup_path))
EEFileUtils.copyfile(self, '/etc/nginx/sites-available/{0}.conf'
.format(data['ee_domain']), backup_path)
if data['currsitetype'] in ['html', 'php', 'mysql']:
Log.info(self, "Backup Webroot ...")
EEFileUtils.mvfile(self, ee_site_webroot + '/htdocs', backup_path)
configfiles = glob(ee_site_webroot + '/htdocs/*-config.php')
for file in configfiles:
if EEFileUtils.isexist(self, file):
ee_db_name = (EEFileUtils.grep(self, file, 'DB_NAME').split(',')[1]
.split(')')[0].strip())
Log.info(self, 'Backup Database, please wait')
EEShellExec.cmd_exec(self, "mysqldump {0} > {1}/{0}.sql"
.format(ee_db_name, backup_path),
"Failed: Backup Database")
# move wp-config.php/ee-config.php to backup
EEFileUtils.mvfile(self, file, backup_path)

51
ee/core/fileutils.py

@ -5,6 +5,7 @@ import sys
import glob
import shutil
import fileinput
from ee.core.logging import Log
class EEFileUtils():
@ -25,17 +26,20 @@ class EEFileUtils():
shutil.rmtree(file)
self.app.log.info("Done")
except shutil.Error as e:
self.app.log.error('Unable to Remove file {err}'
Log.error(self, 'Unable to Remove file {err}'
.format(err=str(e.reason)))
sys.exit(1)
def create_symlink(self, paths):
def create_symlink(self, paths, errormsg=''):
src = paths[0]
dst = paths[1]
try:
os.symlink(src, dst)
except Exception as e:
self.app.log.error("Unable to create symbolic link ...\n {0} {1}"
if errormsg:
Log.error(self, errormsg + 'n {0} {1}'.
format(e.errno, e.strerror))
Log.debug(self, "Unable to create symbolic link ...\n {0} {1}"
.format(e.errno, e.strerror))
sys.exit(1)
@ -43,7 +47,7 @@ class EEFileUtils():
try:
os.unlink(filepath)
except Exception as e:
self.app.log.error("Unable to reomove symbolic link ...\n {0} {1}"
Log.error(self, "Unable to reomove symbolic link ...\n {0} {1}"
.format(e.errno, e.strerror))
sys.exit(1)
@ -67,7 +71,7 @@ class EEFileUtils():
try:
shutil.move(src, dst)
except shutil.Error as e:
self.app.log.error('Unable to move file {err}'
Log.error(self, 'Unable to move file {err}'
.format(err=str(e.reason)))
sys.exit(1)
@ -75,7 +79,7 @@ class EEFileUtils():
try:
os.chdir(path)
except OSError as e:
self.app.log.error('Unable to Change Directory {err}'
Log.error(self, 'Unable to Change Directory {err}'
.format(err=e.strerror))
sys.exit(1)
@ -92,10 +96,10 @@ class EEFileUtils():
else:
shutil.chown(path, user=user, group=group)
except shutil.Error as e:
self.app.log.error("Unable to change owner : {0} ".format(e))
Log.error(self, "Unable to change owner : {0} ".format(e))
sys.exit(1)
except Exception as e:
self.app.log.error("Unable to change owner {0}".format(e))
Log.error(self, "Unable to change owner {0}".format(e))
sys.exit(1)
def chmod(self, path, perm, recursive=False):
@ -109,5 +113,34 @@ class EEFileUtils():
else:
os.chmod(path, perm)
except OSError as e:
self.log.error("Unable to change owner {0}".format(e.strerror))
Log.error(self, "Unable to change owner {0}".format(e.strerror))
sys.exit(1)
def mkdir(self, path):
try:
os.makedirs(path)
except OSError as e:
Log.error(self, "Unable to create directory {0}"
.format(e.strerror))
sys.exit(1)
def isexist(self, path):
try:
if os.path.exists(path):
return (True)
else:
return (False)
except OSError as e:
Log.error(self, "Unable to check path {0}"
.format(e.strerror))
sys.exit(1)
def grep(self, fnm, sstr):
try:
for line in open(fnm):
if sstr in line:
return line
except OSError as e:
Log.error(self, "Unable to Search string {0}"
.format(e.strerror))
sys.exit(1)

3
ee/core/variables.py

@ -5,6 +5,7 @@ import configparser
import os
import sys
import psutil
import datetime
class EEVariables():
@ -12,6 +13,8 @@ class EEVariables():
config = configparser.ConfigParser()
config.read(os.path.expanduser("~")+'/.gitconfig')
ee_date = datetime.datetime.now().strftime('%d%b%Y%H%M%S')
# EasyEngine core variables
ee_platform_distro = platform.linux_distribution()[0]
ee_platform_version = platform.linux_distribution()[1]

Loading…
Cancel
Save