Just Code‎ > ‎

BATCH - Create a copy of a file with a date & time in the filename

posted Sep 22, 2011, 4:29 AM by Peter Henell   [ updated Jan 16, 2012, 2:14 PM ]
This is a handy snippet for creating backups of a file. The backup will get a date and time appended to its file name.
@echo off

@For /F "tokens=1,2,3 delims=/ " %%A in ('Date /t') do @( 
Set datum=%%C%%B%%A

@For /F "tokens=1,2,3 delims=: " %%A in ('Time /t') do @( 
Set mintid=%%A_%%B

copy ..\target\Target.sql ..\target\Target_backup_%datum%_%mintid%.sql"