I am running a 2008 SQL server. I am using remote backup to backup the server and have two batch files to trigger the backup process. The first batch file contains:
#echo off
CALL "" "C:\Scripts\SQL Maintainence\Nightly Maintenance 2008 SSE.bat"
The second batch file (Nightly Maintenance 2008 SEE) looks like this:
#echo off
osql -S %SERVER% -d msdb /U (username) /P (password) -i "Nightly Maintenance 2008 SSE.sql" -o "Nightly Maintenance 2008 SSE.txt"
For some reason, the first batch file is not calling for the second batch file to run, the script works when manually ran.
I am very new to writing batch files and have done quite a bit of research up to this point. Any help or maybe an article that can help with my issue would be greatly appreciated.
Reposted as answer instead of question...
I think you need to delete the "" immediately after the CALL, like this:
CALL "C:\Scripts\SQL Maintainence\Nightly Maintenance 2008 SSE.bat"
Related
I am using a SQL-Server 2012 (SP2) on a WinServer 2012 R2. I created a maintenance plan that makes a backup of my databases and deletes report files and backup files that are older than 2 days.
My problem is that the maintenance plan doesn't delete files which are older than 2 days. these files are also not deleted after 5 or 6 days. The backups are verified and compressed.
I have rights on the directory (agent is running under LocalSystem) and in the task properties under "file extension" I tried to set the name without and with a dot, e.g. ".bak", "bak" and "*.bak" but nothing works. I changed the order of the task and nothing works.
But I always get success messages. So what is here wrong?
Just to clarify, are you trying to run a script (i.e., .bat) to handle some of this through SQLCMD, and calling that script through Task Scheduler? From your question, it sounds like you've set the Maintenance Plan up in SQL Server, but are trying to setup a "Task" to call it (Task Scheduler), rather than a "Job" (SQL Agent), my apologies if this is not the case.
It will be a lot tidier to do this through the SQL Agent (the SQL Server internal equivalent of Task Scheduler). Once you have a Maintenance Paln you can test through the Management Studio Interface, it's a breeze to add the Agent Job.
If you are running a Task Scheduler Task to call a script, it is likely you're getting "success" because the Task started your script, but the script isn't setup to handle the returns from the SQLCMD call properly.
I have tried to solve it in different ways and there has been no way, the fastest I have found is to use a .bat that deletes them and schedule a windows task that does it every night.
This bat clears from the last 3 days :
FORFILES /P "C:\Directorio" /S /D -3 /c "CMD /c DEL /Q #PATH"
I get a zipped file of sql dumps everyday. I unzip it, and then run this script everyday using a task scheduler to update the database.
#echo off
ECHO %USERNAME% started the batch process at %TIME% >output.txt
for %%f in (C:\Users\Desktop\Crash\*.sql) do (
sqlcmd.exe -S HUTRC1-HP -U sa -P hutrc#2121 -d test -i %%f >>output.txt)
exit
The database doesn't however get updated all the time. Let's just say it is not very reliable. There are some days when it is current, and other days when it's not current. Can't explain why. Is there more efficient script to update the database with? Preferably in powershell.
Creating an SSIS package will help you and achieve all that you want with better error handling.
There are multiple articles out there and a bunch of youtube videos. A youtube video can help you accomplish what you need in no time. Here are some articles that i quickly got off of msdn.
How to create an SSIS package.
How to unzip files in SSIS package without any C# knowledge
How to automate an SSIS package.
Hope this helps.
I am trying to execute a batch file from SQL Server Agent (as it needs to be done before some SSIS-packages are run).
When I execute the job it fails in a few seconds saying "Access denied".
The account under which SQL Server Agent runs has full control on the folder that contains the batch file. The result of the batch would be deleting some files in a folder, calling a webservice and get those same files back from the webservice.
I can run the batch file when I start it with my own (admin) account.
I googled and found several other questions and answers but none of those were covering my problem. I hope you can point to other options.
Thanks for your help.
Johan
Batch file contents:
echo Removing txt files of last run
del Employees.txt
del HrDepFun.txt
del HrEmpActual.txt
echo Files removed
echo Starting getconnectors
{Call Webservice} -> cannot disclose this on stackoverflow
echo Getconnectors done
Batch file execution statement from SQL Server Agent job (type Operating System (CmdExec)):
cmd.exe /c "c:\Program Files (x86)\AFAS\AFASRemote_Call_GetConnectors.bat" > connectorlog.txt 2> connectorerrorlog.txt
My Windows Server 2003 got corrupted and I'm trying to repair it but before that I'm trying to create a backup of my SQL Server databases.
Can anyone please tell me which files do I need to copy from the Windows command line as I'm not familiar with SQL Server. Database files from which I can restore data.
Its an old server but data is important.
And also if I repair Windows server 2003 using repair disk will it effect on SQL Server files ?
http://postimg.org/image/5jsstbqmd/
When I start server I get this error.
You can use this SQL command (adapt to your specific case):
--Back up the files in SalesGroup1:
BACKUP DATABASE YourDBName
TO DISK = 'Z:\SQLServerBackups\BackupFileName.bck';
GO
See Backup in Transact-SQL for more details.
To run a SQL script from command line:
sqlcmd -S myServer\instanceName -i C:\myScript.sql
Before messing with anything, you could take a complete image of your hard drive using a tool such as clonezilla.
I would get to the root of your disk and run
dir /a /s *.mdf
The .mdf file is the file extension that SQL Server uses, and that command will tell you where they are located. The log files are usually in the same directory.
As per your second question, the disk repair will only affect your database files if they are part of the corruption that is happening; which is quite likely if you were running a high I/O database when it crashed. I would definitely try and copy those files off before running a disk check.
I want Task Scheduler in Window run DailyJob.bat daily at a certain time, this file having content like this:
#echo off
DB2 CONNECT TO dbName USER usrName USING password
DB2 .........
DB2 ..........
Moreover, Task Scheduler will run this file by cmd.exe automatically, but cmd doesn't understand DB2 command. Please help me, thanks !
You need to call your db2 statements with the db2cmd command (http://www-01.ibm.com/support/knowledgecenter/SSEPGG_10.5.0/com.ibm.db2.luw.admin.cmd.doc/doc/r0002036.html?cp=SSEPGG_10.5.0%2F3-6-2-6-35)
From CMD.exe
db2cmd -i -c db2 list node directory
There are a lot of related questions in the Web about this problem.