1.

Solve : Database backup script issue?

Answer»

Hello everyone,

I created a batch script with the help of others and modified it to fit my needs. Anyways the first portion of the script works, it creates the backup, and compress it properly but the issue i am having is trying to delete the .bak file after its been compressed, so All i want to see is the zip file. I have searched long and hard for this answer but can't seem to get it right.


@echo Creating Backup folder located in c:/
MKDIR C:\Backups
If exist "C:\Backups" ECHO Directory EXISTS!
@echo Backing up your Database....This may take awhile.....
sqlcmd -S Servername\sqlinstancename -i backupDBscript.sql
SET SQL_Backup_script=C:\Path to file
SET MY_Path=C:\path to backup
set mydate=%date:~4,2%%date:~7,2%%date:~10,4%
for %%x in (*.bak) do cscript "%SQL_Backup_script%\zip.vbs" "%MY_PATH%\%%x" "%MY_PATH%\DB_%mydate%.zip"
del /Q/R "C:\Backups\*.bak"
@pauseI did add del "C:\Backups\*.bak" /q in a test batch file that worked but when i put it in the original batch file it didn't delete it
/R is not a VALID parameter or switch for the DEL command in batch code (command-line). /Q makes it run quietly without prompt and /F would force it to delete read-only files if that is what you were trying to achieve. What might help you while you are learning is to open command prompt and simply type the command you want help on and follow it with [space] /? (i.e. DEL /?)

Try DEL /Q /F "C:\Backups\*.bak"That didn't work :/bumpbump
bumpity bumpI am confused as to why you are hard coding the path C:\backup. Shouldn't all your .bak files be in the MY_PATH directory?
The code you were given should work as long as your .bak files are in that folder.
Code: [Select] DEL /Q /F "C:\Backups\*.bak"I was placing file in WRONG path Thanks guys!



Discussion

No Comment Found