Skip to content

Instantly share code, notes, and snippets.

@cmtoomey
Last active August 19, 2016 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmtoomey/14455fb423102c90e689e20598f5d5d3 to your computer and use it in GitHub Desktop.
Save cmtoomey/14455fb423102c90e689e20598f5d5d3 to your computer and use it in GitHub Desktop.
Tableau Backup to S3
#This was written Python 2.7, not tested for Python 3
#The original version of this script lived in the Tableau Server directory
#That's why newpath adds on 9.1\bin (the second \ is so Python reads it as a slash and not a character escape
#If you have tabadmin on your path, you can comment out lines 13 & 15
#tinys3 is an easy way to handle S3 activity - https://github.com/smore-inc/tinys3
import tinys3
#os give you access to operating system interfaces
import os
#glob finds patterns
import glob
import subprocess
#Move into BIN Folder
path = os.getcwd()
#print path
newpath = path+'\9.1\\bin'
#print newpath
os.chdir(newpath)
#print os.getcwd()
#create an S3 connection
conn = tinys3.Connection('AWS AccessKey','AWS Secret Key')
#find TSBAK File and push
for file in glob.glob('*.tsbak'):
f = open(file,'rb')
#Syntax for conn.upload = (filename, f, bucket)
conn.upload('backup',f,'tableauctdbackup')
#you can also add TLS with conn.upload('backup',f,'tableauctdbackup',tls=TRUE)
#change the endpoint with conn.upload('backup',f,'tableauctdbackup',endpoint=s3-website-us-west-2.amazonaws.com)
#this would be if you want to replicate files across regions or Availability zones
#expire the file conn.upload('my_awesome_key.zip',f,bucket='sample_bucket',expires=3600)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment