Recently when I was working database backups copy to external drives or whatever destination , I tried it with new solution using XCOPY command. Before that solution I was using XP_CMDSHELL command in SQL Server to copy database backup file to external drive, also we should avoid to use XP_CMDSHELL for security concern. So out of SQL server script\query and other tool, the solution came with XCOPY command which copy latest files or as per date specified, so later database backup files or the files created on or after date specified as input. You can visit XCOPY command here.
Lets first share me the command which I am using to copy latest database backup files. Here I am using some variables in the code, but let’s share me script first then I will explain the variables.
XCOPY /Y %source%\%extension% %destination% /s /i /D:%dwDate%
You can see batch file created with above code and the variables used inside and how they are integrated with final XCOPY command. after get to run it will copy database backup files to external drive or whatever destination using source, Destination, file extension (.bak or .trn here) and the date on or after the backup files created. Let’s implement and run it.
This code in batch files copy all the files created Today with specified file type from source folders including sub folders to destination. So lets run batch and see what’s inside. Lets try with sample example and local drives,
Apart from XP_CMDSHELL command using in SQL Server, which methods you are using database backup files to external drives? Please share here. I will post further topic with different method for the same. Hope you enjoyed it.