Automated Windows Backups

February 1st, 2009 Category: General

No Backups for Microsofties?

Mac users will already know the comfort of automated backups to an external hard disc or a network attached storage (NAS) running in background without user action. It’s really useful and easy to use. Microsoft users usually need to find their own backup solution. They can buy extra tools or use some Freeware/OpenSource tools.

My Goals

It’s not much I want, just a few things should be fulfilled:

  • Sync folders from my notebook/PC to an external hard disc (NAS)
  • Sync should run without user action
  • Sync should run automated (wish: when notebook/PC is idle)

SyncToy V2 from Microsoft

Looking for such a automated backup solution I came across the tool SyncToy from Microsoft. It’s currently only available in English language. SyncToy can be obtained for free from the Microsoft homepage:

It is an easy to use Windows application for copying, moving, renaming and deleting files between folder and computers. Handling is easy, the source (left) folder as well as the destination (right) folder is specified. In my case I use the “Echo” sync action, which means that files on the destination folder are also deleted in case they are deleted on my notebook/PC. A preview can be started to see what would happen and finally the synchronization can be started using the “Run” button.

synctoy-01022009-211328.jpg

Still Manual

OK, now we have an easy to use synchronisation tool and it’s for free but it’s not yet running automated in background. To do this automatically the Windows Task Scheduler is used. We generate a new scheduled task through Start, Programs, Accessories, System Tools, Scheduled Tasks. The following command line should be entered for the scheduled task:

"C:\Program Files\SyncToy 2.0\SyncToyCmd.exe" -R

You will need to enter a user should execute the task. You can use your current account (please note: a password seems to be needed, empty passwords seems not to work). Of course you can also generate an extra user, e.g. “backup”. Take care, if the scheduled task is executed as different user which is currently logged in, it’s needed to start SyncToy with “Run As…” for configuration because the configuration is stored separated for every user.

Backup when Idle

When you want to have backups done always when your notebook/PC is idle, then choose the corrosponding option for the scheduled task: execute when idle. My Windows is in German language, so I don’t know the correct name. Furthermore you can define after which passed time in idle the task should be executed. I use 10 minutes here in a first try.

Within the scheduled task options further options can be set like “run task not when operating in battery mode”, “stop task when battery mode is entered” which might be useful for notebooks.

Hint: The user which will execute SyncToy must have access to the local files as well as the remote directory. For debugging try the “Preview” button and the log file (File, view log).

Result

Using a free tool the files of my notebook/PC are not synchronized automatically when I’ve not done any user input for 10 minutes. Great!

It keeps unclear why Microsoft doesn’t add such a backup tool in Windows. Also installation is not absolutely easy. It would be nice if scheduling options could directly be set in SyncToy.

Compared to TimeMachine for Mac really missing are incremental backups, which means you have backups also available from past in a history.

VMWare ESX Backup Script

January 2nd, 2009 Category: VMWare

There is a simple method doing automated backups using VMWare Infrastructure 3. For this reason a command “vcbMounter” is included. Also the name of this command is confusing it can be used for doing backups of virtual machines.

Doing a backup of a virtual machine can be done using a single command line call:

vcbMounter -a name:"Virtual-Machine-1" -r "/path/to/backup/Virtual-Machine-1"

Ok, your vm named “Virtual-Machine-1″ will now be backuped to the given path. The directory is generated from vcbMounter. The next time you will run vcbMounter it will complain that the directory already exists, so you will have to delete the directory every time before you start the backup:

rm -rf "/path/to/backup/Virtual-Machine-1"
vcbMounter -a name:"Virtual-Machine-1" -r "/path/to/backup/Virtual-Machine-1"

But there is another problem which will cause vcbMounter to complain: For every backup vcbMounter generates a snapshot and will not remove it after backup. What we need is to delete the snapshot before we backup:

vmware-cmd "/vmfs/volumes/storage1/Virtual-Machine-1.vmx" removesnapshots

rm -rf "/path/to/backup/Virtual-Machine-1"

vcbMounter -a name:"Virtual-Machine-1" -r "/path/to/backup/Virtual-Machine-1"

We delete the snapshots for a given virtual machine using “vmware-cmd” and removesnapshots. vmware-cmd needs the path to your .vmx file of the virtual machine. It’s usually stored in /vmfs/volumes/…

vcbMounter does not expect the path to the .vmx. It only needs the name of your virtual machine.

Doing the backup on a NFS mount is also possible. You need to deactive the VMWare ESX firewall and can mount e.g. using “mount -t smbfs”.

Simple MySql Backup Script

December 30th, 2008 Category: PHP/MySQL

The following example scripts performs a simple backup of all MySQL databases. The resulting .sql file is automatically zipped. Using “find” backups older than 3 days are deleted, so you will get complete backups of the last 3 days.

This script is intended to be called periodically (e.g. every day) from cron:

2 2       * * *   root /root/scripts/mysql_backup.sh
#/bin/sh
now=`date "+%Y-%m-%d"`
user="mysql_user"
password="mysql_password"
path="/home/backup/"

cd $path

mysqldump -u $user -p$password  --all-databases | gzip -c > backup_all_$now.sql.gz

# delete files older than 3 days
find . -name "*.gz" -type f -mtime +3 -exec rm {} ";"