Reputation: 25
I am trying to write a bat file to backup a folder on my work server (sometimes the server and backup server do not sync correctly and files go missing).
I have tried many different solutions and read a few different forums to try to resolve this, but I cannot seem to find anything.
@echo This will now create a new backup of S:\Internal Auditor\9 - September 14
@echo off
:: variables
set SRCFOLDER="S:\Internal Auditor\9 - September 14"
set DESTFOLDER="S:\Internal Auditor\2014\9 - Sept Backup"
set folder=%date:~5,2%-%date:~8,2%-%date:~0,4%
set backupcmd=xcopy /W /E /H /V /C /Z /I /F /J /R /Y
echo ######## PLEASE WAIT SYSTEM BACKINGUP SOME DATA########
xcopy %SRCFOLDER% %DESTFOLDER% %backupcmd%
echo !!!!!!!!BACKUP COMPLETED THANKS!!!!!!!!!!!!!!
@pause
Please help - I'm tired of losing files, and I don't want to have to manually backup files every day.
(The goal is the create a new folder with date & time every time it runs under the sub-folder "9 - September 14"{historical backup}).
EDIT Ok - So I have another thread open for something that was different, but now my 2 questions have kinda merged together, so please look @ New folder for every backup CMD and see if you could help...
Upvotes: 1
Views: 1512
Reputation: 29
After you enter the required source and destination path try this code..
set xcopy=xcopy //switches as per your requirement
set Folder=%Date:~-7,2%-%Date:~-10,2%-%Date:~-4,4%
mkdir %DESTPATH%\%Folder%
pause
%xcopy% %SOURCEPATH% %DESTPATH%\%Folder%
pause
Upvotes: 0
Reputation: 57252
use set backupcmd=/W /E /H /V /C /Z /I /F /J /R /Y
instead of set backupcmd=xcopy /W /E /H /V /C /Z /I /F /J /R /Y
. You have redundant xcopy in parameters.
EDIT. As far as I understood your comments you need a new folder like this "S:\Internal Auditor\%date:~5,2%-%date:~8,2%-%date:~0,4%"
so you can do this:
set SRCFOLDER="S:\Internal Auditor"
set "DESTFOLDER="S:\Internal Auditor\2014"
set "folder=%date:~5,2%-%date:~8,2%-%date:~0,4%"
md "%DESTFOLDER%\%folder%" >nul 2>&1
set "backupcmd=/W /E /H /V /C /Z /I /F /J /R /Y"
echo ######## PLEASE WAIT SYSTEM BACKINGUP SOME DATA########
xcopy "%SRCFOLDER%\%folder%" "%DESTFOLDER%\%folder%" %backupcmd%
echo !!!!!!!!BACKUP COMPLETED THANKS!!!!!!!!!!!!!!
Upvotes: 1