?
Solved

Copy selected backup file to another drive

Posted on 2014-03-05
7
Medium Priority
?
269 Views
Last Modified: 2014-03-09
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?
0
Comment
Question by:mcooper13
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 4

Expert Comment

by:Jason Ryberg
ID: 39906525
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

0
 

Author Comment

by:mcooper13
ID: 39906756
What would be the best way to schedule PowerShell script to run daily? Task scheduler?
0
 
LVL 4

Expert Comment

by:Jason Ryberg
ID: 39906783
Yes, task scheduler is a good choice.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:Gerald Connolly
ID: 39908654
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.
0
 

Author Comment

by:mcooper13
ID: 39909187
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.
0
 
LVL 4

Accepted Solution

by:
Jason Ryberg earned 1400 total points
ID: 39909507
The easiest way to parse through a single directory with all your server backups would be to input a file that contains the list of servers.  Not knowing if you conform to a server naming standard, it would be hard to recommend a looping method to group the server backups by server name.

So, assuming you have a list you can input into PowerShell (CSV, txt, etc):

$servers = Import-CSV C:\pathToservers.csv #With "servers" as the header

$Path = \\server\backup_directory
#$BackupDir = Get-ChildItem $Path

$mostrecentBUs = @()

$servers | % {

  $mostrecentBUs += Get-ChildItem "$Path\$($_.servers)_*" | sort LastWriteTime | Select -Last 1

}

$mostrecentBUs | % { Copy-Item $_.FullName \\destination\address  }

Open in new window


Hopefully this helps.
0
 
LVL 17

Expert Comment

by:Gerald Connolly
ID: 39916806
Doh! and i didnt even get a few points for pointing out that glitch!!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For anyone that has accidentally used newSID with Server 2008 R2 (like I did) and hasn't been able to get the server running again because you were unlucky (as I was) and had no backups - I was able to get things working by doing a Registry Hive rec…
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question