PowerShell script for incremental backup

Hi teams.

I have some critical data on our server, I would like to copy it to another storage.
I want to create a powershell secript for this task and schedule it in the task manager on the windows server.
I want to schedule the copying of data to a backup storage every week, and keep 3 latest versions, i.e.

  1. first week copy the data o the backup storage.
  2. the second week copy the data to the backup storage without deleting the backup of the first week.
  3. Third week copy the data to the backup storage without deleting the backup of the first and second week.
    4)fourth week copy the data to the backup storage with deleting the backup of the first week and keeping the backups of the second and third and fourth weeks.
  4. fifth week copy the data into the backup storage with deleting the backup from the second week and keep the backups from the third and fourth week.

please help
thanks in advance

Hi,
My advice :

  • Use robocopy to do this, launching by powershell
    the syntax is robocopy source target arguments

  • In you case, the target will be changed each time, depending of the week. To do this, just use the folowwing in a var (for later use)
    $Week = (Get-CimInstance -ClassName WIN32_LocalTime).WeekInMonth, this return the week in month.
    Then you can build the target path : $TargetPath = $RootBackupPath$Week

  • For the robocopy Arguments, choose copy type Mirror.

Build a script, and if you have an issue, show your code, and someone could help you. It’s your job, and you’re paid for that.
It’s a bit easy to say, « I want this, I want that, » without doing anything at all.

Regards.