Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Grab the current date in YYYY-MM-DD format
- DATE=`date +%Y-%m-%d`
- # Grab the current datetime for timestamping the log entries
- TIMESTAMP=`date '+%Y-%m-%d %H:%M:%S'`
- # Do you want to copy your backups to another location after completion?
- copy_backup="yes"
- # If yes to above, where do you want to copy them?
- external_backup_path="s3://gale-tableau-backup/"
- # How many days do you want to keep old backup files for?
- backup_days="7"
- # What do you want to name your backup files? (will automatically append current date to this filename)
- backup_name="tableau-server-backup"
- # Do you want to copy your archived logs to another location after completion?
- copy_logs="yes"
- # Where do you want to save your archived logs?
- external_log_path="s3://gale-tableau-backup/"
- # How many days to you want to keep archived log files for?
- log_days="7"
- # What do you want to name your logs file? (will automatically append current date to this filename)
- log_name="logs"
- # END OF VARIABLES SECTION
- # LOAD ENVIRONMENT & USER INPUT
- # Get tsm username from command line
- tsmuser=$1
- # Get tsm password from command line
- tsmpassword=$2
- load_environment_file() {
- if [[ -f /etc/opt/tableau/tableau_server/environment.bash ]]; then
- source /etc/opt/tableau/tableau_server/environment.bash
- env_file_exists=1
- fi
- }
- source /etc/profile.d/tableau_server.sh
- # LOGS SECTION
- # get the path to the log archive folder
- log_path=$(tsm configuration get -k basefilepath.log_archive -u $tsmuser -p $tsmpassword)
- echo $TIMESTAMP "The path for storing log archives is $log_path"
- #go to logs path
- #cd $log_path
- # count the number of log files eligible for deletion and output
- # echo $TIMESTAMP "Cleaning up old log files..."
- # lines=$(find $log_path -type f -name '*.zip' -mtime +$log_days | wc -l)
- # if [ $lines -eq 0 ]; then
- # echo $TIMESTAMP $lines found, skipping...
- #
- # else $TIMESTAMP $lines found, deleting...
- # #remove log archives older than the specified number of days
- # find $log_path -type f -name '*.zip' -mtime +$log_days -exec rm {} \;
- # echo $TIMESTAMP "Cleaning up completed."
- # fi
- #archive current logs
- echo $TIMESTAMP "Archiving current logs..."
- tsm maintenance ziplogs -a -t -o -f logs-$DATE.zip -u $tsmuser -p $tsmpassword
- #copy logs to different location (optional)
- if [ "$copy_logs" == "yes" ];
- then
- echo $TIMESTAMP "Copying logs to remote share"
- aws s3 mv $log_path/$log_name-$DATE $external_log_path/logs/ --recursive
- fi
- # END OF LOGS SECTION
- # BACKUP SECTION
- # get the path to the backups folder
- backup_path=$(tsm configuration get -k basefilepath.backuprestore -u $tsmuser -p $tsmpassword)
- echo $TIMESTAMP "The path for storing backups is $backup_path"
- # go to the backup path
- # cd $backup_path
- # count the number of log files eligible for deletion and output
- echo $TIMESTAMP "Cleaning up old backups..."
- lines=$(find $backup_path -type f -name '*.tsbak' -mtime +$backup_days | wc -l)
- if [ $lines -eq 0 ]; then
- echo $TIMESTAMP $lines old backups found, skipping...
- else $TIMESTAMP $lines old backups found, deleting...
- #remove backup files older than N days
- find $backup_path -type f -name '*.tsbak' -mtime +$backup_days -exec rm {} \;
- fi
- #export current settings
- echo $TIMESTAMP "Exporting current settings..."
- tsm settings export -f $backup_path/settings.json -u $tsmuser -p $tsmpassword
- #create current backup
- echo $TIMESTAMP "Backup up Tableau Server data..."
- tsm maintenance backup -f $backup_name -d -u $tsmuser -p $tsmpassword
- #copy backups to different location (optional)
- if [ "$copy_backup" == "yes" ];
- then
- echo $TIMESTAMP "Copying backup and settings to remote share"
- aws s3 mv $backup_path/* $external_backup_path/ --recursive
- fi
- # END OF BACKUP SECTION
- # CLEANUP AND RESTART SECTION
- # cleanup old logs and temp files
- echo $TIMESTAMP "Cleaning up Tableau Server..."
- tsm maintenance cleanup -a -u $tsmuser -p $tsmpassword
- # restart the server (optional, uncomment to run)
- #echo "Restarting Tableau Server"
- #tsm restart -u $tsmuser -p $tsmpassword
- # END OF CLEANUP AND RESTART SECTION
- # END OF SCRIPT
- echo $TIMESTAMP "Housekeeping completed"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement