Browse Source

Improved error handling and commented code

next
gau1991 10 years ago
parent
commit
448ef6789c
  1. 3
      bin/easyengine
  2. 26
      src/modules/site/migrate/ee_mod_migrate_data.sh
  3. 6
      src/modules/site/migrate/ee_mod_migrate_setup.sh

3
bin/easyengine

@ -770,7 +770,8 @@ elif [ "$EE_FIRST" = "site" ]; then
ee_mod_migrate_data ee_mod_migrate_data
# Create site # Create site
ee site create $EE_DOMAIN $EE_SITE_CREATE_OPTION $EE_SITE_CACHE_OPTION ee site create $EE_DOMAIN $EE_SITE_CREATE_OPTION $EE_SITE_CACHE_OPTION \
|| ee_lib_error "Unable to create site, exit status = " $?
# Setup migration # Setup migration
ee_mod_migrate_setup ee_mod_migrate_setup

26
src/modules/site/migrate/ee_mod_migrate_data.sh

@ -2,24 +2,36 @@
function ee_mod_migrate_data() function ee_mod_migrate_data()
{ {
# Remove if any previous directory and create /ee-backup
rm -rf /ee-backup/$EE_DOMAIN && mkdir -p /ee-backup/$EE_DOMAIN/ && cd /ee-backup/$EE_DOMAIN/ rm -rf /ee-backup/$EE_DOMAIN && mkdir -p /ee-backup/$EE_DOMAIN/ && cd /ee-backup/$EE_DOMAIN/
ee_lib_echo "Copying webroot from $EE_REMOTE_SERVER, please wait..."
# Copy webroot using ssh with the help of rsync
if [ "$EE_REMOTE_METHOD" == "ssh" ]; then if [ "$EE_REMOTE_METHOD" == "ssh" ]; then
# Lets FTP or rsync files # Lets FTP or rsync files
rsync -avz --progress $EE_REMOTE_USER@$EE_REMOTE_SERVER:$EE_REMOTE_PATH/ /ee-backup/$EE_DOMAIN/ rsync -avz --progress $EE_REMOTE_USER@$EE_REMOTE_SERVER:$EE_REMOTE_PATH/ /ee-backup/$EE_DOMAIN/ \
|| ee_lib_error "Unable to migrate data using rsync, exit status = " $?
if [ ! -f /ee-backup/$EE_DOMAIN/wp-config.php ] && [ "$EE_SITE_CREATE_OPTION" != "--html" ] && [ "$EE_SITE_CREATE_OPTION" != "--php" ] && [ "$EE_SITE_CREATE_OPTION" != "--mysql" ]; then if [ ! -f /ee-backup/$EE_DOMAIN/wp-config.php ] && [ "$EE_SITE_CREATE_OPTION" != "--html" ] && [ "$EE_SITE_CREATE_OPTION" != "--php" ] && [ "$EE_SITE_CREATE_OPTION" != "--mysql" ]; then
rsync -avz --progress $EE_REMOTE_USER@$EE_REMOTE_SERVER:$EE_REMOTE_PATH/../wp-config.php /ee-backup/$EE_DOMAIN/ rsync -avz --progress $EE_REMOTE_USER@$EE_REMOTE_SERVER:$EE_REMOTE_PATH/../wp-config.php /ee-backup/$EE_DOMAIN/ \
|| ee_lib_error "Unable to migrate data using rsync, exit status = " $?
fi fi
# Copy webroot using ftp with the help of lftp
elif [ "$EE_REMOTE_METHOD" == "ftp" ]; then elif [ "$EE_REMOTE_METHOD" == "ftp" ]; then
lftp -e "mirror --verbose -c $EE_REMOTE_PATH /ee-backup/$EE_DOMAIN; quit" ftp://$EE_REMOTE_USER@$EE_REMOTE_SERVER lftp -e "mirror --verbose -c $EE_REMOTE_PATH /ee-backup/$EE_DOMAIN; quit" ftp://$EE_REMOTE_USER@$EE_REMOTE_SERVER \
|| ee_lib_error "Unable to migrate data using ftp, exit status = " $?
if [ ! -f /ee-backup/$EE_DOMAIN/wp-config.php ] && [ "$EE_SITE_CREATE_OPTION" != "--html" ] && [ "$EE_SITE_CREATE_OPTION" != "--php" ] && [ "$EE_SITE_CREATE_OPTION" != "--mysql" ]; then if [ ! -f /ee-backup/$EE_DOMAIN/wp-config.php ] && [ "$EE_SITE_CREATE_OPTION" != "--html" ] && [ "$EE_SITE_CREATE_OPTION" != "--php" ] && [ "$EE_SITE_CREATE_OPTION" != "--mysql" ]; then
lftp -e "get -c $EE_REMOTE_PATH/../wp-config.php; quit" ftp://$EE_REMOTE_USER@$EE_REMOTE_SERVER lftp -e "get -c $EE_REMOTE_PATH/../wp-config.php; quit" ftp://$EE_REMOTE_USER@$EE_REMOTE_SERVER \
|| ee_lib_error "Unable to migrate data using ftp, exit status = " $?
fi fi
# Copy webroot using sftp with the help of lftp
elif [ "$EE_REMOTE_METHOD" == "sftp" ]; then elif [ "$EE_REMOTE_METHOD" == "sftp" ]; then
lftp -e "mirror --verbose -c $EE_REMOTE_PATH /ee-backup/$EE_DOMAIN ; quit"; sftp://$EE_REMOTE_USER@$EE_REMOTE_SERVER lftp -e "mirror --verbose -c $EE_REMOTE_PATH /ee-backup/$EE_DOMAIN ; quit"; sftp://$EE_REMOTE_USER@$EE_REMOTE_SERVER \
|| ee_lib_error "Unable to migrate data using sftp, exit status = " $?
if [ ! -f /ee-backup/$EE_DOMAIN/wp-config.php ] && [ "$EE_SITE_CREATE_OPTION" != "--html" ] && [ "$EE_SITE_CREATE_OPTION" != "--php" ] && [ ]"$EE_SITE_CREATE_OPTION" != "--mysql" ]; then if [ ! -f /ee-backup/$EE_DOMAIN/wp-config.php ] && [ "$EE_SITE_CREATE_OPTION" != "--html" ] && [ "$EE_SITE_CREATE_OPTION" != "--php" ] && [ ]"$EE_SITE_CREATE_OPTION" != "--mysql" ]; then
lftp -e "get -c $EE_REMOTE_PATH/../wp-config.php; quit" sftp://$EE_REMOTE_USER@$EE_REMOTE_SERVER lftp -e "get -c $EE_REMOTE_PATH/../wp-config.php; quit" sftp://$EE_REMOTE_USER@$EE_REMOTE_SERVER \
|| ee_lib_error "Unable to migrate data using lftp, exit status = " $?
fi fi
fi fi
} }

6
src/modules/site/migrate/ee_mod_migrate_setup.sh

@ -4,7 +4,8 @@ function ee_mod_migrate_setup()
{ {
# Copy data # Copy data
ee_lib_echo "Copying data from /ee-backup to webroot, please wait..." ee_lib_echo "Copying data from /ee-backup to webroot, please wait..."
cp -av /ee-backup/$EE_DOMAIN/* /var/www/$EE_DOMAIN/htdocs/ cp -a /ee-backup/$EE_DOMAIN/* /var/www/$EE_DOMAIN/htdocs/ \
|| ee_lib_error "Unable to copy backup data to site webroot, exit status = " $?
# Setup Database # Setup Database
if [ "$EE_SITE_CREATE_OPTION" = "--wp" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then if [ "$EE_SITE_CREATE_OPTION" = "--wp" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then
@ -21,7 +22,8 @@ function ee_mod_migrate_setup()
# Import database # Import database
ee_lib_echo "Importing database, please wait..." ee_lib_echo "Importing database, please wait..."
pv $EE_MYSQL_PATH | mysql $EE_DB_NAME pv $EE_MYSQL_PATH | mysql $EE_DB_NAME \
|| ee_lib_error "Unable to import database, exit status = " $?
fi fi
} }

Loading…
Cancel
Save