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.shellexec import EEShellExec
from ee.core.variables import EEVariables from ee.core.variables import EEVariables
from ee.core.logging import Log from ee.core.logging import Log
import glob
def SetupDomain(self, data): def SetupDomain(self, data):
@ -141,6 +142,7 @@ def SetupWordpress(self, data):
EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
EEShellExec.cmd_exec(self, "wp --allow-root core download") 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) data = SetupDatabase(self, data)
if prompt_wpprefix == 'True' or prompt_wpprefix == 'true': if prompt_wpprefix == 'True' or prompt_wpprefix == 'true':
try: try:
@ -247,7 +249,9 @@ def SetupWordpressNetwork(self, data):
ee_site_webroot = data['webroot'] ee_site_webroot = data['webroot']
EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
EEShellExec.cmd_exec(self, 'wp --allow-root core multisite-convert' 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): def InstallWP_Plugin(self, plugin_name, data):
@ -271,3 +275,30 @@ def SetWebrootPermissions(self, webroot):
self.app.log.debug("Setting Up Permissions...") self.app.log.debug("Setting Up Permissions...")
EEFileUtils.chown(self, webroot, EEVariables.ee_php_user, EEFileUtils.chown(self, webroot, EEVariables.ee_php_user,
EEVariables.ee_php_user, recursive=True) 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 glob
import shutil import shutil
import fileinput import fileinput
from ee.core.logging import Log
class EEFileUtils(): class EEFileUtils():
@ -25,17 +26,20 @@ class EEFileUtils():
shutil.rmtree(file) shutil.rmtree(file)
self.app.log.info("Done") self.app.log.info("Done")
except shutil.Error as e: 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))) .format(err=str(e.reason)))
sys.exit(1) sys.exit(1)
def create_symlink(self, paths): def create_symlink(self, paths, errormsg=''):
src = paths[0] src = paths[0]
dst = paths[1] dst = paths[1]
try: try:
os.symlink(src, dst) os.symlink(src, dst)
except Exception as e: 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)) .format(e.errno, e.strerror))
sys.exit(1) sys.exit(1)
@ -43,7 +47,7 @@ class EEFileUtils():
try: try:
os.unlink(filepath) os.unlink(filepath)
except Exception as e: 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)) .format(e.errno, e.strerror))
sys.exit(1) sys.exit(1)
@ -67,7 +71,7 @@ class EEFileUtils():
try: try:
shutil.move(src, dst) shutil.move(src, dst)
except shutil.Error as e: 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))) .format(err=str(e.reason)))
sys.exit(1) sys.exit(1)
@ -75,7 +79,7 @@ class EEFileUtils():
try: try:
os.chdir(path) os.chdir(path)
except OSError as e: 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)) .format(err=e.strerror))
sys.exit(1) sys.exit(1)
@ -92,10 +96,10 @@ class EEFileUtils():
else: else:
shutil.chown(path, user=user, group=group) shutil.chown(path, user=user, group=group)
except shutil.Error as e: 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) sys.exit(1)
except Exception as e: 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) sys.exit(1)
def chmod(self, path, perm, recursive=False): def chmod(self, path, perm, recursive=False):
@ -109,5 +113,34 @@ class EEFileUtils():
else: else:
os.chmod(path, perm) os.chmod(path, perm)
except OSError as e: 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) sys.exit(1)

3
ee/core/variables.py

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

Loading…
Cancel
Save