Post-Backup Batch File to Rename Backup FIles

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jpfulton248
Posts: 3
Joined: 20 Nov 2018 07:28

Post-Backup Batch File to Rename Backup FIles

#1 Post by jpfulton248 » 20 Nov 2018 07:48

I currently have a batch file that runs each time a backup finishes. The software (Acronis) triggers the batch file to run as a Post-Command. The job of the batch file is to rename the backup file and add the current date/time timestamp. The directory that holds the backup files usually has about 7 total backup files in it. The batch file iterates through all files in the folder that start with the word "Archive" and end with the letters ".tib" (tib is the Acronis backup file extension). The files are then renamed to "Backup_[timestamp].tib". I need to improve error handling... if Acronis detects a post-command finished with an error then Acronis reflects an error on the backup task. So if for some reason there are no files that need to be renamed and the batch file returns "The system cannot find the file specified".

I want to change the batch file to first check if there are any renames needed if yes then it can run exactly as it does now, if no then exit. Don't know how to do that. Any help appreciated. Here's my current code. Thanks!

Code: Select all

@echo off
set hr=%time:~0,2%
if "%hr:~0,1%" equ " " set hr=0%hr:~1,1%
rename "Archive*.tib" Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%hr%%time:~3,2%%time:~6,2%.tib

aGerman
Expert
Posts: 3414
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Post-Backup Batch File to Rename Backup FIles

#2 Post by aGerman » 20 Nov 2018 11:10

Code: Select all

if exist "Archive*.tib" (
  REM rename ...
)
Note that you have to prepare your hr variable beforehand.

Steffen

Post Reply