Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.06 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Grab the current date in YYYY-MM-DD format
  4. DATE=`date +%Y-%m-%d`
  5. # Grab the current datetime for timestamping the log entries
  6. TIMESTAMP=`date '+%Y-%m-%d %H:%M:%S'`
  7. # Do you want to copy your backups to another location after completion?
  8. copy_backup="yes"
  9. # If yes to above, where do you want to copy them?
  10. external_backup_path="s3://gale-tableau-backup/"
  11. # How many days do you want to keep old backup files for?
  12. backup_days="7"
  13. # What do you want to name your backup files? (will automatically append current date to this filename)
  14. backup_name="tableau-server-backup"
  15. # Do you want to copy your archived logs to another location after completion?
  16. copy_logs="yes"
  17. # Where do you want to save your archived logs?
  18. external_log_path="s3://gale-tableau-backup/"
  19. # How many days to you want to keep archived log files for?
  20. log_days="7"
  21. # What do you want to name your logs file? (will automatically append current date to this filename)
  22. log_name="logs"
  23.  
  24. # END OF VARIABLES SECTION
  25.  
  26. # LOAD ENVIRONMENT & USER INPUT
  27.  
  28. # Get tsm username from command line
  29. tsmuser=$1
  30. # Get tsm password from command line
  31. tsmpassword=$2
  32.  
  33. load_environment_file() {
  34. if [[ -f /etc/opt/tableau/tableau_server/environment.bash ]]; then
  35. source /etc/opt/tableau/tableau_server/environment.bash
  36. env_file_exists=1
  37. fi
  38. }
  39.  
  40. source /etc/profile.d/tableau_server.sh
  41.  
  42. # LOGS SECTION
  43.  
  44. # get the path to the log archive folder
  45. log_path=$(tsm configuration get -k basefilepath.log_archive -u $tsmuser -p $tsmpassword)
  46. echo $TIMESTAMP "The path for storing log archives is $log_path"
  47.  
  48. #go to logs path
  49. #cd $log_path
  50.  
  51. # count the number of log files eligible for deletion and output
  52. # echo $TIMESTAMP "Cleaning up old log files..."
  53. # lines=$(find $log_path -type f -name '*.zip' -mtime +$log_days | wc -l)
  54. # if [ $lines -eq 0 ]; then
  55. # echo $TIMESTAMP $lines found, skipping...
  56. #
  57. # else $TIMESTAMP $lines found, deleting...
  58. # #remove log archives older than the specified number of days
  59. # find $log_path -type f -name '*.zip' -mtime +$log_days -exec rm {} \;
  60. # echo $TIMESTAMP "Cleaning up completed."
  61. # fi
  62.  
  63. #archive current logs
  64. echo $TIMESTAMP "Archiving current logs..."
  65. tsm maintenance ziplogs -a -t -o -f logs-$DATE.zip -u $tsmuser -p $tsmpassword
  66. #copy logs to different location (optional)
  67. if [ "$copy_logs" == "yes" ];
  68. then
  69. echo $TIMESTAMP "Copying logs to remote share"
  70. aws s3 mv $log_path/$log_name-$DATE $external_log_path/logs/ --recursive
  71. fi
  72.  
  73. # END OF LOGS SECTION
  74.  
  75. # BACKUP SECTION
  76.  
  77. # get the path to the backups folder
  78. backup_path=$(tsm configuration get -k basefilepath.backuprestore -u $tsmuser -p $tsmpassword)
  79. echo $TIMESTAMP "The path for storing backups is $backup_path"
  80.  
  81. # go to the backup path
  82. # cd $backup_path
  83.  
  84. # count the number of log files eligible for deletion and output
  85. echo $TIMESTAMP "Cleaning up old backups..."
  86. lines=$(find $backup_path -type f -name '*.tsbak' -mtime +$backup_days | wc -l)
  87. if [ $lines -eq 0 ]; then
  88. echo $TIMESTAMP $lines old backups found, skipping...
  89. else $TIMESTAMP $lines old backups found, deleting...
  90. #remove backup files older than N days
  91. find $backup_path -type f -name '*.tsbak' -mtime +$backup_days -exec rm {} \;
  92. fi
  93.  
  94. #export current settings
  95. echo $TIMESTAMP "Exporting current settings..."
  96. tsm settings export -f $backup_path/settings.json -u $tsmuser -p $tsmpassword
  97. #create current backup
  98. echo $TIMESTAMP "Backup up Tableau Server data..."
  99. tsm maintenance backup -f $backup_name -d -u $tsmuser -p $tsmpassword
  100. #copy backups to different location (optional)
  101. if [ "$copy_backup" == "yes" ];
  102. then
  103. echo $TIMESTAMP "Copying backup and settings to remote share"
  104. aws s3 mv $backup_path/* $external_backup_path/ --recursive
  105. fi
  106.  
  107. # END OF BACKUP SECTION
  108.  
  109. # CLEANUP AND RESTART SECTION
  110.  
  111. # cleanup old logs and temp files
  112. echo $TIMESTAMP "Cleaning up Tableau Server..."
  113. tsm maintenance cleanup -a -u $tsmuser -p $tsmpassword
  114. # restart the server (optional, uncomment to run)
  115. #echo "Restarting Tableau Server"
  116. #tsm restart -u $tsmuser -p $tsmpassword
  117.  
  118. # END OF CLEANUP AND RESTART SECTION
  119.  
  120. # END OF SCRIPT
  121. echo $TIMESTAMP "Housekeeping completed"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement