Solved

Getting started with Robocopy

Posted on 2012-03-25
6
571 Views
Last Modified: 2014-11-12
a friend recomended robocopy, i wish to get started, but have no idea how.

i am using server 2008 r2
i want to copy a folder called c:\gdrive  to my f drive
i woul dlike robocopy to make a new folder on my f drive, rather then over write it.
my ideal situation would be to have a new folder corresponding to the day of the month the copies were made.
it is fine with me, if it makes one copy, then subsequent are only the changed files... but i do  have a small amount of data and a large destination drive.

is anyone familiar....with how i would begin.?
0
Comment
Question by:intelogent
[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
6 Comments
 
LVL 2

Expert Comment

by:ven16
ID: 37762572
may the below link helps you to do it, it use the powershell script.
and let me know the result
http://itnshare.blogspot.co.uk/2009/10/autorotate-and-renaming-files-as-for_14.html
0
 
LVL 30

Expert Comment

by:IanTh
ID: 37762586
best link for robocopy is
http://ss64.com/nt/robocopy.html

it has all th command options
0
 
LVL 6

Expert Comment

by:Tomislavj
ID: 37762590
maybe free cobian backup 8 is easier to use for this purpose because there's no need for scripts, just choose options (and there is option for have daily backups as different names)
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 8

Expert Comment

by:Brent Challis
ID: 37769618
I have a PowerShell function that I use for backing up files.  It creates a command line for running RoboCopy after reading a configuration file which is a csv file listing the sourcedirectory,targetdirectory


# ==============================================================================================
#
# NAME: Backup-RCopy
#             PowerShell utility which utilises RoboCopy to perform the copying of the directory
#            structure copying the files that are new or altered.
# AUTHOR: bchallis ,
# DATE  : 26/01/2012
#
# COMMENT:
#
# ==============================================================================================
function Backup-RCopy
{
    [CmdletBinding(SupportsShouldProcess=$True)]
    Param
    (
        [Parameter(Mandatory=$True)]
        [string]$ConfigurationFileName,
        [Parameter(Mandatory=$True)]
        [string]$LogFileName,
        [switch]$Force
    )

    function Log
    {
        Param
        (
            [parameter(Mandatory=$true)]
            [int]$Level,
            [parameter(Mandatory=$true)]
            [String]$TaskCategory,
            [parameter(Mandatory=$true)]
            [String]$Message
        )
        if (Test-Path Function:\Add-BCLogEntry)
        {
            Add-BCLogEntry -Path $LogFileName -Level $Level -Source "BackupRCopy" -taskCategory $TaskCategory -message $Message
        }
          else
        {
              ("[{0}] {1}" -f ([System.DateTime].Now.ToString()),$Message) | Out-File -FilePath $LogFileName -Append
        }
    }
   
    function IsNull
    {
          Param
          (
                $value,
                $default
          )
          $retValue = $value
          if ($value -eq $null)
          {
                $retValue = $default
          }
          else
          {
                if ([String].IsNullOrEmpty($value))
                {
                      $retValue = $default
                }
          }
          return $retValue
    }
   
    function Display-Configuration
    {
          $configurations = Import-Csv $ConfigurationFileName
            foreach ($config in $configurations)
            {
            $sourceDirectory = $config.SourceDirectory.Trim()
            if (-not $sourceDirectory.EndsWith("\"))
            {
                $sourceDirectory += "\"
            }
            $targetDirectory = $config.DestinationDirectory.Trim()
            if (-not $targetDirectory.EndsWith("\"))
            {
                $targetDirectory += "\"
            }
            Write-Host      "Source directory = $sourceDirectory - Target directory = $targetDirectory."
            }
    }

#############################################################################################################
# Main Code
#############################################################################################################

      $errorsFound = $false
      if (Test-Path $ConfigurationFileName)
      {
          Write-Verbose "Using configuration file $ConfigurationFileName"
            $configurations = Import-Csv $ConfigurationFileName
            foreach ($config in $configurations)
            {
                  if ($config -ne $null)
                  {
                        $sourceDirectory = $config.SourceDirectory
                        $targetDirectory = $config.DestinationDirectory
                        if (($sourceDirectory -ne $null) -and ($targetDirectory -ne $null))
                        {
                              if ($PSCmdlet.ShouldProcess((Get-Item env:\ComputerName).Value, ("Backing up {0} up to {1}" -f $sourceDirectory,$targetDirectory)))
                              {
                              if (-not $sourceDirectory.EndsWith("\"))
                              {
                                  $sourceDirectory += "\"
                              }
                              if (-not $targetDirectory.EndsWith("\"))
                              {
                                  $targetDirectory += "\"
                              }
                              
                              if (-not (Test-Path $targetDirectory))
                              {
                                  if ((Test-Path (Split-Path $targetDirectory -Qualifier)) -and $Force)
                                  {
                                      New-Item $targetDirectory -type directory
                                  }
                              }
                              
                                    if ((Test-Path $sourceDirectory) -and (Test-Path $targetDirectory))
                                    {
                                  $command = "RoboCopy " + $sourceDirectory + " " + $targetDirectory + " /E /Z /XO /COPY:DAT"
                                  
                                      try
                                      {
                                          Write-Verbose "Command: $command"
                                                    $procres = Invoke-Expression $command
                                          if ($verbosePreference)
                                          {
                                              foreach ($o in $procres)
                                              {
                                                  Write-Host $o.ToString()
                                              }
                                          }
                                      }
                                      Catch
                                      {
                                          $errorsFound =$true
                                      }
                                    }
                                    else
                                    {
                                  $message = ("Unable to locate source ($sourceDirectory) and destination ($targetDirectory) directories.")
                                  Log -Message $message -Level 2 -TaskCategor y "Backing up files"
                                  $errorsFound =$true
                                          Write-Warning $message
                                    }
                              }
                              else
                              {
                                    # Selected to not perform action
                              }
                        }
                  }
            }
                Add-BCLogEntry -Path $LogFileName -Level 0 -Source "rBackup" -TaskCategory "SuccessfulBackup" -Message "Backup Complete"
      }
      else
      {
            $errorsFound =$true
            Log -Level 3 -TaskCategory "Initialisation" -Message "configuration File not found."
            Write-Warning "Unable to find configuration file $ConfiguratinFileName"
      }
}
0
 
LVL 8

Expert Comment

by:SeaSenor
ID: 37777088
Intelogent... here is the .bat file I think you were wanting from me.

it is attached
Here are the steps:

1. rename the extension from .txt to .bat

2. I have the source name as:    C:\gdrive
3. I have the destination name as :   F:\gdrive

4. create your 'folderlist' to include the folders you want to copy.  Name it:  folderlist.txt  and place it in the same diretory you put this .bat file ( i use just the C:\  folder)
5. Create a folder named Robocopylogfiles on the F:\   drive.

This script will create a folder with the current date, and copy any new/changed files only.
The first round it will probably copy everything... which is good.

It will also create a log file and it will then put a copy of that days log file into the folder of the day it was created.

This should accomplish what you are asking in your post.

Let me know if you need more help.
Daily-incremental.txt
0
 
LVL 8

Accepted Solution

by:
SeaSenor earned 500 total points
ID: 37814914
Did that provide what you needed?
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Working with spreadsheets can be a daunting task, especially when having to deal with large amounts of data. All you see are rows and rows of numbers and soon your eyes begin to glaze over. Take advantage of the tools in Google Sheets to create prof…
This article explains how to install and use the NTBackup utility that comes with Windows Server.
This Micro Tutorial will demonstrate how marketers can use the Mobile Emulation Tool in Chrome Developer Tool. This will let you preview your site on any mobile device.
This Micro Tutorial will demonstrate common damaging and frequent mistakes I see in most analytic audits. Most of them are campaign tagging mistakes, so this video will break it down into simple steps.

733 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