I currently have to windows batch files the first takes all files in a directory ending .bak and adds them to a rar file with todays date in the name
the second one ftp the rar file to another server.
the first ones code is
set path="C:\Program Files\WinRAR\";%path%
set date=%dd-mm-yyyy%
rar a D:\backups\dbs.rar -ri1 -mt2 -ag[dd-mm-yyyy] -m5 D:\backups\*.BAK
del D:\backups\*.BAK
which is called from inside sql server manager when its finished backing up the databases but could easily be run from a scheduled task
the seconds code is
@echo off
echo user Dbusser> ftpuploader.dat
echo ftppassword>> ftpuploader.dat
echo bin>> ftpuploader.dat
echo put %1>> ftpuploader.dat
echo quit>> ftpuploader.dat
ftp -n -s:ftpuploader.dat 127.0.0.1
del ftpuploader.dat
which I manually called from a cmd promt with the name of the rar file as an argument
ftpuploader.bat d:\pathtorar\dbs[21-10-2013].rar
what I want to know is can anyone tell me how to either merge the two files so it automatically uploads the file once its created and finished it or automate the schedule task to that it changes the date bit in the name of the rar file every day
thanks
This requires XP Pro and higher to use Wmic.
It sets the variable with the date, in a reliable manner, and uses that to create the RAR filename and also launch the FTP batch file.
I changed this line if not errorlevel 1 del D:\backups\*.BAK which should protect the *.bak files from being deleted if the RAR archiving fails for any reason.
@echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "datestamp=%DD%-%MM%-%YYYY%"
set path="C:\Program Files\WinRAR\";%path%
rar a D:\backups\dbs[%datestamp%].rar -ri1 -mt2 -m5 D:\backups\*.BAK
if not errorlevel 1 del D:\backups\*.BAK
ftpuploader.bat D:\backups\dbs[%datestamp%].rar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With