Search : in
By :

Move files to ...\%date%\%time%\ fails

Last answer on Nov 8, 2009 4:55:43 pm GMT ghostcorps, on Nov 19, 2008 4:50:11 am GMT 
 Report this message to moderators

Hi Guys,


I have been trying to make a simple batch script to create database backups and move then into a folder named by date, and a sub folder by time.

This is what I have so far:

---
@echo off

@echo Backing Up Server1
mysqldump -A -Q -R -c -e --lock-tables=FALSE -uXXXX -pXXXX -hX.X.X.1 > c:\backup\01.sql

@echo Backing Up Server2
mysqldump -A -Q -R -c -e --lock-tables=FALSE -uXXXX -pXXXX -hX.X.X.2 > c:\backup\02.sql

@echo Backing Up Server3
mysqldump -A -Q -R -c -e --lock-tables=FALSE-uXXXX -pXXXX -hX.X.X.3 > c:\backup\03.sql

set folderdate=%date:~7,2%-%date:~4,2%-%date:~10,4%
mkdir c:\backup\%folderdate%
set foldertime=%time:~0,2%-%time:~3,2%
mkdir c:\backup\%folderdate%\%foldertime%
move c:\backup\*.sql c:\backup\%folderdate%\%foldertime%\
---

I have this scheduled to run every 12hours from 8PM. However, while the batch that runs at 8PM is successful, the 8AM files remain unmoved. In fact in the AM, the 'foldertime' folder is created outside the 'folderdate' folder and sites next to the files that have been created but not moved.

And yet, at 8Pm everything works like a charm. Presumably this has to do with using 24hour time, as the folders are names in 24hr, while XP uses AM/PM in the 'modified' column. I do not see any logic that would cause this to happen the way it does, but I hope someone can point me in the right direction.


thanks

=^_^=

Configuration: Windows XP
Firefox 3.0.4

Best answers for « Move files to ...\%date%\%time%\ fails » in :
Batch Script - Move files to \%date%\%time%\ Show Batch Script - Move files to \%date%\%time%\ Issue Solution Note Issue I have been trying to make a simple batch script to create database backups and move then into a folder named by date, and a sub folder by time. This is what I...
Using .MOV file ON Windows Movie Maker ShowUsing .MOV file ON Windows Movie Maker Solution Windows Movie Maker does not recognize my .MOV files Solution Windows Movie Maker natively does not recognize MOV files The solution is to convert ( MOV files into AVI files....
How to read a .DAA file ShowHow to open a .DAA file DAA is the acronym for Direct Access Archive and is used mainly for data compression and file splitting. Like .bin/.cue files, the .daa extension is an archive file format that can be used to divide a movie file into...
Saving file MSWMM under other format ShowSaving file MSWMM under other format How to save under format Windows Movie Maker How to save your file under audio or video format? Windows Movie maker is a software for creating and editing video under Microsoft windows...
Download Titlebar Date-Time ShowTitlebar Date-Time is a tool to customize the display. It is possible to change the color of the background or the text, to modify the item order by simple drag-and-drop operation. For instance, here are some additional options to customize the...
PNG format ShowPNG format The PNG format (Portable Network Graphics or Ping format) is a bitmap (raster) graphic file format. It was developed in 1995 in order to provide a free alternative to the GIF format, which is a proprietary format whose rights are held by...

1

eicher1, on Nov 19, 2008 10:31:18 am GMT
  • +1

And so what you are willing to do is to put the am file in the folderdate thats it?

Reply to eicher1

2

ghostcorps, on Nov 19, 2008 8:41:52 pm GMT
  • +3

I need the file to go to %foldertime% so that the structure is as follows:

c:\backup\todaysdate\8am\files.sql
c:\backup\todaysdate\8PM\files.sql
c:\backup\yesterdaysdate\8AM\files.sqk
c:\backup\yesterdaysdate\8PM\files.sql

etc etc

Reply to ghostcorps

3

abdullah, on Mar 9, 2009 4:54:55 pm GMT

Call me on my mobile number will provide you the complete solution
Thanks,Regards
Abdullah
Senior Software Eng
9822098433

Reply to abdullah

7

jon, on Oct 12, 2009 9:23:34 pm BST

I need to identify the latest backup file amoung several other files in the backup folder. All have the same extension of .NPS. The file name is generated by the application. Several times a day the staff makes backups of the data. I only need the most current version of the backup file. This is identified only by the time of the creation of the file. In a batch file, I need to extract/identify the file to copy to another folder located on another server.

Will you please give me the code to accomplish this?

J

Reply to jon

4

Rob, on Mar 10, 2009 8:05:02 am GMT
  • +2

Insertthe following lines in your batch file:

set DD=%DATE:~0,2%
set MM=%DATE:~3,2%
set YY=%DATE:~8,2%
set YYYY=%DATE:~6,4%
set HH=%TIME:~0,2%
set MN=%TIME:~3,2%

You can now string them together in any format you want to create a dated folder name, eg,

set FOLDER=%YYYY%-%MM%-%DD%

echo %FOLDER% will now give you 2009-03-10

I recommend you use this reverse date format as it sorts better.

Alll the best.

ROB

Reply to Rob

5

email2kale, on May 19, 2009 9:05:19 pm BST

Hi Rob,

Thanks for your posting...

I have put in what you have said here... but I'm having problem in removing space which is coming after year...

following is the code the i'm using...

@ECHO OFF
CLS
SET DD=%DATE:~7,2%
SET MM=%DATE:~4,2%
SET YYYY=%DATE:~10,4%
SET HH=%TIME:~0,2%
SET MN=%TIME:~3,2%
SET SS=%TIME:~6,2%

SET FOLDER="%YYYY%-%MM%-%DD%"

mkdir C:\Test\%FOLDER%

So, the folder creates with "2009 -05-19".. you see that there is space between 2009 and -05. Please advice on how to remove this. Thanks in advance.

Kale.

Reply to email2kale

6

jk, on Oct 1, 2009 6:21:57 pm BST
  • +1

Remove the space at the end of the line SET YYYY=%DATE:~10,4%

Reply to jk

8

Richard.Williams, on Nov 8, 2009 4:54:50 pm GMT
  • +1

Here is a script in.


# Script MySQLBackup.txt
# Get data and time
var str datetime, date, time
set $datetime = gettime() 
# Separate date and time
set $date = { chex -p "8]" $datetime }
set $time = { chex -p "8[" $datetime }

# Make folders for date and time
system mkdir ("c:/backup/"+$date) 
system mkdir ("c:/backup/"+$date+"/"+$time)

# Create the backups.
echo "Backing Up Server1 "
system "mysqldump -A -Q -R -c -e --lock-tables=FALSE -uXXXX -pXXXX -hX.X.X.1 > c:/backup/"+$date+"/"+$time+"/01.sql "

echo "Backing Up Server2 "
system "mysqldump -A -Q -R -c -e --lock-tables=FALSE -uXXXX -pXXXX -hX.X.X.2 > c:/backup/"+$date+"/"+$time+"/02.sql "

echo "Backing Up Server3 "
system "mysqldump -A -Q -R -c -e --lock-tables=FALSE -uXXXX -pXXXX -hX.X.X.3 > c:/backup/"+$date+"/"+$time+"/03.sql "

Reply to Richard.Williams

9

 Richard.Williams, on Nov 8, 2009 4:55:43 pm GMT

Forgot to mention - above script is in biterscripting.

Reply to Richard.Williams