Last active
December 16, 2015 16:18
-
-
Save mrsarm/5461771 to your computer and use it in GitHub Desktop.
Backup Liferay bundled with Tomcat: BBDD, data folder and complete instalation in a .tar.gz file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Liferay backup script. | |
# | |
# Author: Mariano Ruiz (2012-2013) | |
# http://www.mrdev.com.ar | |
# | |
DATE=`date "+%Y%m%d"` | |
LIFERAY_HOME="/java/liferay-portal-6.1.2-ce-ga3" | |
CATALINA_HOME="$LIFERAY_HOME/tomcat-7.0.40" | |
LIFERAY_BACKUP_DIR="/java" | |
BBDD="lportal_prod" | |
BBDD_ENGINE="mysql" | |
BBDD_BACKUP_DIR="$LIFERAY_HOME" | |
PREFIX_BACKUP_NAME="$BBDD" | |
BBDD_USER="lportal" | |
BBDD_PASS="admin" | |
HOST="localhost" | |
if [ "$BBDD_ENGINE" == "mysql" ] | |
then | |
CMD_DUMP="/usr/bin/mysqldump" | |
CMD_PARAMS="--single-transaction -u $BBDD_USER --password=$BBDD_PASS -a --host=$HOST $BBDD" | |
fi | |
if [ "$BBDD_ENGINE" == "postgres" ] | |
then | |
export PGPASSWORD="$BBDD_PASS" | |
CMD_DUMP="/usr/bin/pg_dump" | |
CMD_PARAMS="$BBDD -U $BBDD_USER --host=$HOST --no-password" | |
fi | |
# | |
# TO RESTORE THE INSTALLATION: | |
# tar -xzf PREFIX_BACKUP_NAME-DATE.sql.tar.gz | |
# | |
# TO RESTORE BACKUP BBDD IN MYSQL: | |
# mysql -u BBDD_USER BBDD -p < PREFIX_BACKUP_NAME-DATE.sql | |
# | |
# TO RESTORE BACKUP BBDD IN POSTGRES: | |
# psql -d BBDD -f PREFIX_BACKUP_NAME-DATE.sql > /dev/null | |
# | |
###################################################### | |
error () { | |
echo "Use: $0 { all | db } [-restart]" | |
exit 2 | |
} | |
if [ "$#" == 0 ] | |
then | |
error | |
fi | |
if [ "$1" != "all" -a "$1" != "db" ] | |
then | |
error | |
fi | |
if [ -n "$2" -a "$2" != "-restart" ] | |
then | |
error | |
fi | |
echo "Starting Liferay backup ... " | |
if [ "$2" == "-restart" ] | |
then | |
echo "Shutdown Liferay ... " | |
$CATALINA_HOME/bin/shutdown.sh | |
sleep 4 | |
fi | |
# Liferay DB | |
$CMD_DUMP $CMD_PARAMS > $BBDD_BACKUP_DIR/$PREFIX_BACKUP_NAME-$DATE.sql | |
chmod 700 $BBDD_BACKUP_DIR/$PREFIX_BACKUP_NAME-$DATE.sql | |
if [ "$1" == "all" ] | |
then | |
tar -cf $LIFERAY_BACKUP_DIR/$PREFIX_BACKUP_NAME-$DATE.tar \ | |
--exclude=$CATALINA_HOME/logs/* --exclude=$CATALINA_HOME/work/* \ | |
--exclude=$CATALINA_HOME/temp/* \ | |
$LIFERAY_HOME | |
gzip -9 $LIFERAY_BACKUP_DIR/$PREFIX_BACKUP_NAME-$DATE.tar -f | |
fi | |
if [ "$2" == "-restart" ] | |
then | |
echo "Starting Liferay ... " | |
$CATALINA_HOME/bin/startup.sh | |
fi | |
echo "Liferay backup done." | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hy,
thanks for the job,
when i lunch the backup...sh i got this message
" tar: Removing leading `/' from member names "
can you advice myself please ?
Dom.