Writing a batch file to do this .... |
![]() |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
Forum Member
Join Date: Dec 2009
Posts: 2,990
|
Writing a batch file to do this ....
Picture this:
folder c:\stuff and 2 external hard drives f: and g: I want to back up the c:\stuff folder onto both f: and g: drives. Is it possible to write a batch file that does: (1) copy c:\stuff to f:\ (2) copy c:\stuff to g:\ (3) shut down computer. I'm using Windows XP and there won't already be a stuff folder existing on either f: or g: drives. And there will be ample room on both drives to take the new stuff folder. |
|
|
|
|
Please sign in or register to remove this advertisement.
|
|
|
#2 | |
|
Forum Member
Join Date: Jul 2003
Posts: 1,235
|
Quote:
Code:
xcopy c:\stuff f:\ /s /i xcopy c:\stuff g:\ /s /i shutdown /s |
|
|
|
|
|
|
#3 |
|
Forum Member
Join Date: Feb 2011
Posts: 2,657
|
Code:
xcopy /s c:\stuff f:\stuff xcopy /s c:\stuff g:\stuff shutdown /s /f /t 01 |
|
|
|
|
|
#4 |
|
Forum Member
Join Date: Jan 2003
Location: london
Services: N8-00 vod, Nexus7, O2 BB 8meg, humax PVR, W7-64 - Minecraft FTW
Posts: 31,160
|
robocopy might be better. introduced from vista onwards.
Code:
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Fri Jun 22 14:21:56 2012
Usage :: ROBOCOPY source destination [file [file]...] [options]
source :: Source Directory (drive:\path or \\server\share\path).
destination :: Destination Dir (drive:\path or \\server\share\path).
file :: File(s) to copy (names/wildcards: default is "*.*").
::
:: Copy options :
::
/S :: copy Subdirectories, but not empty ones.
/E :: copy subdirectories, including Empty ones.
/LEV:n :: only copy the top n LEVels of the source directory tree.
/Z :: copy files in restartable mode.
/B :: copy files in Backup mode.
/ZB :: use restartable mode; if access denied use Backup mode.
/EFSRAW :: copy all encrypted files in EFS RAW mode.
/COPY:copyflag[s] :: what to COPY for files (default is /COPY:DAT).
(copyflags : D=Data, A=Attributes, T=Timestamps).
(S=Security=NTFS ACLs, O=Owner info, U=aUditing info).
/DCOPY:T :: COPY Directory Timestamps.
/SEC :: copy files with SECurity (equivalent to /COPY:DATS).
/COPYALL :: COPY ALL file info (equivalent to /COPY:DATSOU).
/NOCOPY :: COPY NO file info (useful with /PURGE).
/SECFIX :: FIX file SECurity on all files, even skipped files.
/TIMFIX :: FIX file TIMes on all files, even skipped files.
/PURGE :: delete dest files/dirs that no longer exist in source.
/MIR :: MIRror a directory tree (equivalent to /E plus /PURGE).
/MOV :: MOVe files (delete from source after copying).
/MOVE :: MOVE files AND dirs (delete from source after copying).
/A+:[RASHCNET] :: add the given Attributes to copied files.
/A-:[RASHCNET] :: remove the given Attributes from copied files.
/CREATE :: CREATE directory tree and zero-length files only.
/FAT :: create destination files using 8.3 FAT file names only.
/256 :: turn off very long path (> 256 characters) support.
/MON:n :: MONitor source; run again when more than n changes seen.
/MOT:m :: MOnitor source; run again in m minutes Time, if changed.
/RH:hhmm-hhmm :: Run Hours - times when new copies may be started.
/PF :: check run hours on a Per File (not per pass) basis.
/IPG:n :: Inter-Packet Gap (ms), to free bandwidth on slow lines.
/SL :: copy symbolic links versus the target.
/MT[:n] :: Do multi-threaded copies with n threads (default 8).
n must be at least 1 and not greater than 128.
This option is incompatible with the /IPG and /EFSRAW options.
Redirect output using /LOG option for better performance.
::
:: File Selection Options :
::
/A :: copy only files with the Archive attribute set.
/M :: copy only files with the Archive attribute and reset it.
/IA:[RASHCNETO] :: Include only files with any of the given Attributes set.
/XA:[RASHCNETO] :: eXclude files with any of the given Attributes set.
/XF file [file]... :: eXclude Files matching given names/paths/wildcards.
/XD dirs [dirs]... :: eXclude Directories matching given names/paths.
/XC :: eXclude Changed files.
/XN :: eXclude Newer files.
/XO :: eXclude Older files.
/XX :: eXclude eXtra files and directories.
/XL :: eXclude Lonely files and directories.
/IS :: Include Same files.
/IT :: Include Tweaked files.
/MAX:n :: MAXimum file size - exclude files bigger than n bytes.
/MIN:n :: MINimum file size - exclude files smaller than n bytes.
/MAXAGE:n :: MAXimum file AGE - exclude files older than n days/date.
/MINAGE:n :: MINimum file AGE - exclude files newer than n days/date.
/MAXLAD:n :: MAXimum Last Access Date - exclude files unused since n.
/MINLAD:n :: MINimum Last Access Date - exclude files used since n.
(If n < 1900 then n = n days, else n = YYYYMMDD date).
/XJ :: eXclude Junction points. (normally included by default).
/FFT :: assume FAT File Times (2-second granularity).
/DST :: compensate for one-hour DST time differences.
/XJD :: eXclude Junction points for Directories.
/XJF :: eXclude Junction points for Files.
::
:: Retry Options :
::
/R:n :: number of Retries on failed copies: default 1 million.
/W:n :: Wait time between retries: default is 30 seconds.
/REG :: Save /R:n and /W:n in the Registry as default settings.
/TBD :: wait for sharenames To Be Defined (retry error 67).
::
:: Logging Options :
::
/L :: List only - don't copy, timestamp or delete any files.
/X :: report all eXtra files, not just those selected.
/V :: produce Verbose output, showing skipped files.
/TS :: include source file Time Stamps in the output.
/FP :: include Full Pathname of files in the output.
/BYTES :: Print sizes as bytes.
/NS :: No Size - don't log file sizes.
/NC :: No Class - don't log file classes.
/NFL :: No File List - don't log file names.
/NDL :: No Directory List - don't log directory names.
/NP :: No Progress - don't display percentage copied.
/ETA :: show Estimated Time of Arrival of copied files.
/LOG:file :: output status to LOG file (overwrite existing log).
/LOG+:file :: output status to LOG file (append to existing log).
/UNILOG:file :: output status to LOG file as UNICODE (overwrite existing log).
/UNILOG+:file :: output status to LOG file as UNICODE (append to existing log).
/TEE :: output to console window, as well as the log file.
/NJH :: No Job Header.
/NJS :: No Job Summary.
/UNICODE :: output status as UNICODE.
::
:: Job Options :
::
/JOB:jobname :: take parameters from the named JOB file.
/SAVE:jobname :: SAVE parameters to the named job file
/QUIT :: QUIT after processing command line (to view parameters).
/NOSD :: NO Source Directory is specified.
/NODD :: NO Destination Directory is specified.
/IF :: Include the following Files.
Ability to tolerate network interruptions and resume copying. (incomplete files are marked with a date stamp of 1980-01-01 and contain a recovery record so Robocopy knows where to continue from) Ability to skip Junction Points which can cause to fail copying in an infinite loop (/XJ) Ability to copy file data and attributes correctly, and to preserve original timestamps, as well as NTFS ACLs, owner information, and audit information using command line switches. (/COPYALL or /COPY Copying folder timestamps is also possible in later versions (/DCOPY:T).Ability to assert the Windows NT "backup right" (/B) so an administrator may copy an entire directory, including files denied readability to the administrator. Persistence by default, with a programmable number of automatic retries if a file cannot be opened. A "mirror" mode, which keeps trees in sync by optionally deleting files out of the destination that are no longer present in the source. Ability to skip files that already appear in the destination folder with identical size and timestamp. A continuously-updated command-line progress indicator. Ability to copy file and folder names exceeding 256 characters — up to a theoretical limit of 32,000 characters — without errors.[1] Multithreaded copying. (Windows 7 only) [2] Return code[3] on program termination for batch file usage. |
|
|
|
|
|
#5 |
|
Forum Member
Join Date: Jul 2009
Posts: 2,523
|
OP, the commands given above will do what you want. Just in case yoiu do not know, you should type those commands into a text editor (notepad will do fine) and save the file with the three commands into a file named mything.BAT
Of course make up your own name instead of mything. Now you can run it in two ways. By double clicking the file, or by typing the file name at the command prompt. You need not type the extension. So click Start, and type command prompt into the box. Then type help. You will be given a list of commands, including how to get help on any command, and lots of other halp. You can scroll the window. This is supposed to be for advanced users, but it is a doddle, and much easier than using the gui, if like me you would rather know what you are doing than just clicking and hoping. Note particularly the CD command, and the PATH command, both crucial. This is the real operating system,. All the GUI windows and clicking are merely methods of issuing the comands you see when you type help. |
|
|
|
|
|
#6 |
|
Forum Member
Join Date: Aug 2010
Location: Essex
Services: too many
Posts: 13,522
|
I would definitely use robocopy in preference to xcopy
and I would definitely use a utility like puresync over a batch file. |
|
|
|
|
|
#7 |
|
Forum Member
Join Date: Dec 2009
Posts: 2,990
|
^ digital spy rocks.
To #1 - gonna try this out using my other computer, just to confirm to myself (1) it does the trick and (2) doesn't format the disk or something else equally OMGy (highly unlikely but just want to see it working elsewhere before giving it the main job) To #2 - Unfortunately I'm WinXPed so robocopying isn't possible - won't be facing Win7 until a finally buy that LapTop which is No2 on my "thngs I'd like to have". Also, all those "this will do this and that, and cater for this scenerio and that one.. etc" <- well that does feel a little too advanced for my liking at the mo - being able to use something short 'n simple if I ensure the 'situation' is right (ie. no files already there, no networking thingies etc), feels the best choice.
|
|
|
|
|
|
#8 | |
|
Forum Member
Join Date: Aug 2010
Location: Essex
Services: too many
Posts: 13,522
|
Quote:
http://www.microsoft.com/en-us/downl....aspx?id=17657 As the saying goes, with great power comes great danger. Its VERY easy to delete vast quantities of data if you get the commands the wrong way round and don't forget that it is synchronising so will delete files on the destination if they have been deleted on the source. Fortunately you can simulate the copy without doing it so you have can test it before unleashing the power. |
|
|
|
|
|
|
#9 |
|
Forum Member
Join Date: Mar 2006
Services: A hoover or some other generic vacuum cleaning machine.
Posts: 27,600
|
I use a batch file (way for complicated that what the OP is after) because no utility i could ever find would ever do completely what i was after.
|
|
|
|
|
|
#10 | |
|
Forum Member
Join Date: Dec 2002
Posts: 179
|
Quote:
|
|
|
|
|
|
|
#11 |
|
Forum Member
Join Date: Jan 2003
Location: london
Services: N8-00 vod, Nexus7, O2 BB 8meg, humax PVR, W7-64 - Minecraft FTW
Posts: 31,160
|
|
|
|
|
|
|
#12 | |
|
Forum Member
Join Date: Dec 2009
Posts: 2,990
|
Quote:
So setting up the batch file to do it to both drives then shutdown, means I can set it off, go to bed, and be greeted in the morn by a shutdown computer and two wd-drives full of backed up stuff. ![]() btw: just tried the bathfile (without the shutdown line) and if works a dream :bigyay: |
|
|
|
|
|
|
#13 | |
|
Forum Member
Join Date: Aug 2010
Location: Essex
Services: too many
Posts: 13,522
|
Quote:
http://www.jumpingbytes.com/en/pures...atic-jobs.html |
|
|
|
|
|
|
#14 | ||
|
Forum Member
Join Date: Mar 2006
Services: A hoover or some other generic vacuum cleaning machine.
Posts: 27,600
|
Quote:
Quote:
|
||
|
|
|
|
|
#15 |
|
Forum Member
Join Date: Aug 2010
Location: Essex
Services: too many
Posts: 13,522
|
I don't get this ? Of course you can do it with a batch file but bother writing a script when a simple app can do all the functions with a few clicks and I don't really see any issue install an app to do a specific function.
|
|
|
|
|
|
#16 |
|
Forum Member
Join Date: Mar 2006
Services: A hoover or some other generic vacuum cleaning machine.
Posts: 27,600
|
Personally, it lacks the flexibility. I spent ages trying loads of different backup apps a couple of years ago, and found problems with every single one of them. In my batch files i actually use robocopy.exe quite a bit, which has lots of flags which aren't exposed in the GUI app MS tech wrote. So i decided to just use it directly instead of their wrapper.
|
|
|
|
|
|
#17 | |
|
Forum Member
Join Date: Aug 2010
Location: Essex
Services: too many
Posts: 13,522
|
Quote:
If you are happy using batch scripts then great for you. |
|
|
|
|
|
|
#18 |
|
Forum Member
Join Date: Mar 2006
Services: A hoover or some other generic vacuum cleaning machine.
Posts: 27,600
|
|
|
|
|
|
|
#19 |
|
Forum Member
Join Date: Jun 2005
Posts: 8,497
|
You can't beat a nice little batch file.
On the other hand, for straightforward file copying (as opposed to syncing) I'll recommend TeraCopy. It's faster than the Windows standard file copying and it handles errors more gracefully (it doesn't get halfway through and then go 'nah, I don't like this one file, so I'm going to stop the entire job'). You can also set it to verify the files and shutdown the system upon completion. It's a small install and you can either set it as the default copy handler or just use it as and when required. |
|
|
|
|
|
#20 |
|
Forum Member
Join Date: Jun 2006
Posts: 1,068
|
If you have XP Professional you can add this batch file to a scheduled task to run every night.
I have a similar batch file that copies a load of files from our NAS to a USB backup disk,every night at 01:00am (even I don't work at that time of the morning) |
|
|
|
|
|
#21 |
|
Forum Member
Join Date: Dec 2009
Posts: 2,990
|
^such a schedule would require having computer and both Xdrives on 24/7, right ?! - and that's something, in this age of crippliing(?) electricity bills, I'd prefer not to do. (I even turn off the monitor when I'm not sat by the computer cos it is doing something like converting a whole bunch of ts files to mp3)
|
|
|
|
|
|
#22 | |
|
Forum Member
Join Date: Aug 2010
Location: Essex
Services: too many
Posts: 13,522
|
Quote:
You can also put PC and NAS to sleep when not in use, they consume a few watts just to check for events. |
|
|
|
|
|
|
#23 |
|
Forum Member
Join Date: Dec 2009
Posts: 2,990
|
When I was using my comp to record tvshows I would daily use the wakeup/standby option (thems were the days), and luckily my computer is one of the ones for which standby DOES drop the electricty usage by a great deal - maybe this'll be something "to be aware of" and file under "possible things to do in the future".
|
|
|
|
|
|
#24 |
|
Forum Member
Join Date: Dec 2009
Posts: 2,990
|
And another thing....
xcopy c:\stuff f:\ /s /i xcopy c:\stuff g:\ /s /i shutdown /s is working a treat but is there an 'addon' I can (erm) add before the shutdown to delete everything in c:\stuff ? - I don't want to delete the folder, just the contents. Looking thru the various resonses I've seen: /MOV :: MOVe files (delete from source after copying). /MOVE :: MOVE files AND dirs (delete from source after copying) so: xcopy c:\stuff f:\ /s /i xcopy c:\stuff g:\ /s /i /move shutdown /s would do it, right ?! btw: with /MOV, if my stuff folder had subfolders, would /MOV delete the files inside those subfolders but leave the folders alone, ie. still there - whilst the /MOVE would delete files+folders. |
|
|
|
|
|
#25 |
|
Forum Member
Join Date: Jul 2003
Posts: 1,235
|
XCOPY doesn't have /mov or /move - that's ROBOCOPY.
ROBOCOPY /S /MOV - will leave the source folders alone (ie still there, but empty) |
|
|
|
![]() |
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
|
All times are GMT +1. The time now is 19:54.




Copying folder timestamps is also possible in later versions (/DCOPY:T).