使用特定名称(或最新名称)通过网络复制文件

Copy files over network with a specific name (or the most recent one)

我必须每天通过网络复制我的 SQL 服务器备份文件。为此,我正在考虑编写批处理文件或 powershell 脚本并将其 运行 作为计划任务。
此过程中的一个问题是区分特定数据库的最新文件,因为同一数据库的三天备份保存在源目录中。命名约定为:databaseName_backup_yyyy_mm_dd_hhmmss.bak
例如数据库myDatabase的源码目录下有这三个文件:
myDatabase_backup_2015_03_19_230000.bak
myDatabase_backup_2015_03_20_230000.bak
myDatabase_backup_2015_03_21_230000.bak

该文件要么是为某一特定数据库创建的最新文件,要么是名称包含上述当前日期的文件。

谢谢大家。

编辑:我可以在目标服务器上实现它,而不是在源服务器上。

我这样做,没有太多聪明的 Powershell 逻辑,借用传统的 CMD,因为 SQL 正在处理您的保留(从外观上看是 3 个完整备份)我执行以下操作。 运行 通过存储这些 SQL 备份的服务器上的任务计划程序(因此它们是 PULL 而不是从 SQL 发送)

$remoteserver = "servername"
$remoteshare = "backups$"

$toEmail = "something@something.com"
$subject = "$remoteserver Robocopy Log"
$fromEmail = "anemail@domain.com"
$smtpServer = "exchange.local"
$Attachment = "C:\scripts$remoteserver-copy.log"


robocopy "$remoteshare$remoteserver\" G:\LocalDestination\"$remoteserver"\ /s | Out-File $Attachment
Send-MailMessage $toEmail $subject -SmtpServer $smtpServer -From $fromEmail -Attachment $Attachment

`