In this article we'll look at a solution, to use Robocopy to scan the C: drive for document files and back them up (for example; copy to a USB flash drive).
Robocopy
This is a free command line program included with Windows as standard. In my example here I'll be using Windows 7 but this will also work for Windows 10 as well.
If you'd like to learn more about the basic functionality of Robocopy please see my previous article on the subject: https://mgxp.blogspot.ch/2015/01/robocopy-backup-and-file.html
Finddocx
Finddocx is just a name I've given my script. It consists of two files, a command (batch) file and a Robocopy job file.
Finddocx.cmd (command file)
The command (batch) file, double click to execute. This contains the source and destination locations. Here's what it looks like inside:ROBOCOPY C:\ %username% /JOB:finddocx
pause
The first line is as follows:
ROBOCOPY <source> <destination> /JOB:<jobfile>
In my example I will search the entire C: drive (C:\). The backup files will be stored in a folder named after my own Windows username, the %username% is a variable. The /JOB:finddocx will use the finddocx.rcj for parameters.
The pause command at the end is just to stop the command window from closing when the script ends.
Finddocx.rcj (job file)
The job file. It contains various parameters including which file types to backup. The following is inside the file:
:: Finddocx example job file
:: mgxp.blogspot.ch
:: January 2018
:: Use two colons :: to disable a command from running.
:: This job file is a modified version of one generated by Robocopy.
:: See Robocopy /? for more details.
::
:: Include These Files :
::
/IF :: Include Files matching these names
*.doc?
:: *.xls?
:: *.ppt?
:: *.pdf
:: *.txt
:: *.png
:: *.jpg
::
:: Exclude These Directories :
::
/XD :: eXclude Directories matching these names
AppData
::
:: Copy options :
::
/S :: copy Subdirectories, but not empty ones.
/COPY:DAT :: what to COPY for files (default is /COPY:DAT).
/PURGE :: delete dest files/dirs that no longer exist in source.
::
:: Retry Options :
::
/R:0 :: number of Retries on failed copies: default 1 million.
/W:30 :: Wait time between retries: default is 30 seconds.
::
:: Logging Options :
::
/LOG+:log.txt :: output status to LOG file (append to existing log).
/TEE :: output to console window, as well as the log file.
In the above job file, where you see two colons :: it means that the text on that line is ignored. In other words, :: means a comment.
/IF
You'll notice that there's an /IF command at line 12. Below it there is a list of file types. In my example above only *.doc? is enabled. However, if you wish, remove the :: next to the others to backup more file types. You could also extend this list and add even more file types.
/XD
Add folders here that you do not want it to search. I've put AppData here because it was just giving 'access denied' errors so I prefer to exclude it. You can add more folders here as needed.
Setup Finddocx
The following is an example only:
- Insert a USB flash drive
- Create a folder on it called "finddocx"
- Copy the source code for finddocx.cmd (above)
- Open Notepad and Paste
- Save the file to the USB drive into the finddocx folder as finddocx.cmd
- Copy the source code for finddocx.rcj (above)
- Open Notepad (a new window) and Paste
- Save the file to the USB drive into the finddocx folder as finddocx.rcj
- Edit the finddocx.cmd and rcj files as needed (you may wish to add more file types to search for, you may wish to change the destination folder, etc).
Run Finddocx
Here's what happens if I double click my finddocx.cmd, a command window will open you'll see thousands of files zoom by:
Don't worry, don't touch, just let it work. Once it has finished press a key to close it.
Look in the folder on your flash drive:
A log.txt file has been created, open in Notepad to see what happened, what was backed up, if there were errors, etc.
You'll see a folder with your username, in my example "Michael". This is where the backup is. Double click Michael (or whatever your folder is called) and you'll see something like this:
There will be sub-folders. These represent the folders from your C: drive. If you explorer these folders you'll find the various doc files that were backed up. The folder structure where they were found on your C: is maintained and replicated here.
Notes
- The second time you run Finddocx with the same user it will delete the existing files on your backup destination (USB drive) and replace them with new copies from the C: drive.
- Using the %username% variable means you can take your USB flash drive from computer to computer backing up data. The backed up files will be stored in separate folders on your USB drive.
- Instead of using %username% you could edit the finddocx.cmd and change it to backup to %computername%.
- If you want to create your own Robocopy job file from scratch you can do. You must use the /SAVE:<job> parameter. Please see the Robocopy documentation or Robocopy /? for details.
Disclaimer
Use at your own risk! The script I've included here is just an example to get you started. I am not guaranteeing anything. I am not responsible if you mess something up! Take care, especially with user data.
Conclusion
This script is just a start, using it and the power of Robocopy you can easily backup user files. Of course it can't replace a proper backup solution but as explained in the introduction, it could be a simple way to make a copy of important user files prior to replacing a computer or re-imaging it. I hope you found this article useful.
No comments:
Post a Comment