mysqldump batch script runs but leaves empty file - batch-file

I have made a simple batch script to back up a database, however when it runs it creates a empty file. This batch script is located in the same folder where mysqldump.exe is located. Following code:
#ECHO off
start /wait mysqldump.exe -u user -p "password" database > "Z:\sql-backup\"database-backup.sql
Any help would really help. New to Batch scripting.

I had used the below commands in batch file and it has worked properly.
First of all you should goto bin directory and issue the below mentioned mysqldump command. The same you can mention in the batch file as it is.
cd C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin
mysqldump -uroot -ppassword database > "C:\ProgramData\MySQL\MySQL Server 5.6\Data\"Database_bkp.sql

Related

How do I execute cmd commands through a bat file?

I need to create a .bat to put together with my setup system to install a network driver, but I have some difficulties in creating the bat.
This .bat needs:
execute a cmd with administrator privileges
run this command: netcfg.exe -v -l networkbll_lwf.inf -c s -i nt_networkbll
exit
The folder for all files location is: c:\Windows\System\Drivers.
You might have to use another batch file first to launch the second with admin rights.
In the first use
runas /noprofile /user:mymachine\administrator batchfilename.bat
PAUSE
and write the needed command in another bat file

batch file - sqlcmd failing in scheduled tasks (0x2331)

I'm trying to use scheduled tasks to run a database back up once per day using sqlcmd that points to a SQL script.
If I open a command prompt and run the code in the batch file everything is successful but when task manager tries it gets a 0x2331 error.
A search reveals it's something to do with permissions - maybe I need to change the path to the sql file?
here is the script:
ECHO OFF
ECHO This is running to backup a database
sqlcmd -S COMPNAME -i C:\backup.sql
GO
ECHO Success!
EXIT
I'm new to batch files to tried to keep it as simple as possble.

Mysqldump simple batch issue

I am trying to write a simple batch file to run a MySqlDump. I created a new file in notepad, pasted the text below, and then saved it as a bat file. However when I attempt to run this in command prompt the screen pops up right away and then goes away just as fast. If I run these commands manually in command prompt it works as expected.
This is my first bat file I have created so I'm guessing I am doing something wrong? In looking at similar issues in StackOverflow the code below appears to be what is suggested so I'm confused why this isn't working?
cd C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin
mysqldump --user=xxx --password=xxx --all-databases --single-transaction > C:\Users\JMaze\Desktop\nSite\MySQL Backup\bk.sql
Adding the quotes to each of the file paths appears to have fixed the issue. The final code looks like this:
cd "C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin"
mysqldump --user=xxx --password=xxx --all-databases --single-transaction > "C:\Users\JMaze\Desktop\nSite\MySQL Backup\bk.sql"

How do I create a batch file from Advantage SQL script?

I have created sql script using SQL Utility within Advantage Data Architect of Sybase. The script is saved on my workstation. Now, how do I create a batch file that would run the script from desktop?
I found this command line online, but it doesn't seem to be working:
#echo on
isql -U "username" -P "password" -S "servername" -D "database" -i "path"
#echo off
I am new to Advantage SQL, trying to learn as much as I can.
Thanks.
You use adssqlcmd.exe, passing the connection and script name as command-line parameters. There is an example of doing so on that second page:
rem Using the connection path option, and process the script files
rem after making the connection.
rem The program will terminate after processing all files
asqlcmd.exe -S ALS:d:\mydata\main.add -U user1 -P sample -i myscript.sql
There's a list of supported commands that outline what you can and can't do in the script as well.
Also note that adssqlcmd.exe is a feature added in ADS v11, and is not available to earlier versions of ADS.

Batch file and ftp script works, unless used with task scheduler

I have written a batch file that calls an FTP script that downloads files from multiple folders from a remote server. When I execute the batch file it works perfectly. However when I schedule it with task scheduler it pulls all the files down except for those in one specific folder.
I've checked permissions, there are no issues there. The relevant parts of the batch file and FTP script are below. For the purposes of this question I've shortened both. So the question would be why does it download from the "RWSmith" directory but not the "TrimarkFoodcraft" directory when run from Task Scheduler. I know that batch files are not case sensitive but I added the extra suffixes because the files do end in .DAT instead of .dat and they were not downloading.
Script and Batch File are on Windows Server 2008 R2 and the server it is downloading from is Windows Server 2003.
Batch File:
ftp -i -s:ftpCommands.txt 0.0.0.0
FTP Script:
username
password
cd "AdamsBurch"</br>
lcd "C:\EDIScanner\DistributerEDIFiles\AdamsBurch"
mget *.dat
mdelete *.dat
cd \
cd "RWSmith"
lcd \
lcd "C:\EDIScanner\DistributerEDIFiles\RWSmith"
mget *.dat
mdelete *.dat
cd \
cd "TrimarkFoodcraft"
lcd \
lcd "C:\EDIScanner\DistributerEDIFiles\TrimarkFoodcraft"
mget *.dat
mget *.DAT
mdelete *.dat
mdelete *.DAT
close
bye
The FTP account might not be in the root directory. After connecting, use pwd to see what directory is current.
username
password
pwd
Instead of assuming the directories are off of the root, use relative references.
cd ..
cd "TrimarkFoodcraft"

Resources