Browse Source

Update Back up directory structure

bugfixes
harshadyeola 10 years ago
parent
commit
b3030f53f9
  1. 36
      src/modules/site/ee_mod_site_backup.sh

36
src/modules/site/ee_mod_site_backup.sh

@ -5,33 +5,39 @@ function ee_mod_site_backup()
# Backup directory setup
local ee_webroot=$(grep root /etc/nginx/sites-available/$EE_DOMAIN | awk '{ print $2 }' | sed 's/;//g' | sed 's/\/htdocs//')
if [ ! -d $ee_webroot/backup ] || [ ! -d $ee_webroot/backup/htdocs/$EE_DATE ] || [ ! -d $ee_webroot/backup/nginx/$EE_DATE ] || [ ! -d $ee_webroot/backup/db/$EE_DATE ]; then
mkdir -p $ee_webroot/backup/{htdocs/$EE_DATE,nginx/$EE_DATE,db/$EE_DATE} || ee_lib_error "Unable to create $ee_webroot/backup directory, exit status =" $?
if [ ! -d $ee_webroot/backup/$EE_DATE ]; then
mkdir -p $ee_webroot/backup/$EE_DATE || ee_lib_error "Fail to create backup directory, exit status =" $?
fi
ee_lib_echo "Backup location: $ee_webroot/backup/$EE_DATE"
ee_lib_echo "Backup NGINX configuration, please wait..."
# Backup $EE_DOMAIN NGINX configuration
cp /etc/nginx/sites-available/$EE_DOMAIN $ee_webroot/backup/$EE_DATE/ \
|| ee_lib_error "Failed: Backup NGINX configuration, exit status =" $?
# Move htdocs
if [ "$EE_SITE_CURRENT_OPTION" = "HTML" ] || [ "$EE_SITE_CURRENT_OPTION" = "MYSQL" ] || [ "$EE_SITE_CURRENT_OPTION" = "PHP" ]; then
ee_lib_echo "Backup webroot at $ee_webroot/backup/htdocs/$EE_DATE/, please wait..."
mv $ee_webroot/htdocs $ee_webroot/backup/htdocs/$EE_DATE/ || ee_lib_error "Unable to move $ee_webroot/htdocs to backup, exit status =" $?
mkdir -p $ee_webroot/htdocs
if [ "$EE_SITE_CURRENT_OPTION" = "HTML" ] || [ "$EE_SITE_CURRENT_OPTION" = "PHP" ] || [ "$EE_SITE_CURRENT_OPTION" = "MYSQL" ]; then
ee_lib_echo "Backup webroot, please wait..."
mv $ee_webroot/htdocs $ee_webroot/backup/$EE_DATE/ \
|| ee_lib_error "Failed: Backup webroot, exit status =" $?
ee_lib_echo "Setting up webroot, please wait..."
mkdir -p $ee_webroot/htdocs || ee_lib_error "Failed: Setting up webroot, exit status =" $?
fi
ee_lib_echo "Backup NGINX configuration at $ee_webroot/backup/nginx/$EE_DATE/, please wait..."
# Backup $EE_DOMAIN NGINX configuration
cp /etc/nginx/sites-available/$EE_DOMAIN $ee_webroot/backup/nginx/$EE_DATE/ &>> $EE_COMMAND_LOG
# Database backup
if [ -f $(grep root /etc/nginx/sites-available/$EE_DOMAIN | awk '{ print $2 }' | sed 's/;//g' | sed 's/htdocs/*-config.php/') ]; then
local ee_db_name=$(grep DB_NAME $(grep root /etc/nginx/sites-available/$EE_DOMAIN | awk '{ print $2 }' | sed 's/;//g' | sed 's/htdocs/*-config.php/' 2> /dev/null) | cut -d"'" -f4)
ee_lib_echo "Backup Database $ee_db_name at $ee_webroot/backup/db/$EE_DATE/, please wait..."
mysqldump $ee_db_name > $ee_webroot/backup/db/$EE_DATE/${ee_db_name}.sql \
|| ee_lib_error "Unable to dump ${ee_db_name}, exit status =" $?
ee_lib_echo "Backup Database, please wait..."
mysqldump $ee_db_name > $ee_webroot/backup/$EE_DATE/${ee_db_name}.sql \
|| ee_lib_error "Failed: Backup Database, exit status =" $?
# Move ee-config.php and copy wp-config.php to backup
if [ -f $ee_webroot/ee-config.php ]; then
mv $ee_webroot/ee-config.php $ee_webroot/backup/htdocs/$EE_DATE/ || ee_lib_error "Unable to move $ee_webroot/ee-config.php to backup, exit status =" $?
mv $ee_webroot/ee-config.php $ee_webroot/backup/$EE_DATE/ \
|| ee_lib_error "Failed: Backup ee-config.php, exit status =" $?
else
cp $ee_webroot/wp-config.php $ee_webroot/backup/htdocs/$EE_DATE/ || ee_lib_error "Unable to move $ee_webroot/wp-config.php to backup, exit status =" $?
cp $ee_webroot/wp-config.php $ee_webroot/backup/$EE_DATE/ \
|| ee_lib_error "Failed: Backup wp-config.php, exit status =" $?
fi
fi
}

Loading…
Cancel
Save