How I can Create log for post deployment script in dacpac? - visual-studio-2013

I am using the SQL server Database Project. To deploy .dacpac file I am using the SqlPackage.exe with command line arguments.
Using Action: DriftReport, I am able to create the log (Added/update/Modified) of objects. But Still I am not able to create the log for post deployment script (operation like insert, update, etc).
Is there any way to create reports for successful and failures data insertion.

What I have done to achieve this is about same as Peter's comment. I got a batch file something as follow
sqlpackage.exe /a:publish /tcs:"the connection string" /sf:".\package.dacpac" >"%1" 2>"%2"
FOR %%A IN ("%2") DO SET FileSize=%%~zA
if %FileSize% gtr 0 start notepad "%2"
Then I would run the batch as:
thebatch.bat result.txt error_result.text
The idea was redirect the output of this console command into file "result.txt"(by using " >") and redirect the error message to "error_result.text"(by using " 2>"), and then to rely on %~z in batch file to get a file size and open the file only if something went wrong.

Related

Redirecting output of multiple bat files to one console window

I am running multiple microservices locally for development purposes. Currently I am doing it by a .bat script, where I am calling other .bat files, which are starting my services. It starts multiple console windows, and this is not handy to navigate between outputs.
The script which is starting services now looks like this:
start cmd /k call api_one.bat
start cmd /k call api_two.bat
...
In api_xxx.bat I am starting iisexpress with my api.
I am looking for a way to make it more comfortable. For example by redirecting all of the outputs to a single one, with for example a prefix to identify from which script output lines are from.
I had a similar problem, where I was calling a batch file from a batch file which started another batch file.. to complicated to explain but let me get you some code that helped me:
content from test.bat:
set logname=.\log.log
if exist %logname% ( type nul > %logname%
)
echo Now starting example.bat>>%logname%
call C:\example.bat >>%logname%
echo finished example.bat>>%logname%
so now here is content of example.bat:
echo starting integrated commands
start /b cmd /k "C:\example2.bat"
[some code to check for a process that starts in example2.bat]
echo finished integrated commands
and the content of example2.bat can be whatever you want and is also displayed in the logfile.
Note that my example2.bat has an exit at the end, because example.bat checks if example2.bat is running. only when it finishes it goes on with the script. For myself it worked out I got everything from all 3 scripts into one logfile.

Detect a Missing file based on its Date

I need to manually monitor a random windows-based backup program for failures and the only way to do this is via checking for the daily backup file it makes.
A batch file would be simplest for me to implement. It would need to scan a directory for a certain file type and then do X if a file doesn't exist that was created/modified yesterday.
C:\backups\random-named-file.tib 27/03/2017
C:\backups\random-named-file.tib 28/03/2017
C:\backups\random-named-file.tib 29/03/2017
So if a random-named-file.tib wasnt created or modified yesterday, it means the backup failed and I would write output to the console saying "Backup Failed"
Does anyone please have any ideas ?
EDIT :
To clarify, the backup files are coming from a custom application that has no way to check for missed backups. The batch file solution I'm looking for will be integrated into our RMM platform, which will take the results of the batch file and raise a support desk ticket for our Service desk to action.
The backup application will apply its own retention policies and delete any backups older then 4 days.
I'm just trying to detect if a backup was missed the previous day. The filenames are variable, the only constant is the file extension ( *.tib)
This backup app doesn't write eventlogs, nor does it create its own log files I can parse for Failure messages.
1) I would suggest you, go through this article
four-ways-to-manage-windows-server-2008-backup-on-multiple-servers
2) There is a windows scheduler which can act according to your situation
Window scheduler Wiki
3) You can write scripts which alert you whenever it fails
4) I have found a Solution for your similar kind of problem
make-windows-task-scheduler-alert-on-fail
TL:Dr --> see step 4
I manged to do what you asked. On a quick note, since it's Windows backup program there should be a way to automatically alert when backup fails.
Note about this example: I did this in a specific folder structure. If you want to change the location of batch file, second line of code inside batch file needs to be updated with appropriate path. In this example the path is relative, but it's easy to change, so I leave that up to you.
Here is my folder structure:
\---batch # Folder with batch file
backups.txt # check_backups.bat creates this file
check_backups.bat # Batch file that does the job
| filename1.tib
| filename2.tib
| filename3.tib
| filename5.tib
Here is the code of batch file (check_backups.bat):
#echo off
dir ..\* /a-d /b > "%~dp0\backups.txt"
set count=1
setlocal EnableDelayedExpansion
FOR /F "delims=*" %%A IN (backups.txt) DO (
SET fl=%%~nA
IF !fl:~8! NEQ !count! (
echo Backup Failed: Missing file is 'filename!count!.tib'
goto failed
)
SET /A count=!count!+1
)
echo All is good
:failed
pause
If filename9.tib is missing you will get a message: "Backup failed: Missing file is filename9.tib".
If everyhing is good you will get a message: "All is good".

how to detect the existence of a txt file using a batch commands

I need to write a batch script to run on windows.
I will schedule that file to run every minute on the server to test the existence of a txt file, on that server and then delete it.
Wha the batch file does is this:
check the existence of txt file on the server and if it finds that file in that location, 1) delete it 2 ) run some other actions.
I know what those actions are. I got the code for it already.
I need help only on how to check the existence of that txt file and how to delete it if it is there.
What commands do I need?
I'd appreciate if you could throw some pointers.
Rob Van Der Woude's batch file reference is an excellent source:
http://www.robvanderwoude.com/if.php
As it examples show how this can be achieved.
IF [NOT] EXIST filename command
Something like this...
IF EXIST file.txt Start script.bat
Or...
IF EXIST file.txt GOTO somelabel

Findstr on remoteserver unsuccessful

I am trying to run this .bat script
set target_path =\\remoteserver\c$\newfolder\newfolder1\logs >log.txt
findstr /m "ERROR" "%target_path%\file1.txt" >> log.txt
The expected output from this .bat file is that it will pick up "ERROR" string from file1.txt from the "remoteserver" and will show as output in log.txt.
But,once when i run this script it shows me the following error
FINDSTR: Cannot open \remoteserver\c$\newfolder ...
Kindly, suggest me the flaws or correct script so that the above script gets executed successfully with the expected output .
thanks for your quick update and sorry for acknowledging late. I tried executing the batch script with the necessary corrections you mentioned needed in the script , but still i face the same problem . I am unable to fetch the "ERROR" from log file and get the expected output. Is there any other field to be added to "FINDSTR" to pull up the ERROR ??.. Kindly, assist me for the same.
Thanx in advance.
Not at all sure how you achieved that response given the scant 2 lines of code you've posted.
You are setting the variable "target_path ", not "target_path" according to your first line. Batch is sensitive to spaces in a set statement.
Since "target_path" is not set, it's a total mystery how your response is Cannot open \remoteserver\c$\newfolder ... unless the variable "target_path" had been previously set in the environment. The findstr should, with the posted code, have been executed against the file "\file1.txt" - not as reported.

Close Adobe Acrobat 4 (executed via batch) when file name not found

I have developed a solution where a PL/SQL Oracle API generates the file name of a PDF (inc. full file path) that requires printing (parameter 1) and then using the DBMS_SCHEDULER passes both that file name and a printer name (parameter 2) to the following batch file:
"C:\Program Files (x86)\Adobe\Acrobat 4.0\Reader\AcroRd32.exe" /t %1 %2
However there are occurrences where the file name passed to the batch file does not exist. Because the file does not exist Adobe continues to run (in background). This stops the API from executing again, until someone ends the windows process manually, as the DBMS job is connected to the Adobe instance.
Unfortunately (unless there is a way in Oracle to check if the file exists in the directory) I cannot work around this issue on the Oracle side, therefore I need to tackle it on the Windows side.
Therefore is there any additional logic that I can add to the batch file or any other script that will validate the existence of the file and if the file does not exist then end the process. The solution must be efficient as the printing of the PDF files is time sensitive.
If anyone does have an Oracle side solution for this issue then I will happily supply the relevant code.
Thanks in advance.
Not launching Acrobat is easier than trying to close it. You can just check for the file existence in the batch file using the IF EXIST command:
#IF EXIST %1 (
"C:\Program Files (x86)\Adobe\Acrobat 4.0\Reader\AcroRd32.exe" /t %1 %2
) ELSE (
REM optionally report error?
)
There are ways to check for the file from Oracle, but this is probably simpler since you already have a batch file, unless you want to test and report the error earlier in the process.

Resources