Link to home
Start Free TrialLog in
Avatar of mcooper13
mcooper13Flag for United States of America

asked on

Copy selected backup file to another drive

My backup application outputs a file called servername_YYYY_MM_DD_HH_MM_SS with each backup job run.

I wish to automate copying this file to another drive for offsite storage purposes. Since there will be multiple backup files of this server by date/time what script can I use to select the last, or most recent backup file to copy?
Avatar of Jason Ryberg
Jason Ryberg

Here is a PowerShell method to select the latest written file in a directory:

$Path = \\server\backup_directory
Get-ChildItem $Path | sort LastWriteTime | Select -Last 1

Open in new window

Avatar of mcooper13

ASKER

What would be the best way to schedule PowerShell script to run daily? Task scheduler?
Yes, task scheduler is a good choice.
Avatar of Gerald Connolly
Just to be pedantic, that script doesnt do what you expect, it is using the last write time (not sure if thats "created date-time" or "modified date-time") from the file metadata, not selecting by filename.
To clarify, the drive that stores the daily backup files for server1 will also have backup files for server2, 3, etc. so good point. The file name does need to be part of the selection criteria.
ASKER CERTIFIED SOLUTION
Avatar of Jason Ryberg
Jason Ryberg

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Doh! and i didnt even get a few points for pointing out that glitch!!