Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Copy selected backup file to another drive

Posted on 2014-03-05
7
Medium Priority
?
272 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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

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…
Resolving an irritating Remote Desktop connection that stops your saved credentials from being used.
This tutorial will walk an individual through the steps necessary to configure their installation of BackupExec 2012 to use network shared disk space. Verify that the path to the shared storage is valid and that data can be written to that location:…
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…
Suggested Courses

810 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