I would like to ask for your assistance in updating the script below in order to move the backup file (*.tsbak) after the backup and send an email notification after.
The script below is a bat file that is being used to backup our Tableau Server on a daily basis. Currently, we move the backup file manually and send a email manually to the stakeholders that the backup is complete.
I would like to seek your assistance to do the following if possible:
1. If backup is successful:
A. Delete the existing backup copy from E:\Tableau\Backup\
B. Copy the new backup from D:\Tableau\Tableau_Backup\ to E:\Tableau\Backup\
C. Delete the backup from D:\Tableau\Tableau_Backup\ upon successful copy (Prefer to copy than move to prevent any system failure and having the backup corrupted)
D. Send email of the successful completion
2. If backup encountered a failure:
A. Send an email with the failure encountered
Hoping for a favorable response on this one. Thank you, Tableau Community!
:: Please customise this to the version of Tableau Server you are running.
set "BINPATH=D:\Program Files\Tableau Server\%VERSION%\bin"
:: This command sets the path to the Tableau Server bin directory in order to use the tabadmin command. Change this to match the location of your Tableau Server install.
:: This command sets the path to the backup folder - change this to match the location of your backup folder
:: This command creates a variable called SAVESTAMP which grabs the system time and formats in to look like DD-MM-YYYY
:: This gets rid of the slashes in the system date which messes up the commands later when we're trying to append the date to the filename
echo %date% %time%: *** Housekeeping started ***
:: Prints that text to the DOS prompt
cd /d %BINPATH%
:: changes directory to the above path and takes into account a drive change with the /d command
:: ROTATING THE LOG FILES
echo %date% %time%: Cleaning out old log files...
forfiles -p %BACKUPPATH% -s -m *.zip /D -5 /C "cmd /c del @path"
:: Cleans out files in the specified directory that end with a .zip extension and are older than 5 days
echo %date% %time%: Backing up log files...
tabadmin ziplogs -l -n -f
copy logs.zip %BACKUPPATH%\logs-%SAVESTAMP%.zip"
:: BACKING UP THE TABLEAU SERVER
echo %date% %time%: Cleaning out old backup files...
forfiles -p %BACKUPPATH% -s -m *.tsbak* /D -2 /C "cmd /c del @path"
:: Cleans out files in the specified directory that end in .tsbak extension and are older than 2 days
echo %date% %time%: Backing up data...
tabadmin backup %BACKUPPATH%\ts_backup -d
:: Backs up the Tableau Server and creates a file ts_backup.tsbak with the system date appended to the filename
REM echo %date% %time%: Running cleanup...
REM tabadmin cleanup
:: Cleans out the Tableau server logs.
echo %date% %time%: *** Housekeeping completed ***
:: Prints that text to the DOS prompt to show that the jobs are all done