Batch file for Autobackup

mjm6783

IT Wombat
Member
Local time
12:19 AM
Messages
66
Location
Portland, OR
I have a question regarding a batch file I've been working on to automate some of my daily tasks. I am copying a list of specific network database files from the server onto an external HD. Up until now I've just been manually Ctrl-clicking and dragging them over as a group. Not too difficult, but I thought it might be clever to handle it with an automated task.

I've figured out how to COPY the files from one location to another, but I'm running into problems when I try and create a dated folder to drop them into. I understand that the "mkdir" command will make a file, and I was reading about how to have that file's name be "ddmmyy". My question is how do I write one code which creates the dated folder (preferably with dashes mm-dd-yy) and then copies the files into that newly created folder.

Right now, my code has a static location to copy the files to. I need it to adapt to whatever the file name for that day is. I hope that makes sense.
 

My Computer My Computer

OS
XP Professional, 7 Professional
Code:
@ECHO OFF
 FOR /F "tokens=1-4 delims=/ " %%I IN ('DATE /t') DO SET mydate=%%J%%K%%L 
ECHO The value is "%mydate%"
will create a value that is %mydate% and will always contain the current date (the format you want but no dashes)
I don't know if this can be used in conjuction with the mkdir command in naming the folder though.

mkdir just doesn't have any switches or variables associated with it.
All it does is make directories.
This is actually one command linux has win beat on
 

My Computer My Computer

Computer Manufacturer/Model Number
Insane hobo technologies. ;-)
OS
Windows 7 x64
CPU
Intel i7 2600k
Motherboard
Asrock z68 extreme 4 gen 3
Memory
G.skill Ripjaw 16gigs @ 1866
Graphics Card(s)
Nvidia gtx580 (evga)
Sound Card
Integrated HD audio + hdmi
Monitor(s) Displays
24" ASUS widescreen + 42" insignia
Screen Resolution
1080p (1920x1080)
Hard Drives
128 Samsung 830
256 Samsung 840
3 x 1tb storage drive (various)
1 western digital 1tb (eSATA)
1 Seagate 1tb (eSATA)
PSU
1 kilowatt SLI/Crossfire rated Silverstone modular
Case
NZXT Phantom + additional 220 fan
Cooling
Zalmann
Keyboard
Microsoft wireless 3000 (v2)
Mouse
MS - wireless 5000 (bluetrack)
Internet Speed
depends on if you ask me or my provider.
Other Info
The above information is provided as is, and the author assumes no responsibility for issues it may cause with your sanity or fanboyism.
Huzzah!!

Even though your code wasn't exactly what I needed, it contained the missing puzzle piece. A light bulb went off in my head, and suddenly the world's simplest workaround was right in front of me. I use the "md" function to create a folder called "temp" then copy all the files to the static folder, then rename the folder to the current date using a function quite similar to yours. Here is the finished product, I've replaced all of the user specific information with descriptions in red parenthesis:

@echo off
md "(drive):\(path)\temp"
COPY "(drive):\(path)\(filename1.type)" "(drive):\(path)\temp"
COPY "(drive):\(path)\(filename2.type)" "(drive):\(path)\temp"
COPY "(drive):\(path)\(filename3.type)" "(drive):\(path)\temp"
COPY "(drive):\(path)\(filename4.type)" "(drive):\(path)\temp"
COPY "(drive):\(path)\(filename5.type)" "(drive):\(path)\temp"
COPY "(drive):\(path)\(filename6.type)" "(drive):\(path)\temp"
COPY "(drive):\(path)\(filename7.type)" "(drive):\(path)\temp"
for /f "tokens=1-4 delims=/ " %%d in ("%date%") do rename "(drive):\(path)\temp" %%e-%%f-%%g

Works like a charm, saves me time, and makes me look like a computer whiz to my boss. Thanks to Maguscreed and Win7 forums as always. Every time I've posted here I've had nothing but good experiences.
 

My Computer My Computer

OS
XP Professional, 7 Professional
Nice, I figured that would push you in the right direction.
Creative solution I was sitting there trying to figure out how to drop %mydate% info into mkdir.
...don't think it can be done that way at all though.
 

My Computer My Computer

Computer Manufacturer/Model Number
Insane hobo technologies. ;-)
OS
Windows 7 x64
CPU
Intel i7 2600k
Motherboard
Asrock z68 extreme 4 gen 3
Memory
G.skill Ripjaw 16gigs @ 1866
Graphics Card(s)
Nvidia gtx580 (evga)
Sound Card
Integrated HD audio + hdmi
Monitor(s) Displays
24" ASUS widescreen + 42" insignia
Screen Resolution
1080p (1920x1080)
Hard Drives
128 Samsung 830
256 Samsung 840
3 x 1tb storage drive (various)
1 western digital 1tb (eSATA)
1 Seagate 1tb (eSATA)
PSU
1 kilowatt SLI/Crossfire rated Silverstone modular
Case
NZXT Phantom + additional 220 fan
Cooling
Zalmann
Keyboard
Microsoft wireless 3000 (v2)
Mouse
MS - wireless 5000 (bluetrack)
Internet Speed
depends on if you ask me or my provider.
Other Info
The above information is provided as is, and the author assumes no responsibility for issues it may cause with your sanity or fanboyism.
You know I just had another thought about this.
You could set up a autoplay on the usb drive so it automatically copies whenever you plug in the back device.
 

My Computer My Computer

Computer Manufacturer/Model Number
Insane hobo technologies. ;-)
OS
Windows 7 x64
CPU
Intel i7 2600k
Motherboard
Asrock z68 extreme 4 gen 3
Memory
G.skill Ripjaw 16gigs @ 1866
Graphics Card(s)
Nvidia gtx580 (evga)
Sound Card
Integrated HD audio + hdmi
Monitor(s) Displays
24" ASUS widescreen + 42" insignia
Screen Resolution
1080p (1920x1080)
Hard Drives
128 Samsung 830
256 Samsung 840
3 x 1tb storage drive (various)
1 western digital 1tb (eSATA)
1 Seagate 1tb (eSATA)
PSU
1 kilowatt SLI/Crossfire rated Silverstone modular
Case
NZXT Phantom + additional 220 fan
Cooling
Zalmann
Keyboard
Microsoft wireless 3000 (v2)
Mouse
MS - wireless 5000 (bluetrack)
Internet Speed
depends on if you ask me or my provider.
Other Info
The above information is provided as is, and the author assumes no responsibility for issues it may cause with your sanity or fanboyism.
True, I never thought of that, I'll try it today.

**update**
Didn't have much time to mess with this, but my initial attempts were unsuccessful. I created an autorun.inf file and placed it in the external drive. I thought the code would be a piece of cake, ([autorun] open=*), but no matter how I try and format the text, I get no result. The autorun definitely boots when I turn on the external, but the batch file doesn't run. I tried using shellexecute instead of open, but to no avail.

I'm guessing it's because the .bat isn't an .exe. So maybe if I run a modified setup.exe, or some other intermediary program I'll have some more luck. Let me know what your take is, I'd be interested to know all my options before I troubleshoot further.

Is it wrong that I find this terribly interesting? LoL
 
Last edited:

My Computer My Computer

OS
XP Professional, 7 Professional
Hmmm.. a bunch of threads online are implying that autorun functions have been disabled for external drives. Not sure if I fully believe that or not. Can anyone confirm or deny?
 

My Computer My Computer

OS
XP Professional, 7 Professional
I don't seem to be able to run the batch file with an autoplay function, everywhere I look, people say that the code is super simple, and should look something like this:

[autorun]
open=filename.bat

or

[autorun]
open=filepath\filename.bat

I've also tried substituting "shell" and "shellexecute" for open. It's weird, because when I type the file path into "run" it works, and I thought the shellexecute function would work the same. When the autorun.inf file activiates, it pops up a flashlight and attempts to run something, but the batch never runs, and the files aren't copied.

This isn't a huge deal, because I can just keep a copy of the .bat on my desktop and double click it once I've plugged the drive in. But now I'm seriously curious as to what steps I've missed here. Any help would be greatly appreciated.
 

My Computer My Computer

OS
XP Professional, 7 Professional
try this way

Code:
[FONT=Arial][SIZE=2][COLOR=#008000][AutoRun]
OPEN=backup.bat[/COLOR]
[COLOR=#008000]ICON=MYAPP.EXE
ACTION=Run Backup Routine[/COLOR][/SIZE][/FONT]
just put any icon file on the usb root and change target to suit.
I think that's what it's looking for.
 

My Computer My Computer

Computer Manufacturer/Model Number
Insane hobo technologies. ;-)
OS
Windows 7 x64
CPU
Intel i7 2600k
Motherboard
Asrock z68 extreme 4 gen 3
Memory
G.skill Ripjaw 16gigs @ 1866
Graphics Card(s)
Nvidia gtx580 (evga)
Sound Card
Integrated HD audio + hdmi
Monitor(s) Displays
24" ASUS widescreen + 42" insignia
Screen Resolution
1080p (1920x1080)
Hard Drives
128 Samsung 830
256 Samsung 840
3 x 1tb storage drive (various)
1 western digital 1tb (eSATA)
1 Seagate 1tb (eSATA)
PSU
1 kilowatt SLI/Crossfire rated Silverstone modular
Case
NZXT Phantom + additional 220 fan
Cooling
Zalmann
Keyboard
Microsoft wireless 3000 (v2)
Mouse
MS - wireless 5000 (bluetrack)
Internet Speed
depends on if you ask me or my provider.
Other Info
The above information is provided as is, and the author assumes no responsibility for issues it may cause with your sanity or fanboyism.
Still not working

So, I've made some progress, but I'm still stumped. I'm starting to think that it has something to do with the drive itself. It's a Verbatim 500GB external desktop drive. It's formatted to NTSB. When I originally bought it, I had set it up to run as a multiboot drive, in order to run .ISO programs.

In order to bypass the potential conflict between autorun and .bat files, I even tried creating a self extracting .exe, using IExpress.exe. When I double click the .exe it runs the .bat with no issues. But a simple autorun function to run the .exe gives no significant response.

I tried your format, with both the .bat file, and the .exe file. It won't open with either. The autorun is functioning, because the icon I used replaced the default one. Also, it's searching the drive, (theoretically trying to find the file to open), but it never actually locates it. I'm checking the root path now, but to no avail. I feel like I'm missing a simple detail, but I've tried so many combinations, that it seems unlikely.
 

My Computer My Computer

OS
XP Professional, 7 Professional

My Computer My Computer

Computer Manufacturer/Model Number
Insane hobo technologies. ;-)
OS
Windows 7 x64
CPU
Intel i7 2600k
Motherboard
Asrock z68 extreme 4 gen 3
Memory
G.skill Ripjaw 16gigs @ 1866
Graphics Card(s)
Nvidia gtx580 (evga)
Sound Card
Integrated HD audio + hdmi
Monitor(s) Displays
24" ASUS widescreen + 42" insignia
Screen Resolution
1080p (1920x1080)
Hard Drives
128 Samsung 830
256 Samsung 840
3 x 1tb storage drive (various)
1 western digital 1tb (eSATA)
1 Seagate 1tb (eSATA)
PSU
1 kilowatt SLI/Crossfire rated Silverstone modular
Case
NZXT Phantom + additional 220 fan
Cooling
Zalmann
Keyboard
Microsoft wireless 3000 (v2)
Mouse
MS - wireless 5000 (bluetrack)
Internet Speed
depends on if you ask me or my provider.
Other Info
The above information is provided as is, and the author assumes no responsibility for issues it may cause with your sanity or fanboyism.
The power of the robocopy command is truly amazing. One might find some of the options there to be useful.
 

My Computer My Computer

Computer Manufacturer/Model Number
Toshiba Satellite S875D-S7239 laptop
OS
MS Windows 7 Ultimate SP1 64-bit
CPU
AMD A10-4600M
Motherboard
AMD Pumori (Socket FT1)
Memory
6.00 GB Dual-Channel DDR3 @ 798MHz (11-11-12-28)
Graphics Card(s)
AMD Radeon HD 7660G
Sound Card
High Definition Audio Device
Monitor(s) Displays
Generic PnP Monitor (1600x900@60Hz)
Screen Resolution
1600x900@60Hz
Hard Drives
SSD 119GB Corsair CSSD-V128GB2 ATA Device
Keyboard
Standard PS/2 Keyboard
Mouse
HP Wireless Optical Mobile Mouse Model FHA-3410
Internet Speed
What the local pub, local coffee shop offers.
Other Info
Optical Drive:MATSHITA BD-CMB UJ160B ATA Device


Also have an Asus ha1002xp netbook with Win 7 Ultimate installed.
Back
Top