I love Beyond Compare. It is so useful. It allows you to compare contents of files in a very nice way. It can also compare entire directories. It can even compare and copy binary files.
In many ways, I prefer it to the built in Windows copy functionality because if there is an error in Windows copy, you have to try again and I never really know the state of the destination folder. When I use Beyond Compare, if there is an error all I have to do is look at the differences or just simply try again. I also get that warm-fuzzy when I see that there is no difference between the source and destination directories.
I also like to have the same warm-fuzzy when it comes to “backups". I don’t trust backup solutions in general. It isn’t that they aren’t good, it is that I don’t trust that I am configuring it right. What I want is to be able to see the files after a backup in the destination drive. Then if I can use a tool like Beyond Compare to verify the source and destination directories are the same, then I feel confident that what think I backed up is actually backed up.
One important point with this model is that I am not really talking about a true backup in the sense that most backup software provides. Most backup software saves different versions of a given file for a certain period of time. While, what I am talking about here could be modified to do so, it would be a substantially different solution. What I am talking about is really a way to snapshot my important data to another disk in the event that my disk fails. I am not worried about me changing a file and needing a previous version of a files. I use manual copies or version control for this type of stuff. I don’t need this for most files, thus I only need the most recent snapshot of my important data.
You can actually use Beyond Compare to do what I just described. However, I want an automated way of doing this. I also want to be notified of any errors. There is nothing worse than thinking your backup is running, and then when you need it most, you realize it was broken. So, always periodically check that your backup process is working.
Below are my scripts I have created to automate the process. The only software needed to do this is Beyond Compare and Microsoft LogParser and MS Windows XP (or greater I’m sure). LogParser is only needed if you want to see any errors that occur. If you like checking log files, then you don’t need LogParser.
This scripts below will need to be tweaked to match your environment. My environment is such that I have an external hard drive that I backup to. You can also use UNC pathnames as well if you want to use a Windows share.
You can download a zip file of the same basic thing, or you can follow the instructions below.
Assume E:\ is the volume that you are backing up to.
- Create E:\backupScript directory
- Create E:\backupScript\Logs directory
- Create E:\backup directory
- Create E:\backupScript\backupAll.bat text file.
- Create E:\backupScript\backupDirectory.bc text file.
- Create E:\backupScript\backupOne.bat text file.
- Create E:\backupScript\CheckForError.bat text file.
- Create E:\backupScript\CheckForErrors.sql text file.
- In Beyond Compare, create a Saved Session for each of the directories you want to backup. This would be the same thing you would use if you were to compare two directories, just that you save the configuration information. The name you give it will be used in the backupAll.bat file.
- Copy the content from each of the sections below into the appropriate text file you created.
This is the main file that you will run to do the backup. You can use Windows Scheduled Tasks to run this an a regular interval to automate the backup process. You need to modify this file to have a line for each of the Saved Sessions you created in the initial setup. If you are backup up a SQL Server database directory, then be sure to stop SQL Server first, otherwise the files will be locked and cannot be backed up. You could also schedule a backup of the SQL Server databases, and then backup the database backups. The choice is yours. The backup is running on my laptop where I don’t have much disk space to make backups of the databases just to back them up, but I no problem stopping SQL Server since I am the only one using it.
call backupOne.bat "Backup dev to E"
call backupOne.bat "Backup Inetpub to E"
call backupOne.bat "Backup Video to E"
rem Stop SQL Server so we can backup the database files
net stop MSSQLSERVER
call backupOne.bat "Backup Databases to E"
rem Check for errors
Below is a Beyond Compare script. It tells Beyond Compare to clear any read only flags in the destination directory so that we won’t get any errors when replacing any files. Then it makes the source and destination directory the same. There are other options, just check the Beyond Compare docs on how to modify the script to change the behavior of the sync command (see the last line), the rest of the script is to clear the read only flags.
# Backup Directory
# Turn on logging
log verbose %LOGS_PATH%\backup-%BACKUP_NAME%.log
# Load the deployment directory on the server and the backup directory on the server
#Must expand all folders so that select will work
# Select all files in the backup directory on server
# Clear the read only flag on the backup directory on server
# Assume yes to all confirmation messages
# Copy all files from local directory to backup directory on the server
sync mirror mirror:left->right
This file is very simple and doesn’t really need to be modified unless you changed the path to the Logs directory, or have installed Beyond Compare in a different path. This just tells Beyond Compare to run as quietly as possible so that it doesn’t disturb us. :)
IF NOT EXIST %LOGS_PATH% md %LOGS_PATH%
"C:\Program Files\Beyond Compare 2\bc2.exe" /silent @backupDirectory.bc
This file is optional. You really only need it if you want to scan the log files for errors and then show them to you. It tells MS LogParser to query the logs we created using the query defined in the CheckForErrors.sql file. Adjust the path to LogParser if needed or a different version is used.
"C:\Program Files\Log Parser 2.2\LogParser" file:CheckForErrors.sql -i:TEXTLINE
This file is optional like I said before. Adjust the path to your log files if you didn’t use the same path as I did.
select * into DATAGRID from E:\backupScript\Logs\*.log where Text like '%Script Error%'