(Updated) Tableau Server housekeeping made easy – Windows Edition
*** This is an update of an older blog post that I wrote about creating a backup and housekeeping script for Tableau Server. If you require housekeeping scripts for Tableau Server v2018.2 or later, then read on. If you require scripts for Tableau Server 2018.1 or earlier, then go here instead: https://www.theinformationlab.co.uk/2014/07/25/tableau-server-housekeeping-made-easy/
*** If you are looking for a Linux version of these scripts then have a look here: https://www.theinformationlab.co.uk/2018/03/08/tableau-server-housekeeping-made-easy-linux-edition/
The best thing about administering Tableau Server is its self-sufficiency – processes that die are automatically respawned, the cluster controller ensures that all nodes in a server cluster are up and responding, and monitoring tools are already built-in via the administration dashboards. While this is all very handy, Tableau Server does require a bit of housekeeping to keep the server backed up and free of old log and temp files. Left on its own, a Tableau Server will quickly accumulate hundreds of MB in log files and leave your install at risk with no automatic backup process in place.
In this article I will give you a set of handy scripts and some instructions for scheduling these scripts that will take the guesswork out of your Server housekeeping tasks. However, before you start zipping and backing up everything, you need to give some thought to your backup and log rotation strategy. How many backup files should you keep? How long should we save our old log files for?
A note on backup and log rotation strategy
How often you backup, when you backup and how many backups you store will largely depend on your business needs, but I would recommend always storing at least two backup files, just in case one of the files becomes corrupted. You may want to store more backup files, but keep in mind that the backup file contains all the data on your server, so it could end up being quite large and you’ll need to make sure you have plenty of storage. After many years of deploying Tableau Servers, I can tell you that most server admins choose to backup their Tableau Server every night.
On the other hand, attitudes towards log files vary, but I would recommend you archive and clean up your logs once a week to avoid them growing too large. It is also useful to keep some recent logs archived in case you need to investigate an issue and analyse historical log files, or raise a ticket with Tableau Support. A good recommendation is to clean out these archived logs weekly, storing up to four weeks of zipped log files. Since these logs are primarily text files, they compress well and the resulting zip files are typically quite small.
Creating a backup script
So let’s say we want to put the above strategy into action. We can achieve this with one or more batch scripts, that will execute the following commands:
- Compress the current log files into a archive (zip file) and store these at a certain location
- Remove any archives older than 28 (or whatever you choose) days
- Backup the tableau server data and store this at a certain location
- Remove any backups older than 7 (or whatever) days
- Append the date to both the zipped logs and the backups
- Clean up the current, active logs once you’ve zipped them into an archive
For clarity, I have divided these tasks across three separate scripts, which means you can schedule them individually at different times according to your needs. These scripts are available to download from Github here:
How to use these scripts
Backup – tableau-server-backup-script.cmd
This script requires a few command line parameters in order to work. Starting with v 2018.2, we use TSM at the command line to perform administrative tasks. TSM requires authentication, and so we need to specify the username and password for the account that has permissions to run TSM. This user also needs to be a local administrator on the server, so that the log and backup files can be written successfully.
We also need to give our backup file a name, and specify the retention period in days for saving older backups. Any backup files older than this period will be removed when the script executes.
Lastly, we need to specify whether to allow overwrite or not. The TSM backup command is slightly different to the older tabadmin backup command in this respect, as it will not overwrite a backup file of the same name. Now, if we’re backing up daily and appending the date to the end of the filename, this shouldn’t be an issue, but if we’re backing up more often than that, or testing the script before deploying it, then we may need to overwrite a file of the same name. This script allows you to specify an overwrite parameter in this case. This which will check for any existing files (with the same name that we’re about to create) and remove them.
Here is how you specify the parameters at the command line:
tableau-server-backup-script.cmd -n ts_backup -u admin -p password -d 7 -o false where: -n,--name Name of the backup file -u,--username TSM administrator username -p,--password TSM administrator password -d,--days Delete backup files older than N days -o,--overwrite Overwrite any existing backup with the same name -h,--help Show help information
Log archival – tableau-server-log-archive-script.cmd
This script is going to archive your log files using the ‘tsm maintenance ziplogs’ command. It requires fewer parameters to run, but we still need to specify a TSM user and password, as well as the retention period (in days) for older log archives. This script will remove any log archives older than the retention period upon script execution. I would recommend you run this script once a week, and keep the last four (i.e. a month’s worth) of log archives. To do this, you would specify a retention period of 28 days.
This script will archive all available logs; it will overwrite any existing log archives with the same name in the same folder; and it will name the log archives in the format logs-yyyy-mm-dd.zip using the current date. Run this script with the following parameters:
tableau-server-log-archive-script.cmd -u admin -p password -d 28 where: -u,--username TSM administrator username -p,--password TSM administrator password -d,--days Delete log archives older than N days -h,--help Show help information
Cleanup – tableau-server-cleanup-script.cmd
This script cleans up all current log files (except the active log being written to) and removes any temp files created during the normal operating of the server, using the ‘tsm maintenance cleanup’ command. The script does not, however, cleanup the http-requests table in the PostgreSQL repository. While this is an option when running the cleanup command, it’s not recommended since this table is used in the built-in administrative views to analyse metrics like dashboard and view load times. It’s likely you’ll want to keep a history of this data, so this script does not attempt to clean up that table. Depending on the volume of activity on your Tableau Server, you may want to consider cleaning up this table on a less frequent basis, to reduce the bloat of the repository.
This script only requires the TSM credentials as command-line parameters:
tableau-server-cleanup-script.cmd -u admin -p password where: -u,--username TSM administrator username -p,--password TSM administrator password -h,--help Show this help