Page 1 of 1

easily backup your htdocs dir

PostPosted: 30. November 2009 10:25
by aveeshkumar
Hi,

To those who might want a date-based backup of the htdocs folder

- this will let you backup all files/folders from the root of htdocs incl subdirectories to a folder names Y-M-D
- exclude certain directories/files based on name or file extension
- create a log file called log - y-m-d


I had spent hours looking at free backup solutions for my localhost xampp windows installation and finally came up with the following:
1. After installing in c:\xampp, I created a directory caled c:\backup
2. In there I put in backup.bat which is:
----------------------
@echo off

FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
For /f "tokens=1-4 delims=/ " %%a in ('date /t') do (set dateymd=%%c-%%b-%%a)
echo %dateymd%

SET dir=%dateymd%\
SET logfile=backup-log-%dateymd%.txt
echo %dir%
echo %logfile%
rem md %dir%
xcopy ..\htdocs\*.* %dir% /s /EXCLUDE:backup-exclude.txt > %logfile%
------------------------------
NOTE:
1 - this assumes that the system date (DOS) is in d-m-Y format. If not, modify the set dateymd accordingly
2. credits for the above file go to several posts I found after googling (DOS batch file date...)
3. The xcopy command allows you to specify a file that lists what you want to exclude from xcopy. Mine contains:
-----------------------------
blog\
content\
dojo\
email\
files\
xampp\
.zip
.exe
---------------------------

Hope this helps someone - if there is a better solution, please be gentle in your replies. Thanks to Apachefriends for an easy to use great webserver....

If this is of help, please email me at aveeshkumar at gmail dot com to inspire me to post more often :-)