For some of our SQL servers, I am sweeping backup dumps instead of backing the databases up directly (it's a political thing). What I'd like to do is have a script run that deletes the contents of the backup directory only after a successful backup. Right now I have a script that runs and deletes the contects of the directory, but it runs the delete command whether or not the backup completes successfully. For example, last night there was a VSS issue on the server i was trying to back up, so I only backed up about 20GB out of 250GB and everything was deleted by the script.
Here is the current script:
@echo off
ECHO =====NetWorker SAVE SET COMMAND=======
SHIFT
SET arg=%0
:loop
SHIFT
IF %0.==. GOTO save
SET arg=%arg% %0
GOTO loop
:save
"C:\Program Files\Legato\nsr\bin\save.exe" %arg%
del /s /q "D:\MSSQL10.MSSQLSERVER\MSSQL\Backup\*.*"
echo Successful
What do I need to do to make it so the del command only executes after a successful backup? Using NetWorker 7.6.3. This might be a good time to mention I'm not awesome at scripting
I wanted to chime back in on this. I've worked out a script that will delete files in directories only after a successful backup. This will work for Windows only:
@echo off
ECHO =====NetWorker SAVE SET COMMAND=======
SHIFT
SET arg=%0
:loop
SHIFT
IF %0.==. GOTO save
SET arg=%arg% %0
SET delpath=%0
GOTO loop
REM These are the save commands that run the required
REM NetWorker backup commands.
:save
REM Note: Enter correct path to your NetWorker bin
REM directory (line below is default path)
"C:\Program Files\Legato\nsr\bin\save.exe" %arg%
IF %ERRORLEVEL% EQU 0 (GOTO success) ELSE (GOTO failure)
:success
del /s /q %delpath%\*.*
echo Successful, contents of %delpath% deleted.
GOTO end
:failure
echo An error was found. Contents of %delpath% not deleted.
Really? Nobody has done anything like this? C'mon community, I know you can do better than that!
In 21st century most people use online backup so they do not need to mess around with scripts. There are several ways how to do this, but I would suggest to include del command to be part of SQL dump instead. That way, old dump stays there until new one is ready to go (unless those overwrite each other already where in such case you do not need delete action at all).
You need to add into your script a test to check the last backup, something like running an mminfo:
mminfo -q "savetime>1 day ago,name=MSSQL:,client=clientname,incomplete=false" -r {some fields}
Then querying the results you get out until you are happy what you have is deleteable - when you are using the delete command in a script it is sensible to put as many checks in as you can to make really really sure you have backed your data up before deleting it.
Yes..that works. But problem with doing a "push" backup (client initiated), is that you dont know if tape drive is
available, tape media is available etc. That's why savepnpc is there. it creates a small "script" which you can modify to what you want.
In my case, I use it to backup MYSQL database. using the savepnpc "script" , I stop the slave threads, take backup and once backup is done, restart slave threads. This is all done in 3 lines.
I dont know much about your configuration. In an enterprise tuned setup i would assume that devices and media were available. Its still possible to check this client side via script.
I havent heard great things about savepnpc over the years but maybe its better now.
imasock
16 Posts
2577
0
Posted June 11th, 2012 12:00
I wanted to chime back in on this. I've worked out a script that will delete files in directories only after a successful backup. This will work for Windows only:
@echo off
ECHO =====NetWorker SAVE SET COMMAND=======
SHIFT
SET arg=%0
:loop
SHIFT
IF %0.==. GOTO save
SET arg=%arg% %0
SET delpath=%0
GOTO loop
REM These are the save commands that run the required
REM NetWorker backup commands.
:save
REM Note: Enter correct path to your NetWorker bin
REM directory (line below is default path)
"C:\Program Files\Legato\nsr\bin\save.exe" %arg%
IF %ERRORLEVEL% EQU 0 (GOTO success) ELSE (GOTO failure)
:success
del /s /q %delpath%\*.*
echo Successful, contents of %delpath% deleted.
GOTO end
:failure
echo An error was found. Contents of %delpath% not deleted.
:end