script needed

Posted on 2014-01-17
Last Modified: 2014-04-29
I have a windows 2008 server that has a directory called D:\Vault backups
inside of this directory is a backup that occurs every night M-F.
I need to move the contents of the backup folder into another directory call Vaultlogix where it will be backed up to the cloud.
THe problem is that the backup directory under D:\vault backups recreates itself every night with a different day and time stamp that are not consistent. THe date stamp is, but the time stamp varies. So for example, here is the name of the current backup directory:
I need to move the contents of that folder to the vaultlogix folder and then delete empty date and time stamped directory that is left in the original location.
Can I do this with a batch file or some sort of a script?
  • 5
  • 2
LVL 53

Accepted Solution

Will Szymkowski earned 500 total points
ID: 39790101
You can use robocopy to accomplish this. Take a look at a PAQ that I answered with similar requirements that you have. See link below...


Author Comment

ID: 39790108
i got robocopy to work with a static folder name, but my challenge is how do I enter a variable to let robocopy know that it is to move the contents of the folder whose name begins with "vaultbackup" because the rest of the directory name is going to change daily and I need to have some type of wildcard entry that lets robocopy know to look in the directory that starts with that name...

Author Comment

ID: 39790109
i think i am close with this link, but still dont' know what i am doing
LVL 18

Expert Comment

by:Steven Harris
ID: 39790142
Although Robocopy is popular and easy to use, I tend to lean towards PowerShell's copy-item, but I think we still need some more info.  What is the full path of the source and destinations?  Such as:

"D:\Vault Backup\Vaultbackup_2014_01_16_11_00_09_PM"



In this case, you could use:

copy-item "D:\Vault Backup\Vaultbackup*\*.*" "E:\VaultLogix"
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.


Author Comment

ID: 39790886
ok, we are geting closer now. Does Powershell have a utility/command for MOVING the data? It needs to be relocated to a different directory on the same disk partition. It is over 30 gb so I don't want to copy it. Plus I want to make sure that when it move the contents of the "Vaultbackup_2014_01_16_11_00_09_PM" folder, that it removes the empty parent folder altogether from it's original location. That way when the next backup kicks in and gets copied to the "vault backup" folder it does not have to worry about overwriting anything which at this point the backup utility cannot do.
LVL 18

Expert Comment

by:Steven Harris
ID: 39791033
This is going to be a long post, so bare with me here...

Does Powershell have a utility/command for MOVING the data? It needs to be relocated to a different directory on the same disk partition. It is over 30 gb so I don't want to copy it.
Sure!  Easy enough, we just change it to move-item.

Plus I want to make sure that when it move the contents of the "Vaultbackup_2014_01_16_11_00_09_PM" folder, that it removes the empty parent folder altogether from it's original location.
Just to make sure I understand your statement here:

This should be similar to what you see now:
The folder/files exist in the SOURCE, but not in the DESTINATION
Before ScriptAfter you run the script, this is the outcome:
The folder/files now reside in the DESTINATION and are removed from the SOURCE
After Script
In short, the script is just automating the Cut/Paste functionally.

If all of the above is correct, then perform a test using the following:

Move-Item "D:\Vault Backup\Vaultbackup*" "E:\VaultLogix" -whatIf

Open in new window

"D:\Vault Backup\Vaultbackup*" - will look for any folder starting with "Vaultbackup..."

The whatIf will describe the command, without actually executing it.  Such as:
PS> Move-Item "D:\Vault Backup\Vaultbackup*" "E:\VaultLogix" -WhatIf
What if: Performing the operation "Move Directory" on target "Item: C:\Vault Backup\Vaultbackup_2014_01_16_11_00_09_PM Destination: A:\VaultLogix\Vaultbackup_2014_01_16_11_00_09_PM".

Open in new window

If you are NOT wanting the actual folder moved, and just want the files, then we need to modify this a bit.

Author Comment

ID: 39793429
We do need to modify it.
The initial backup that is run creates the folder called "Vaultbackup_2014_01_16_11_00_09_PM" -- inside of that folder are the files and subfolders that need to be moved to the destination location (vaultlogix folder)-- where it will then be backed up to the cloud.
THe cloud backup system requires that the source folder's name is not a variable or else it will think it is NEW data and back the whole thing up to the cloud again. Which is why we must not move the parent folder with the date/time stamp  (Vaultbackup_2014_01_16_11_00_09_PM).
So i guess I need to be able to do 2 things:
1. move the contents of the time stamped folder to a different location
2. remove the time stamped (empty) folder once the move is completed so that the "vault backup" folder is now empty. I have to do this because the first backup that occurs does not have the ability to overwrite anything in the folder, it would just create a new folder with a new time stamp and so we would have 2 folders with very similar name (except for the date and time stamp) which would confuse the move script...

Author Closing Comment

ID: 40030925
I ended up using Robocopy in multiple bat files to accomplish the task.

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Scenario:  You do full backups to a internal hard drive in either product (SBS or Server 2008).  All goes well for a very long time.  One day, backups begin to fail with a message that the disk is full.  Your disk contains many, many more backups th…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…

862 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

28 Experts available now in Live!

Get 1:1 Help Now