Guest User

Untitled

a guest
Sep 6th, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. #!sh
  2. # Filename: RestoreBackups.sh
  3. # Description: This Shell script helps you restore multiple Joomla! site backups created with Akeeba Backup
  4. # Author: Carlos Camara www.cmcamara.com
  5. # License: GPL v2.0 or later
  6.  
  7. #################
  8. # Configuration #
  9. #################
  10. #
  11. # Absolute path to unjpa file (included in jpa_utils package that you can download from JoomlaCode:
  12. UNJPA_PATH="$HOME/jpa_utils/"
  13. # Absolute path to the folder where all backup files are stored
  14. BACKUPS_FOLDER=$HOME/BackupsToRestore/
  15. # Absolute path to the folder in your webserver where the backups will be restored
  16. WEB_PATH=$HOME/public_html/RestoredBackups/
  17. # DB USer
  18. MYSQL_USER=""
  19. # DB Password
  20. MYSQL_PASS=""
  21. # Database to store restored sites tables
  22. MYSQL_DB="restored_sites"
  23.  
  24. ##We clean up older restored sites
  25. #rm -r $WEB_PATH
  26. #mysql -u $MYSQL_USER -p$MYSQL_PASS -e "DROP DATABASE $MYSQL_DB"
  27.  
  28. cd $BACKUPS_FOLDER
  29. OLDIFS=$IFS
  30. IFS=$'\n'
  31. SITE_COUNT=0
  32. for BACKUP in `ls`; do
  33. let "++SITE_COUNT"
  34. if [ ! "$BACKUP" == "restauradas" ]; then
  35. cd $BACKUPS_FOLDER
  36.  
  37. EXTENSION=${BACKUP##*.}
  38. BACKUPFOLDER=${BACKUP%.$EXTENSION}
  39. BACKUPFOLDER=${BACKUPFOLDER// /}
  40. mkdir -p $WEB_PATH/$BACKUPFOLDER
  41. cp ${BACKUP} $WEB:PATH/$BACKUPFOLDER
  42. cd $WEB_PATH/$BACKUPFOLDER
  43. if [ "$EXTENSION" == "jpa" ]; then
  44. cp $UNJPA_PATH/unjpa.php ./
  45. php unjpa.php "${BACKUP}"
  46. rm unjpa.php
  47. elif [ "$EXTENSION" == "zip" ]; then
  48. unzip "${BACKUP}"
  49. fi
  50. rm "${BACKUP}"
  51. #exit
  52. LOGPATH=$WEB_PATH/$BACKUPFOLDER/logs
  53. TMPPATH=$WEB_PATH/$BACKUPFOLDER/tmp
  54. DBPREFIX=$(sed -n 's/.*prefix *= *\([^ ]*.*\)/\1/p' < installation/sql/databases.ini)
  55. DBPREFIX=${DBPREFIX#\"}
  56. OLDDBPREFIX=${DBPREFIX%\"}
  57. $DBPREFIX="res$SITE_COUNT"
  58. sed -i s/#__/$DBPREFIX/g installation/sql/site.sql
  59.  
  60. echo "Starting DB restoration"
  61. #read startingdb
  62. mysql -u $MYSQL_USER -p$MYSQL_PASS -e "CREATE DATABASE IF NOT EXISTS $MYSQL_DB"
  63. mysql -u $MYSQL_USER -p$MYSQL_PASS $MYSQL_DB < installation/sql/joomla.sql
  64.  
  65. SQLFILE_COUNT=1
  66. SQLFILE="joomla.s0$SQLFILE_COUNT"
  67. SQLFILE_PATH="$WEB_PATH/$BACKUPFOLDER/installation/sql/"
  68. while [ -f $SQLFILE_PATH/$SQLFILE ]; do
  69. let "++SQLFILE_COUNT"
  70. echo "Starting DB restoration $SQLFILE"
  71. sed -i s/#__/$DBPREFIX/g $SQLFILE_PATH/$SQLFILE
  72. mysql -u $MYSQL_USER -p$MYSQL_PASS $MYSQL_DB < $SQLFILE_PATH/$SQLFILE
  73. if [ $SQLFILE_COUNT lt 10 ];then
  74. SQLFILE="joomla.s0$SQLFILE_COUNT"
  75. else
  76. SQLFILE="joomla.s$SQLFILE_COUNT"
  77. fi
  78. SQLFILE_PATH="$WEB_PATH/$BACKUPFOLDER/installation/sql/"
  79. done
  80.  
  81. echo "DB restoration finished\n"
  82.  
  83. sed -i "s/\(\$db *= *\).*/\1\'${MYSQL_DB}\';/" configuration.php
  84. sed -i "s/\(\$user *= *\).*/\1\'${MYSQL_USER}\';/" configuration.php
  85. sed -i "s/\(\$host *= *\).*/\1\'localhost\';/" configuration.php
  86. sed -i "s/\(\$password *= *\).*/\1\'$MYSQL_PASS\';/" configuration.php
  87. sed -i "s/\(\$prefix *= *\).*/\1\'${DBPREFIX}\';/" configuration.php
  88. sed -i "s/\(\$sef_rewrite *= *\).*/\1\'0\';/" configuration.php
  89. sed -i "s|\(\$log_path *= *\).*|\1\'${LOGPATH}\';|" configuration.php
  90. sed -i "s|\(\$tmp_path *= *\).*|\1\'$TMPPATH\';|" configuration.php
  91.  
  92. #After db restoration we remove the installation folder
  93. rm -r $WEB_PATH/$BACKUPFOLDER/installation
  94.  
  95. #We change file permissions to be sure everything works in php as a module configurations
  96. chmod 777 -R $WEB_PATH/$BACKUPFOLDER
  97.  
  98. #Move backup file after restoration
  99. mkdir -p $BACKUPS_FOLDER/restauradas/
  100. mv "$BACKUPS_FOLDER/$BACKUP" "$BACKUPS_FOLDER/restauradas/$BACKUP"
  101. fi
  102. done
  103. IFS=$OLDIFS
Add Comment
Please, Sign In to add comment