The following batch script below, copies a folder to a folder. The folder is created with a name according to date that the script is run. The script will output a log file of the operation - files which were copied will be logged.

This script is intended only for WINDOWS machines. (XP and above)

Step 1

Click on Start > Run.

Enter cmd and press the enter key

Step 2

In the black window that opened write:

# EDIT BACKUP.BAT

The backup.bat is the name of the file that we created .

Step 3

In the blue screen that we just opened copy and paste the following (each line without the # mark):

# FOR /F "TOKENS=1* DELIMS= " %%A IN ('date/T') DO SET CDATE=%%B
# FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('date/T') DO SET mm=%%B
# FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET dd=%%B
# FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B
# SET date=%dd%-%mm%-%yyyy%
# md C:\%date%
# copy "c:\folder_name\*.*" c:\%date%>>c:\LogFile.txt
echo %date% %time%>>c:\LogFile.txt

Let's explain the code above:

EXPLANATION 1

# FOR /F "TOKENS=1* DELIMS= " %%A IN ('date/T') DO SET CDATE=%%B
# FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('date/T') DO SET mm=%%B
# FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET dd=%%B
# FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B
# SET date=%dd%-%mm%-%yyyy%
# md c:\%date%

All of this sequence is actually a command to open a library if
the correct date for the day .

EXPLANATION 2

# copy "c:\folder_name\*.*" c:\%date%

This is the command that copy the files in to the date folder (the backup folder).

EXPLANATION 2-A

folder_name is the folder that you want to copy from him

%date% is the folder with the correct day to copy the files that we want to backup .

EXPLANATION 3

# >>c:\logFile.txt
# echo %date% %time%>>c:\LogFile.txt

This is a LOG file that contain the names of all the files that we copy and also the time and date that the backup was runs.

I wrote this script for a friend of mine for backup of folders in his father's business.

Kobi

Viewed 6648 times.
Share |
How to migrate from o... (Daniel, 16:52 06/04/2013)
How to redirect SNMP ... (Daniel, 18:32 24/08/2012)
How to add httpd.conf... (Daniel, 19:20 24/03/2012)
How to avoid entering... (Daniel, 03:11 27/12/2011)
How to configure SOFT... (Daniel, 23:24 26/12/2011)
Subversion - Tortoise... (21:02 17/01/2010, 119668 views)
How to install Nagios... (01:08 23/12/2011, 45660 views)
Byte Order Mark (BOM)... (17:36 22/02/2010, 28714 views)
How to avoid entering... (03:11 27/12/2011, 27772 views)
Raid Types (17:54 09/02/2010, 21168 views)