I've tried to take backup using Windows batch command. It's working, but I need to take automatic backups with different name for 7 days as day1.bak
, day2.bak
, ...
SQLCMD -S xx.xx.xxx.xx -U test -P xxxx
-Q "BACKUP DATABASE test TO DISK='C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Backup\test4.bak'"
Is there is a Jenkins plugin to do this automatically?
set mydate=%date:~10%%date:~4,2%%date:~7,2%
set mytime=%time:~0,2%%time:~3,2%%time:~6,2%
forfiles /P 'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Backup\' /S /M *.bak /D -7 /C "cmd /c del @PATH" // Delete all file less than 7 days
sqlcmd -S .\sqlexpress -Q "BACKUP DATABASE [YourDataBaseName] TO DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Backup\%mydate%_%mytime%.bak' WITH NOFORMAT, NOINIT, NAME = N'YourDataBaseName-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10"
Note: filename equals date-time now by using both variable mydate & mytime
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.