SQL Server xp_copy_files security thoughts and able to specify files older than only?

techresearch7777777 1,921 Reputation points
2025-03-08T22:37:16.5733333+00:00

Hello noticed somewhat of a new recent feature xp_copy_files (for SQL Server2019 & higher) which we have SQL Server 2022 (believe most things similarly were done previously via xp_cmdshell which had security concerns).

Is it correct to say xp_copy_files is more secure than xp_cmdshell and if yes... how is it more secure and any concerns as well and what are the minimum permissions need to run this?

As an example test I have the following:

EXEC master.sys.xp_copy_files

'C:\SQLServer2022LocalBackups\*.bak', 

'S:\SharedTargetFolderLocation\';

But would like to copy all of my SQL .bak files that are only 1 day old instead of including all older previous days .bak files within source C drive Backups folder to target S drive Shared folder.

Does this new xp_copy_files have a parameter/option to do this (like say specify less than or equal to 1,440 minutes to represent 1 day)?

Thanks in advance.

SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
147 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.