Automatic files backup sample

MouseRobot allows to automate work with files and directories. Creating back up of files is an example of such work.

In this example, we consider how you can automate backups using the MouseRobot.

You will see how to use MouseRobot to pack files to ZIP-archive and save them in specified folder.

So, periodically, we need to create backups of the folder "D:\folder". We store the backup-files in ZIP-archive in the folder "D:\folder\Backup". The name of the ZIP-file will contain the date and time of creation.

Instead of the folder "D:\folder\" you can specify any other folder on your computer.

1. Create a new task for MouseRobot.

2. We obtain the date and time by using the built-in functions of MouseRobot.

{Now} - returns the current date and time. The format is set by the computer settings.

IMPOTANT NOTE! To see the format of the date and time on your computer you need to:

  • add the step "Dialog" to the task
  • write {Now} in the "Text dialog"
  • run the macro

A dialog box as shown below will be displayed:

3. Save the current values of date and time in the variable {a}.

  • add the step "Set variable or call function"
  • write "{a}" in the field "Variable"
  • Since "{Now}" may contain invalid for the filename characters (in our case - "/" and ":") it is necessary to replace them by using the "{StrReplace}".

  • in the field "Value" write "{StrReplace ({StrReplace ({Now}, "/", "_")}, ":", "_")}" - replacing of "/" and ":" in "{Now}" with the symbol "_"

Now, similarly to the first step you can view the value of "{a}".

4. Create a ZIP-file folder "D:\folder" and save it in the folder "D:\folder\Backup":

  • add the snippet "Pack Files" to the task
  • In the field "Options" replace:

  • {ArchiveFile} by "D:\folder\Backup\folder{a}.zip", where {a} contains the date and time
  • {filesToPack} by "D:\folder"

IMPORTANT NOTE! The file name should be enclosed in double quotes (" "), as it can contain spaces.

5. Save the created macro.

6. Run the macro by pressing the button "Run".

After running the macro, ZIP-archive of folder "D:\folder" with the date and time will appear in the folder "D:\folder\Backup".

© AutomationBox 2005-2011