Solved

Copy selected backup file to another drive

Posted on 2014-03-05
7
262 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
  • 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 16

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 350 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 16

Expert Comment

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

Featured Post

Want to promote your upcoming event?

Attending an event? Speaking at a conference? Or exhibiting at a tradeshow? Easily inform your contacts by using a promotional banner in your email signature. This will ensure your organization’s most important contacts are in the know.

Join & Write a Comment

Redirected folders in a windows domain can be quite useful for a number of reasons, one of them being that with redirected application data, you can give users more seamless experience when logging into different workstations.  For example, if a use…
New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now