Computing.Net > Forums > Programming > Backup using xcopy - date in folder

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Backup using xcopy - date in folder

Reply to Message Icon

Name: rhawkes241
Date: July 19, 2008 at 01:35:31 Pacific
OS: WinXP
CPU/Ram: Core2/1024gb
Comment:

Hi there
I use XCOPY to backup all files from my computer to an external hard disk. Currently, it is always to the same folder (X:\backup) with only newer files being updated.

I would like to improve my backups by creating a new backup folder for each date I run the backup batch file - e.g. X:\10-07-08-backup or something similar, and then dump a complete copy of everything I backup using xcopy (c:\documents and settings) into the folder with that date.

How? Thanks!



Sponsored Link
Ads by Google

Response Number 1
Name: ryanoasis
Date: July 20, 2008 at 22:38:20 Pacific
Reply:

Something like this?

@echo off
set month=%date:~4,2%
set day=%date:~7,2%
set year=%date:~10,4%
set dir="C:\Documents and Settings\SomeUser\stuff"
echo %year%
xcopy %dir%\*.* %month%-%day%-%year%-backup\ /q


0

Response Number 2
Name: Mechanix2Go
Date: July 21, 2008 at 00:45:26 Pacific
Reply:

@echo off
setLocal EnableDelayedExpansion

call :YMD8 && cls

echo xcopy /s "c:\documents and settings" x:\%dat%-%month%-%year%\

goto :eof

::====== YMD8 ==========

:YMD8

@echo off > d.d

>> d.d echo E 0100 B4 2A CD 21 B4 4C CD 21
>> d.d echo N DAY.COM
>> d.d echo RCX
>> d.d echo 8
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 88 F0 B4 4C CD 21
>> d.d echo N MONTH.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 89 C8 B4 4C CD 21
>> d.d echo N YEAR.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 88 D0 B4 4C CD 21
>> d.d echo N DAT.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo Q

debug < d.d > nul
del d.d

dat
for %%a in (1 2 3 4 5 6 7 8 9 ) do if errorlevel %%a set dat=0%%a
for %%a in ( 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) do if errorlevel %%a set dat=%%a
echo Date %dat%

day
if errorlevel 0 set day=Sunday
if errorlevel 1 set day=Monday
if errorlevel 2 set day=Tuesday
if errorlevel 3 set day=Wednesday
if errorlevel 4 set day=Thursday
if errorlevel 5 set day=Friday
if errorlevel 6 set day=Saturday
echo Day %day%

month
for %%a in (1 2 3 4 5 6 7 8 9 ) do if errorlevel %%a set month=0%%a
for %%a in ( 10 11 12) do if errorlevel %%a set month=%%a
echo Month %month%

year
if errorlevel 215 set Year=2007
if errorlevel 216 set Year=2008
if errorlevel 217 set Year=2009
if errorlevel 218 set Year=2010
echo Year %Year%

del day.com
del month.com
del year.com
del dat.com
::== DONE


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 3
Name: Pagey
Date: July 21, 2008 at 05:17:19 Pacific
Reply:

Hi,

unfortunately using the %date% command as the variable on most O/S's using '/' (forward slashes) which aren't a valid folder name. So I would reccomend that before you run the XCOPY command, you create a folder like below...

mkdir %date:~0,2%-%date:~3,2%-%date:~7,4%

It looks a bit complicated, but it's basically filtering the output from the %date% system variable. For example, If i do Echo %date% on my system, the output is 21/07/2008 so the first part %date:~0,2% Is the %date% variable but only the 1st and second number (0 = first number, and I want the first 2 numbers, hence the ,2)

So your script would look similar to this

@echo off
Echo Backing up Files!!!
mkdir %date:~0,2%-%date:~3,2%-%date:~7,4%
XCOPY C:\Files to Backup USB:\%date:~0,2%-%date:~3,2%-%date:~7,4%

It doesn't matter what date you run it on, the files will go into a folder for the current date. :)


0

Response Number 4
Name: Mechanix2Go
Date: July 21, 2008 at 05:36:13 Pacific
Reply:

That will work if you have guessed the date layout correctly.

That's why I get the date from BIOS.


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 5
Name: ryanoasis
Date: July 21, 2008 at 17:18:02 Pacific
Reply:

Pagey.

Did you read my post?

I don't get the point of basically duplicating answers.


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Backup using xcopy - date in folder

Using xcopy /exclude with folders? www.computing.net/answers/programming/using-xcopy-exclude-with-folders/12991.html

use creation date in renaming file www.computing.net/answers/programming/use-creation-date-in-renaming-file/15094.html

Retain folders' dates in treecopy www.computing.net/answers/programming/retain-folders-dates-in-treecopy/16159.html