Perpetual Backup Batch File Script

IT Support Forum Forums Backup and Restore General Discussion Perpetual Backup Batch File Script

Viewing 1 reply thread
  • Author
    • #1969

      Here’s my batch file script to perpetually backup some files to a drive, deleting the files older than a day.

      forfiles /p “G:” /s /m *.* /c “cmd /c Del @path” /d -1
      set folder=Date_%date:~10,4%_%date:~7,2%_%date:~4,2%_Time_%time:~0,2%_%time:~3,2%_%time:~6,2%_%time:~9,2%
      mkdir G:\%folder%
      robocopy C:\folder G:\%folder% /XO
      Timeout 1
      GoTo Start

      The script does each backup to a new folder, so you can recover files from any time of the day. If you want to perpetually backup the files to only have one copy, you can just use the following batch file script:

      robocopy C:\folder G:\%folder% /XO

    • #1972

      Perpetual Backup PowerShell Script

      Ok, so the batch file doesn’t work as well as a PowerShell script because the command forfiles doesn’t work well. A better script is the following PowerShell script, which you can save as a ps1 file and run it the same as a batch file (perpetually).

      Here’s the PowerShell version of my perpetual backup batch file script:

      while ($true){
      Get-ChildItem –Path “G:\” –Recurse | Where-Object CreationTime –lt (Get-Date).AddDays(-1) | Remove-Item
      mkdir G:\$folder
      Copy-Item C:\ G:\$folder
      Timeout 60

Viewing 1 reply thread
  • You must be logged in to reply to this topic.