3 Replies Latest reply on Jul 26, 2017 6:54 PM by john liptak

    Bulk Download of workbooks using TABCMD Get - Unknown File Extension

    john liptak

      Hi All,

      I'm generating a batch script that will issue a "TABCMD GET" for every workbook on the server.  The way i do this is to read the Tableau Database and get all the workbook details but i cant find the file extension of the workbook.  ie; Is it a TWB or TWBX.  Without the extension i cant generate the source or target.  eg;

       

      tabcmd get "/workbooks/MyWorkbook.???" -f "E:\DownloadedWorkbooks\MyWorkbook.???"

       

      I have read that you don't need to know the source extension as Tableau will figure it out.  ie; both of these will work

       

      tabcmd get "/workbooks/MyWorkbook.twb" -f "E:\DownloadedWorkbooks\MyWorkbook.twb"

      tabcmd get "/workbooks/MyWorkbook.twbx" -f "E:\DownloadedWorkbooks\MyWorkbook.twb"

       

      but the target workbook needs an accurate extension otherwise you cant open it in Tableau Desktop.

       

      Tableau must know the extension because the workbooks download with the correct extension from Tableau Server so it must be possible to derive.  Any suggestions on how i can derive the extension?

       

      cheers

        • 1. Re: Bulk Download of workbooks using TABCMD Get - Unknown File Extension
          Patrick A Van Der Hyde

          Hello John,

           

          I am asking around to try and locate an answer for you related to this question.  I am also moving this thread to Server Administration where other Server Administrators may be found and might  already know a solution. 

           

          Patrick 

          • 2. Re: Bulk Download of workbooks using TABCMD Get - Unknown File Extension
            Charles Ayotte-Trépanier

            Hi John,

             

            I built a Python script that identify unused workbooks/data sources, then take a backup, delete them and contact the owner. While it's python, most of the script just sends batch commands. The only thing the script below does that I wouldn't know how to do with batch is to determine if a file is zipped.

             

            I'm in a hurry right now so I'll just bluntly paste the part of the script that might help you. I'm not a programmer, and that was my first ever 'program', so please excuse how the code looks

             

            Basically, there's 4 steps:

             

            1. Try downloading object as .twb/.tds

            2. If it failed to download, adding '?noExtract=true' to the name of the object will most likely solve the issue (I eliminated failures after adding that step)

            3. Verify if the file you just downloaded is a zipped file

            4. If it's zipped, change the extension

             

             

                      for tab_object in objects_to_delete:

                                        save_to = directory+"\\"+tab_object[url_pos]

                                        succ_backup = 1

                                        try:

                                            succ_backup = os.system(r'tabcmd get "/'+(r'workbooks/' if tab_object[type_pos]=='Workbook' else r'datasources/') +tab_object[url_pos]+ (r'.twb' if tab_object[type_pos]=='Workbook' else r'.tds') + r'" -f "'+save_to+'" '+tabcmd_login_str + ('' if tab_object[site_pos]==r'Default' else (r' -t "'+ tab_object[site_pos]+r'"') ) )

                                        except:

                                            write_to_logs('First backup attempt returned error')

                                        if succ_backup==1:

                                            try:

                                                succ_backup = os.system(r'tabcmd get "/'+(r'workbooks/' if tab_object[type_pos]=='Workbook' else r'datasources/') +tab_object[url_pos]+ (r'.twb' if tab_object[type_pos]=='Workbook' else r'.tds') + r'?noExtract=true" -f "'+save_to+'" '+tabcmd_login_str + ('' if tab_object[site_pos]==r'Default' else (r' -t '+ tab_object[site_pos]+r'"') ))

                                            except:

                                                write_to_logs('Second backup attempt returned error')                       

               

                                        if succ_backup==0:

                                            err = 0

                                            #add proper extension to the backup file

                                            if tab_object[0]=='Workbook':

                                                if zipfile.is_zipfile(save_to):

                                                    if(os.path.exists(save_to+r'.twbx')):

                                                        try:

                                                            os.remove(save_to+r'.twbx')

                                                        except:

                                                            err=1

                                                            write_to_logs('Could not remove file: '+save_to+r'.twbx')

                                                    try:       

                                                        os.rename(save_to,save_to+r'.twbx')

                                                    except:

                                                        err=1

                                                        write_to_logs('Could not rename file: '+save_to)

                                                    tab_object.append(save_to+r'.twbx')

                                                else:

                                                    if(os.path.exists(save_to+r'.twb')):

                                                        try:

                                                            os.remove(save_to+r'.twb')

                                                        except:

                                                            err=1

                                                            write_to_logs('Could not remove file: '+save_to+r'.twb')

                                                    try:

                                                        os.rename(save_to,save_to+r'.twb')

                                                    except:

                                                        err=1

                                                        write_to_logs('Could not rename file: '+save_to)

                                                    tab_object.append(save_to+r'.twb')

                                            else:

                                                if zipfile.is_zipfile(save_to):

                                                    if(os.path.exists(save_to+r'.tdsx')):

                                                        try:

                                                            os.remove(save_to+r'.tdsx')

                                                        except:

                                                            err=1

                                                            write_to_logs('Could not remove file: '+save_to+r'.tdsx')

                                                    try:

                                                        os.rename(save_to,save_to+r'.tdsx')

                                                    except:

                                                        err=1

                                                        write_to_logs('Could not rename file: '+save_to)

                                                    tab_object.append(save_to+r'.tdsx')

                                                else:

                                                    if(os.path.exists(save_to+r'.tds')):

                                                        try:

                                                            os.remove(save_to+r'.tds')

                                                        except:

                                                            err=1

                                                            write_to_logs('Could not remove file: '+save_to+r'.tds')

                                                    try:       

                                                        os.rename(save_to,save_to+r'.tds')

                                                    except:

                                                        err=1

                                                        write_to_logs('Could not rename file: '+save_to)

                                                    tab_object.append(save_to+r'.tds')

            • 3. Re: Bulk Download of workbooks using TABCMD Get - Unknown File Extension
              john liptak

              Thanks for the script Charles.  I eventually figured that a left join from the Workbooks table to the extracts table will identify if the workbook has an extract attached to it.  if so then it's a twbx if not then it's a twb.

               

                  Select w.*, e.*

                    From Workbooks w Left Outer Join Extracts e on e.Workbook_id = w.id   

               

              Seems to work for me. Obviously you'll need access to the Tableau DB.  You can read about that here

               

              Cheers