/ Published in: Bash
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/bin/bash ############################################################################ # JasperReports Server Backup Script. # Written by Ernesto Ongaro in April 2011 ############################################################################ # JasperReports is free software: you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or (at your # option) any later version. # This script is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. ############################################################################ # Don't just run this script, make sure to edit the options below! ############################################################################ #set this if you're using JasperServer 3.7.1 or below IS_PRE_4=false #Friendly Name for Product PRODUCT_NAME="JR-4.0.1-Pro" BACKUP_DEST="/home/ernesto/Dropbox/Backups" FILE_NAME="`date +%Y%m%d%H%M`.zip" #Delete old backups after some time DELETE_OLD=true #How many days to keep DAYS=15 cd $(dirname $0) if [ "$IS_PRE_4" == "true" ]; then JS_EXPORT_ARGS="--everything --skip-access --output-zip" BUILDOMATIC="../buildomatic/default_master.properties" #Check if script is in right place if [ $(basename $(pwd)) != "scripts" ]; then echo "This script should live in the <js-install>/scripts folder for pre 4.0 installations. Exiting." exit 1 fi else #Then we're working with 4.0+ JS_EXPORT_ARGS="--everything --output-zip" BUILDOMATIC="default_master.properties" if [ $(basename $(pwd)) != "buildomatic" ]; then echo "This script should live in the <js-install>/buildomatic folder for 4.0+ installations. Exiting." exit 1 fi fi # Read information from js config file DB_USER=$(sed '/^\#/d' $BUILDOMATIC | grep 'dbUsername' | tail -n 1 | cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') DB_PASS=$(sed '/^\#/d' $BUILDOMATIC | grep 'dbPassword' | tail -n 1 | cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') DB_NAME=$(sed '/^\#/d' $BUILDOMATIC | grep 'js.dbName' | tail -n 1 | cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') mkdir -p "$BACKUP_DEST/$PRODUCT_NAME" #make sure backup destination exists logger "Starting $PRODUCT_NAME Repository Export" bash js-export.sh $JS_EXPORT_ARGS $BACKUP_DEST/$PRODUCT_NAME/repo-$FILE_NAME && logger "Repository backup written to repo-$FILE_NAME" logger "Starting $PRODUCT_NAME Database Backup" mysqldump -u "$DB_USER" "--password=""$DB_PASS" "$DB_NAME" | zip > $BACKUP_DEST/$PRODUCT_NAME/mysql-$FILE_NAME && logger "Database backup written to mysql-$FILE_NAME" if [ "$DELETE_OLD" == "true" ]; then find $BACKUP_DEST/$PRODUCT_NAME/mysql*.zip -mtime +$DAYS -exec rm {} \; find $BACKUP_DEST/$PRODUCT_NAME/repo*.zip -mtime +$DAYS -exec rm {} \; fi
URL: http://techpoet.blogspot.com