Sometimes it is useful, or even necessary to simply copy existing directories to another hard disk or network drive, rather than using more complicated backup methods. Multiple directories can be backed up comparatively easy with a simple click, by creating and running a batch file.
May 16, 2018 To make changes to the registry and export your changes to a.reg file, follow these steps: Click Start, click Run, type regedit in the Open box, and then click OK. Locate and then click the subkey that holds the registry item or items that you want to change. Click File, and then click Export.
That file can be executed manually from your desktop, can be added to startup or scheduled for periodic execution as needed.Batch files have comparatively easy syntax and can have many uses, so this method could also be a good learning experience by example. You can simply copy the text below, and paste it into Notepad. Set hour=%time:0,2%if '%hour:0,1%' ' set hour=0%time:1,1%set folder=%date:10,4%%date:4,2%%date:7,2%%hour%%time:3,2%%backupcmd% '.source dir.' '%drive%%folder%.destination dir.'
Example - dated directoriesIn the example below, we first set 3 variables: drive, folder, and backupcmd. The 'drive' variable defines the root directory of our backups. The 'folder' takes the 2 digit day value from the current date (US date format, taking 2 digits from the date command output, starting at the 7th character), which we will use as a subdirectory. The third variable, 'backupcmd' defines our backup command with the appropriate command line switches we want to use.@echo off:: variablesset drive=D:Backupset folder=%date:7,2%set backupcmd=xcopy /s /c /d /e /h /i /r /k /yecho ### Backing up directory.%backupcmd% 'C:Program Filessomedirectory' '%drive%%folder%'echo Backup Complete!@pauseThis example will backup the 'C:Program Filessomedirectory' folder to 'D:Backupdd' where dd is the current day of the month.
After a month, we will have 30ish daily copies of the backup. And, because of the xcopy command line switches chosen, following backups will only overwrite files that are newer, speeding up subsequent backups. Alternatively you can add a line to delete the%folder% directory prior to executing the%backupcmd% if you prefer to start clean (and take longer).Cleaning upIt is usually a good idea to clean up temporary files, cookies, and history from the destination backup, as applicable. It is especially useful if you're backing up full, multiple user profiles and overwriting them periodically. Since temporary files and cookies change, your backed up directories will keep increasing with unnecessary files. To remedy this, the following code can be added to the backup script, or to a separate batch file. For the UK people who may stumble upon this.check out the date and time line which will capture the date and time.
If today was and 19:30, the variable dateNtime would be 19-30Hope this saves someone some time!! The code is below@echo off:: variablesset drive=M:mybackupSET dateNtime='%date:0,2%-%date:3,2%-%date:6,6%%time:0,2%-%time:3,2%'set backupcmd=xcopy /s /c /d /e /h /i /r /k /yecho ### Backing up your Sites directory.%backupcmd% 'C:Program FilesSites' '%drive%%dateNtime%'echo Backup Complete - Your Backup is located at%drive%@pause.
![Bulk Bulk](/uploads/1/2/5/6/125602938/614047890.png)
You only need one additonal line for each LAN client/directory, not 10. For example, to backup the administrator profile on 3 remote machines named COMP1, COMP2, and COMP2, you'd need something like:@echo off:: variablesset drive=g:Backupset backupcmd=xcopy /s /c /d /e /h /i /r /k /y%backupcmd% 'COMP1cDocuments and SettingsAdministrator' '%drive%COMP1 - admin profile'%backupcmd% 'COMP2cDocuments and SettingsAdministrator' '%drive%COMP2 - admin profile'%backupcmd% 'COMP3cDocuments and SettingsAdministrator' '%drive%COMP3 - admin profile'echo Backup Complete!@pauseAnd so on, for each client you want to backup. In other words, you do need to add one line of code for each directory you're backing up (it includes all subdirectories as well), I am not sure how you can further simplify that. David,If i want to rename a folder when it's backed up deppending on the date, for example i have a folder with files that are populating every day in C:pictures and i want to make a backup of it every to D:Backup but change the folder name to 'picturesddmmyyyy' what do i have to do? Rename the folder before backing up or during the backup procedure?The main problem of this procedure is how to avoid overwriting every time the new folder to the backup destination to the old folder.How the system will be able to identify the current ddmmyyyy?Can you send me the code for this batch?Thanx for your time.
The xcopy '/d' command-line parameter specifies that the command is to copy all source files that are newer than existing destination files. Using this option allows you to update the backup directory only with files that have changed since last time you ran it (rather than copying all files). You should still end up with identical directories/files after execuring the batch file, while saving time for consecutive backups.I hope this helps. Please direct any further questions to our forums. Im sorry that i dont understand most of them cause im new in batch files but i also want to backup & zip some files, lets say:'C:program Fileswinzipwzzip' -a -p -r C:BACKUPBACKUP.zip 'C:Program Filesahead.'
copy C:BACKUPBACKUP.zip K:BACKUPBACKUP.zipi run this batch every day and i want to verify that the backup is done, otherwise prompt me with an error messagepossible?I think that the best way is to compare the date that the backup was run with the date that the backup.zip file is modyfied. That was a thought but i dont know if is the best waythnx in adnvance. Here is another batch file.
I have it running on my machine so that when it is run it backs up all of my documents in the C: drive to my E: drive. See what you think. Nice and simple. However I do want to add a command to tell it to copy ONLY what has been changed since the last backup. I know this can be done using /D:m-d-y (leaving them blank checks target directory and only copies if the date of the last edit of the source has been changed) However I am not sure how to add it in. Any help would be greatly appreciated.@echo offcolor F9clsxcopy /R /E /H /Y 'c:Documents and SettingsUser1My Documents.'
'E:my documents.' PAUSE. Hi, I have problems with getting the dates on my folder.
I live in Sweden so I tried the other settings. The backup works but I would like to get dates on my folders when I backuo them.@echo off:: variablesset drive=G:ProjektArbetsdokumenttestSET dateNtime='%date:0,2%-%date:3,2%-%date:6,6%%time:0,2%-%time:3,2%'set backupcmd=xcopy /s /c /d /e /h /i /r /k /yecho ### Backing up your Sites directory.%backupcmd% 'C:Documents and SettingsJohnMy Documentsbackup' '%drive%%dateNtime%'echo Backup Complete - Your Backup is located at%drive%@pause.