Vous êtes sur la page 1sur 6

I am having a storage folder on network in which all users will store their active data on a server now that

server is going to be replaced by new one due to place problem so I need to copy sub folders files from the old server storage folder to new server storage folder. I have below ex: from \Oldeserver\storage\data & files to \New server\storage\data & files.

xcopy.exe is definitely your friend here. It's built into Windows, so it's cost is nothing. Just xcopy /s c:\source d:\target You'd probably want to tweak a few things; some of the options we also add include these: /s/e - recursive copy, including copying empty directories. /v - add this to verify the copy against the original. slower, but for the paranoid. /h - copy system and hidden files. /k - copy read-only attributes along with files. otherwise, all files become read-write. /x - if you care about permissions, you might want /o or /x. /y - don't prompt before overwriting existing files. /z - if you think the copy might fail and you want to restart it, use this. It places a marker on each file as it copies, so you can rerun the xcopy command to pick up from where it left off. If you think the xcopy might fail partway through (like when you are copying over a flaky network connection), or that you have to stop it and want to continue it later, you can use xcopy /s/z c:\source d:\target.

Help for batch file

For this example I am going to assume that your CD-RW is in drive G: and that all your files are on Drive F: in the root directory. Sample code: XCOPY F:\*.* G:\ /C /S /D /Y /I Let's break things down: XCOPY allows for copying of files, directories, and sub F:\*.* is our source location G:\ is our destination location /C tells XCOPY to ignore errors, and finish what can be /S tells XCOPY to copy everything including directories subdirectories /D tells XCOPY to only copy source files that are newer directories. done and than the

destination files (big time saver on the process) /Y tells XCOPY to overwrite files without asking for confirmation /I tells XCOPY to automatically create new directories on the destination, if new directories were created in source. Now, let us say that the files you want copied are on drive F, in the directory/folder called "GOOGLE", and your CD writer is still G: XCOPY F:\GOOGLE\*.* G:\GOOGLE\ /C /S /D /Y /I In this example, you would have to manually create the GOOGLE directory on drive G: . Of course, you only would need to do this once. All subdirectories in GOOGLE would get transferred automatically. Why does GOOGLE have to be created on the CD? Well, our source specification already entered the directory GOOGLE (XCOPY F:\GOOGLE\...) The /I switch only works on directories after the current path. The current path has to exist, and the /I switch will create the subdirectories that follow. With the code copied, paste it into notepad, and update the locations to reflect your actual drives and folders. Save the file as filename.bat and for ease of use create a shortcut to the file from the desktop. You can further customize these batch files to include specific files, but things will get messy. I would recommend having the files you need backed up all in one directory, and just copying over the whole directory each time. This will ensure that any new files created get copied automatically, without the need to ever change the batch file. As long as any new files are put into the directory specified in the batch file (or a subdirectory of it), they will get copied. There is no limit on how many lines you can have in a batch file, so you can repeat this code as often as you wish with different sources and destinations. However, if everything is in subdirectories of the source destination, all you need is the one line. Multiple lines are required for directories not on the same branch, or if you only wish to copy select subdirectories of the source. I hope this helps more then confuses. I have also found an article that goes through very similar steps: WEBSITE: Backup Important Files With This Simple Batch File. URL: http://techrepublic.com.com/5100-6270-1051305.html A suggestion made in the article is to have the batch file executed via the Task Scheduler. An option you might find useful if anyone tends to forget to go through the backup process. Please do not hesitate to ask for a clarification if you require further assistance. I will be happy to help you in any way I can. If you are not sure how to modify the code, please send me a full list of files/locations you need backed up, and I will write the code for you. Thank you for choosing Google Answers. SEARCH STRATEGY:

Google Search for "batch file"+"learn"+"simple"

batch file needed


I need to write a batch file that copies a text flie from a network share to a folder in a computer. This what I tried to no avail: copy \\network share root\network share folder\file to copy c:\folder to copy file to
Make sure you use "" around all the long file names. copy "\\network share root\network share folder\file to copy" "c:\folder to copy file to" For instance. copy "\\bobbi\c\Quicken Backup Files\qdata.qel" c:\temp that one works. copy \\bobbi\c\Quicken Backup Files\qdata.qel c:\temp that one doesn't. __________________

Network batch file


The environment is Windows Web Server 2008, and I'm just trying to copy a folder full of files to a network location (a managed backup network folder). Here is my .bat file, running in the folder with my .bat files: copy *.bak \\networklocation\*.bak pause however \\networklocation requires username x and password y, so running the script gives: Logon failure: unknown user name or bad password. I can't figure out a way to supply my credentials. I tried creating a scheduled task and modifying the security options, but this only seems to allow you to use credentials relevant to the machine (i.e. I try putting in username x and it can't find it). How do I run this script with all the right permissions?

Solution:

net use \\networklocation\sharefolder password /USER:username copy \*.bak \\networklocation\sharefolder\*.bak

Backup, Part 3
Batch Files
The key to automated backup is the use of a batch file. This is a text file that contains commands that are executed whenever the file is run. Creating a batch file is easy. In Windows, you can create one using Notepad. The thing to remember is that it must be a pure ASCII text file. Using a Word Processor, even Wordpad, will not produce a pure text file unless you are very careful. I recommend sticking to Notepad to be sure. Microsoft first introduced batch files in DOS, where they used one (autoexec.bat) as one of the main startup files for booting DOS. Since then, the graphical environment of Windows has taken over, and a lot of people either forgot about batch files or never learned about them. But they still have their uses, and backing up files is one of them. I will do an example that assumes you have a Zip drive that is the G: drive on your system. If you want to backup to a different hard drive, or to a network drive, you will need to adjust this accordingly. Start by opening Notepad. Type the following command: copy c:\temp g: That is all, just the one line. Save it to your Desktop, but be careful to name it Test.bat. You need to have the *.bat extension for it to work as a batch file. Now, if you look at the icon on your desktop, you will see that it is not the usual text file icon. It will have gear on it. That is the sign that it is recognized as a batch file. If you have a C:\Temp directory, make sure it has a couple of files in it so you can see how this works. If you don't have such a directory, create one and put a couple of files in it. Now, just double-click on your batch file, and you should see a MS-DOS window open, with a black background, and you will see your files being copied. Each file will be listed, and at the end if will say "X" file(s) copied, where "X" is the number of files in your C:\Temp directory. Now, go to your G: drive (or whichever drive you used for this test), and verify that your files were indeed copied. Congratulations! You have just written and run a batch file. Now, this is the essence of how to use a batch file to backup important files. But we need to refine it a little. First, the "copy" command is just not powerful enough for our purposes. Fortunately, there is another command, called "xcopy", that will do very nicely. You can get information on this command by opening an MS-DOS window (also known as a Command Prompt in Windows NT/2000), and entering the command:

help xcopy Here is what you get back in Windows 2000, for instance: ***************************************************************** Copies files and directory trees. XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W] [/C] [/I] [/Q] [/F] [/L] [/H] [/R] [/T] [/U] [/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z] [/EXCLUDE:file1[+file2][+file3]...] source Specifies the file(s) to copy. destination Specifies the location and/or name of new files. /A Copies only files with the archive attribute set, doesn't change the attribute. /M Copies only files with the archive attribute set, turns off the archive attribute. /D:m-d-y Copies files changed on or after the specified date. If no date is given, copies only those files whose source time is newer than the destination time. /EXCLUDE:file1[+file2][+file3]... Specifies a list of files containing strings. When any of the strings match any part of the absolute path of the file to be copied, that file will be excluded from being copied. For example, specifying a string like \obj\ or .obj will exclude all files underneath the directory obj or all files with the .obj extension respectively. /P Prompts you before creating each destination file. /S Copies directories and subdirectories except empty ones. /E Copies directories and subdirectories, including empty ones. Same as /S /E. May be used to modify /T. /V Verifies each new file. /W Prompts you to press a key before copying. /C Continues copying even if errors occur. /I If destination does not exist and copying more than one file, assumes that destination must be a directory. /Q Does not display file names while copying. /F Displays full source and destination file names while copying. /L Displays files that would be copied. /H Copies hidden and system files also. /R Overwrites read-only files. /T Creates directory structure, but does not copy files. Does not include empty directories or subdirectories. /T /E includes empty directories and subdirectories. /U Copies only files that already exist in destination. /K Copies attributes. Normal Xcopy will reset read-only attribute /N Copies using the generated short names. /O Copies file ownership and ACL information. /X Copies file audit settings (implies /O). /Y Suppresses prompting to confirm you want to overwrite an existing destination file. /-Y Causes prompting to confirm you want to overwrite an existing destination file. /Z Copies networked files in restartable mode.

The switch /Y may be preset in the COPYCMD environment variable. This may be overridden with /-Y on the command line. ********************************************************************** Now, this may be a bit much when you first look at it, but in most cases you won't need all of these options in your batch file. Here is a copy of my own backup batch file, which I call "backup.bat" xcopy /e /v /y E:\Agent \\NTSERVER\NTServerC\KevinBackup\Agent xcopy /e /v /y E:\Agent M:\Backup\Agent xcopy /e /v /y J:\Netscape\Users\KOB1 \\NTSERVER\NTServerC\KevinBackup\Netscape xcopy /e /v /y J:\Netscape\Users\KOB1 M:\Backup\Netscape xcopy /e /v /y F:\MyDocuments \\NTSERVER\NTServerC\KevinBackup\MyDocuments xcopy /e /v /y F:\MyDocuments M:\Backup\MyDocuments xcopy /e /v /y F:\Eudora \\NTSERVER\NTServerC\KevinBackup\Eudora xcopy /e /v /y F:\Eudora M:\Backup\Eudora Let us take this a piece at a time. First, the command "xcopy". This is followed by three "switches" as they are called. The first, /e, says to copy all of the subdirectories and their contents as well. So I only need to name a directory, and all of the contents get copied. The second switch, /v, tells the computer to verify the copy it makes. The third switch, /y, tells the computer to go ahead and overwrite the remote copy of the file without asking me if I am sure. Following these switches, first comes the source, followed by the destination. So in line one, all of the contents of the E:\Agent directory are being copied to a place on the Server. In my case, I am actually doing two backups here. After copying to the server, I also make a copy to a second hard drive (Drive M: on my machine). So, take your Test file, and try creating an xcopy command to back up one of your directories. When you know it works, just create additional xcopy commands for as many directories as you think you need to backup. I think you will find that creating a batch file to do your backups is not hard at all. And next I will show you how to make it automatic.

Vous aimerez peut-être aussi