Powershell script to move backup files

  • Hi,

    I am trying to create a job using power-shell script to move the backup files from one folder to another. I am using Ola Hallengren script for backups. Ola hallengren created a common backup folder with sub-folders for databases and even more sub folders for Full and Log backups. My goal is to move full backups, which are older than a month and save them in a different drive along with the same folder structure. I was able to move the first set of backups without any problem, but I can't move anymore files and keep getting this error even when I try to overwrite the previous file with the force statement:

    Move-Item : Cannot create a file when that file already exists.

    At line:5 char:9

    + Move-Item $i.FullName C:\Test -force

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo : WriteError: (C:\Backup\VALIDATIONgcommon:DirectoryInfo) [Move-Item], I

    + FullyQualifiedErrorId : MoveDirectoryItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand

    Here's the script that I used to move the first set of files:

    foreach ($i in Get-ChildItem C:\Backup\VALIDATION)

    {

    if ($i.CreationTime -lt ($(Get-Date).AddMonths(-1)))

    {

    Move-Item $i.FullName C:\Test

    }

    }

    It would be nice if someone can help me out with the rest of the script.

    By the way,

    Move-Item ............... -force didn't work.

    I recently started working as a DBA, and I am finding it very hard. I could really use your help.

    Thank you

Viewing post 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply