Mercurial PreBackup Script
This project consists of a single script designed to be run before intiating a disk backup operation. The script will search the specified disk or folder for Mercurial Repositories and make clones of them in a specified location to be included in the backup. This behavior is indended to allow backups of the clones to occur while leaving the original repositories available for continued use.
The script has been written and compiled using AutoIt v3 scripting. It is completely free, and the source code is available at https://bitbucket.org/nedmech/hgprebackup/src.
This script has been compiled as a command-line application. Most backup utilities provide the option to call a pre-command before beginning the backup task. This script is intended to be used as the backup pre-command. It can be run independently at any time as well. Note that there are separate executables compiled for 32-bit (x86) and 64-bit (x64) operating systems. Make sure to reference the correct executable for the target operating system architecture.
Command Line Syntax
The settings file is assumed to be the "HgPreBackupSettings.ini" file unless otherwise specified as an optional command-line argument.
NOTE: If the path to the settings file contains spaces, it should be contained in double-quotation marks (") to ensure proper parsing.
> HgPreBackup.exe [settings file path]
Example for 32-bit OS:
> HgPreBackup_x86.exe "HgPreBackupSettings_Project1.ini"
Launching the executable directly from Windows Explorer (typically by double-clicking) will have the same effect as calling it from command-line with no optional arguments. The application will automatically run with settings in the "HgPreBackupSettings.ini" file, or the default settings if the settings file is not found.
The script behavior can be modified by changing the settings in the "HgPreBackupSettings.ini" file. Additionally, the settings file can be copied and renamed for different profiles, and the specific settings file for a profile may be specified as a command-line argument.
- hgPath - Command path for the Mercurial application.
This is typically just 'hg' if Mercurial has been installed such that the 'hg' command is recognised at the command line. If not, a full path to the Mercurial executable must be provided.
- Example: hgPath = C:\Program Files\Mercurial\hg.exe
- RepoPath - Path to search for source repositories.
All primary repositories found in the folder will be cloned to the backup location. Any subrepositories will only be cloned as they are referenced by primary repositories. The number of layers of subfolders that will be checked is limited by the "SubFolderLimit" setting.
- Example: RepoPath = C:\Repositories\Project1\
- BackupPath - Path where backup repositories are to be located.
An exact mirror of the repositories (including subfolder paths) found at "RepoPath" will be created and maintained at this location. The Working Directory of the backup repositories will be kept at Revision 0000 (empty) in order to minimize the space required for a backup.
- Example: RepoPath = C:\BackupRepos\Project1\
- LogPath - Path where log files are to be created.
Typically, this is the same as BackupPath, but an alternate path may be specified to allow logs to be kept in a separate location.
- Example: RepoPath = C:\BackupRepoLogs\Project1\
- SubFolderLimit - Maxmum number of subfolders to check within RepoPath.
This allows the user to specify how deeply to scan the subfolders of RepoPath for repositories. The default value is ten (10). A higher number will allow the script to find repositories that may be more deeply nested. A lower number will reduce the number of subfolders that are scanned, potentially reducing the time it takes to run the script.
Report - Send Email of log file if errors are encountered.
- Expected Values: 'True' or 'False'
- True = Send Email with error report.
- False = No Email will be sent.
- NOTE: When True, Email setting MUST be specified!!!
- Expected Values: 'True' or 'False'
KeepLogCount - Keep at least this number of log files.
- 'KeepLogCount = 0' will keep no log files (KeepLogDays must also be 0)
- 'KeepLogCount = -1' will keep ALL log files (regardless of KeepLogDays setting)
KeepLogDays - Keep at least this many days of log files.
- 'KeepLogDays = 0' will keep no log files (KeepLogCount must also be 0)
- 'KeepLogDays = -1' will keep ALL log files (regardless of KeepLogCount setting)
- NOTE: The KeepLog... settings work in combinaton with each other:
- e.g. at least 30 days worth of logs, AND at least 10 logs. The more generous condition will always take precedence to preserve the maximum amount of historical log information.
NOTE: All of the following MUST be specified if Report is True
- SMTPServer - Name or IP of SMTP server to use.
- Example: SMTPServer = smtp.gmail.com
- NOTE: If using a named server instead of an IP address, make sure that the computer is able to resolve the name correctly. Verify the DNS settings or Hosts file can properly resolve the name.
- SMTPPort - Port number to use for SMTP connection.
- Typical: SMTPPort = 25
- NOTE: GMail uses port 465
- SMTPssl - Use Secure Socket Layer protocol or not.
- SMTPssl = 0 means no SSL is used (less secure, but required if the server does not support SSL)
- SMTPssl = 1 means SSL is USED! (typically required for servers with an "https" address, as well as GMail)
- SMTPUser - Username for SMTP login.
- This is often the same as the email address to be used for outgoing mail.
- SMTPPassword - Password for SMTP login.
- CAUTION!!! - This setting is a known security issue! The password is stored as plain text and is unencrypted. Anyone with access to this file can gain access to the associated SMTP Email account! USE AT YOUR OWN RISK!!! Keep this file in a safe and secure location.
- FromName - Name to identify sender of Email
- Can be left blank
- FromAddress - Email address of sender.
- Typical format: email@example.com
- ToAddress - Comma separated list of addresses to send message to.
- Windows� operating system
- Developed on WinXP Professional v2002 x86 (SP3)
- Tested on Windows� Server 2008 x64
- Mercurial DVCS
- Developed using v2.01
- Earlier version may also be compatible, but not guaranteed.
- Microsoft� Script Runtime (scrrun.dll)
- Developed using Version 126.96.36.19966
- Windows� NT BASE API Client DLL (kernel32.dll)
- Developed using Version 5.1.2600.5781
- Microsoft� CDO for Windows� Library (cdosys.dll)
- Developed using Version 188.8.131.52