Tableau Server - download for local backup

WINNER of Tableau 2019 DataDev Virtual Hack-a-thon!

Maybe I'm paranoid, or just cautious.  In any case, I often want to download all the workbooks across all the sites I have access along with username, group and permission lists.  This would be a daunting task were it not for the Tableau REST API and Microsoft PowerShell.  As described in other earlier posts, I prefer to use PowerShell because it comes installed with Microsoft operating systems, and until recently, running Tableau desktop or server was predominately performed in a Microsoft Windows environment.  Also, as I work predominately with PC's supplied by my employers, those PC's will have PowerShell installed and may have issues with my installing programming languages like Perl, Python, etc.  I find that using tools that already exist is the quicker path for my productivity.

I've tested this script against both installed Tableau servers and Tableau Online -- both work, but there can be some hidden 'gotchas' lurking in your PC configuration.  The first has to do with TLS protocols -- all three protocols (TLS, TLS1.1, TLS1.2) need to be enabled in order for the PowerShell methods to work, AND, should you wish to run the script from a saved file, then the PC's ExecutionPolicy must be set to enable that to happen.  Both of these changes can be done via the PowerShell ISE, if it has been opened with the 'Run as Administrator' option (obviously, the person executing this option must have signed on to the PC with credentials that are part of the administrators security group).

Check the current execution policy and save to a variable:   $original_policy = Get-ExecutionPolicy
Set the policy for local scripts and signed internet scripts to run:   Set-ExecutionPolicy remotesigned

Should you want to revert to the saved policy after running scripts, simply manually run in the same script tab as the above were run: Set-ExecutionPolicy $original_policy

The next step is to set up a file location on your local drive to save the downloaded workbooks, csv and XML files along with a text file that saves the list of downloaded items and time taken.

Here's an overview of what the script does:

  1. Logs into the server and sets the api version appropriate to the server.  The REST api version used in the commands must align with the REST api resident on the server being called.  Since the api version can change with each upgrade, this script pulls the proper api version number from the server.
  2. Logs into the server with your credentials -- in the script these credentials are simply typed in as clear text, which when the script is saved on a network drive may violate corporate IT security policies.  There are ways to avoid saving/using credentials as readable text, but that is covered in another blog post (here).
  3. The 'sites' section is forbidden on Tableau Online, so that section is commented out, but provided for those that run their own Tableau server.  To enable that section of code, remove the less-than symbol on line 71 '<# get list of sites that login identity has access to' and the greater-than sign found on line 106 '#>'.
  4. Obtains list of workbooks that a person has permission to access (Tableau permissions are in place here).  A tabcmd approach is also noted, but not used as the REST api is able to grab the list directly to a variable used by PowerShell.
    1. obtain workbook and project. 
    2. Based on the project designation, create a sub-directory to save the files (project names with a / in them will be have their name split into different sub-directories as the / character is used to determine the creation of sub-directories and the save path for the project's files). Sub-projects will not appear as sub-directories of their parent project. 
    3. Permissions for the project's workbooks and datasources are saved to XML files.
    4. The workbook twb/twbx is retrieved and saved (script determines which is being downloaded and saves appropriately).  Permissions for the workbook is saved as an XML file as are a list of revisions.
    5. A similar process is followed to retreive datasource files and save them as tds/tdsx along with an XML of the permissions and revisions.
    6. Retrieve a list of subscriptions for the site, save as XML.
    7. Retrieve a list of projects for the site, save as XML.
    8. Retrieve a list of views save as XML (used to determine which sheets/dashboards were published as viewable).
    9. Get a list of Users, Groups and Groups' users, save as XML.
    10. Save a text file of downloaded items and time to execute the script.
Copyright© Brad Earle

Site Map | Printable View | © 2008 - 2022 KB Earle Associates LLC | |