• 0

Batching: Reading and writing files


Question

Hi, I have some questions regarding Windows XP batch files. I have a batch file that backs up all my data to another drive (J)

1. I would like it to record the time and date that the batch starts to backup and time and date that the backup completes.

I was thinking that to get it to write STARTED: date and time and then FINISHED: date and time to a log file and then display this data at the end of the backup in the command window like Backup Started: Date/Time and Finished: Date/Time. Can this be achieved? How.

At this moment I could only know about showing Date and Time when it was finished by using the Date and Time commands.

2. I have scheduled this backup file to run at 8pm on Fridays while I am out at the pub. When I come back, I see it shows the date and time and that is the time it started, 8:00:00 pm. I check the backed up files and they are the old data so it hasn't been backed up. When I manually run the file, the backup runs as supposedly. Why is this?

I am trying to automate backups of my Documents and my program settings. See attached file to see what I mean. :)

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

1. %DATE% and %TIME% will give you the date and time. You can set a variable with the current date using: set currdate = %DATE%

You can output to a file using > Ouputfile and >> Outputfile. > will overwrite and >> appends.

2. I'm not sure. Take @echo off out and see if there's errors.

Link to comment
Share on other sites

  • 0

how's this?

cls
@ECHO OFF
TITLE Weekly Backup Procedure
set starttime=%date% %time%
ECHO.
ECHO Backing up your current My Documents...
xcopy "%documents%" "J:\Jason\My Documents\" /e /q
cls
ECHO.
ECHO Backing up your current My Pictures folder...
xcopy "%pictures%" "J:\Jason\My Documents\My Pictures\" /e /q
cls
ECHO.
ECHO Backing up your current My Videos folder...
xcopy "%videos%" "J:\Jason\My Documents\My Videos\" /e /q
cls
ECHO.
ECHO Backing up your current My Music folder...
xcopy "%music%" "J:\Jason\My Documents\My Music\" /e /q
cls
ECHO.
ECHO Backing up your Internet Favourites folder...
xcopy "%userprofile%\Favorites\" /q /e
cls
ECHO.
ECHO Backing up your Mozilla Firefox data files...
xcopy "%userprofile%\Application Data\Mozilla\Firefox" "J:\Jason\Application Data\Mozilla\Firefox\" /e /q /H /y
ECHO.
ECHO Backing up your Mozilla Thunderbird data files...
xcopy "%userprofile%\Application Data\Thunderbird" "J:\Jason\Application Data\Thunderbird\" /e /q /H /y
cls
ECHO.
ECHO Awaiting user input. Press a key...
pause > nul
cls
ECHO.
ECHO Backup started: %starttime%
ECHO.
ECHO Backup completed: %date% %time%
ECHO.
ECHO Press any key to close Backup.
@pause
exit

note: %documents%, %pictures%, %videos%, and %music% are not variables unless you have set them in the Environmental Variables section of the System Control Panel...alternatively, you can set them for just this batch session like so:

set documents="C:\My Documents"

and then whenever %documents% is referred to, you get whatever you set it to. that will need to be done before any references to any of the 'invalid' variables are called.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.