Posted By

ernestoongaro on 04/19/11


Tagged


Versions (?)

JasperServer Backup Script


 / Published in: Bash
 

URL: http://techpoet.blogspot.com

  1. #!/bin/bash
  2. ############################################################################
  3. # JasperReports Server Backup Script.
  4. # Written by Ernesto Ongaro in April 2011
  5. ############################################################################
  6. # JasperReports is free software: you can redistribute it and/or modify it
  7. # under the terms of the GNU Lesser General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or (at your
  9. # option) any later version.
  10.  
  11. # This script is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Lesser General Public License for more details.
  15. ############################################################################
  16. # Don't just run this script, make sure to edit the options below!
  17. ############################################################################
  18. #set this if you're using JasperServer 3.7.1 or below
  19. IS_PRE_4=false
  20. #Friendly Name for Product
  21. PRODUCT_NAME="JR-4.0.1-Pro"
  22. BACKUP_DEST="/home/ernesto/Dropbox/Backups"
  23. FILE_NAME="`date +%Y%m%d%H%M`.zip"
  24. #Delete old backups after some time
  25. DELETE_OLD=true
  26. #How many days to keep
  27. DAYS=15
  28.  
  29. cd $(dirname $0)
  30. if [ "$IS_PRE_4" == "true" ]; then
  31. JS_EXPORT_ARGS="--everything --skip-access --output-zip"
  32. BUILDOMATIC="../buildomatic/default_master.properties"
  33. #Check if script is in right place
  34. if [ $(basename $(pwd)) != "scripts" ]; then
  35. echo "This script should live in the <js-install>/scripts folder for pre 4.0 installations. Exiting."
  36. exit 1
  37. fi
  38. else
  39. #Then we're working with 4.0+
  40. JS_EXPORT_ARGS="--everything --output-zip"
  41. BUILDOMATIC="default_master.properties"
  42. if [ $(basename $(pwd)) != "buildomatic" ]; then
  43. echo "This script should live in the <js-install>/buildomatic folder for 4.0+ installations. Exiting."
  44. exit 1
  45. fi
  46. fi
  47.  
  48. # Read information from js config file
  49. DB_USER=$(sed '/^\#/d' $BUILDOMATIC | grep 'dbUsername' | tail -n 1 | cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
  50. DB_PASS=$(sed '/^\#/d' $BUILDOMATIC | grep 'dbPassword' | tail -n 1 | cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
  51. DB_NAME=$(sed '/^\#/d' $BUILDOMATIC | grep 'js.dbName' | tail -n 1 | cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
  52.  
  53. mkdir -p "$BACKUP_DEST/$PRODUCT_NAME" #make sure backup destination exists
  54. logger "Starting $PRODUCT_NAME Repository Export"
  55. bash js-export.sh $JS_EXPORT_ARGS $BACKUP_DEST/$PRODUCT_NAME/repo-$FILE_NAME && logger "Repository backup written to repo-$FILE_NAME"
  56.  
  57. logger "Starting $PRODUCT_NAME Database Backup"
  58. 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"
  59.  
  60. if [ "$DELETE_OLD" == "true" ]; then
  61. find $BACKUP_DEST/$PRODUCT_NAME/mysql*.zip -mtime +$DAYS -exec rm {} \;
  62. find $BACKUP_DEST/$PRODUCT_NAME/repo*.zip -mtime +$DAYS -exec rm {} \;
  63. fi

Report this snippet  

You need to login to post a comment.