Posts Tagged ‘backup’

ntfsprogs for Virtual Disk Partitions

November 29th, 2009 Comments off

The ntfsprogs package provides a nice set of tools for performing operations on NTFS file systems from non-Windows environments.  There are many uses for these, and I’ve found them helpful in virtualized environments when dealing with virtual disk images.  In particular, they allow for the easy restoration of individual files from NTFS virtual disks from the host OS.  These tools however, are only capable of operating on entire devices, and in many cases the individual partitions of virtual disk images are not exposed as block devices by the operating system, preventing these tools from working.

As a workaround for this, I’ve created a patch against ntfsprogs 2.0.0 that adds an --offset option to most of the tools, allowing a partition offset, in bytes from the start of the device, to be specified.

These patches were tested on OpenSolaris, but should work with other systems as well.  They include a Solaris patch to fix compilation issues on Solaris.  They are available in the following forms:

Compiling the tools can be done with:

$ wget
$ gzcat ntfsprogs-2.0.0-offset.tar.gz | tar -xf -
$ cd ntfsprogs-2.0.0-offset
$ ./configure && make

Once compiled, the tools can be installed with make install, or run in place from the ntfsprogs-2.0.0-offset/ntfsprogs directory without having to install them.

The following example demonstrates the tools operating on a snapshot of an NTFS volume stored on a ZFS zvol block device.

# /dev/zvol/dsk/rpool/xvm/win2k8@installed
  Start Offset    Size  Type
       1048576  100.0M  07 Windows NTFS
     105906176   15.9G  07 Windows NTFS
             0    0.0B  00 Empty
             0    0.0B  00 Empty
# ntfsls /dev/zvol/dsk/rpool/xvm/win2k8@installed
Failed to startup volume: Invalid argument.
Failed to mount '/dev/zvol/dsk/rpool/xvm/win2k8': Invalid argument.
The device '/dev/zvol/dsk/rpool/xvm/win2k8' doesn't have a valid NTFS.
Maybe you selected the wrong device? Or the whole disk instead of a
partition (e.g. /dev/hda, not /dev/hda1)? Or the other way around?
# ntfsls --offset 1048576 /dev/zvol/dsk/rpool/xvm/win2k8@installed
System Volume Information
# ntfsls --offset 105906176 /dev/zvol/dsk/rpool/xvm/win2k8@installed
Documents and Settings
Program Files
Program Files (x86)
System Volume Information
# ntfscat --offset 105906176 /dev/zvol/dsk/rpool/xvm/win2k8@installed \
          Windows/System32/notepad.exe > notepad.exe
Tags: , ,

Windows Backups to ZFS

November 18th, 2009 Comments off

One of the methods I use for backing up Windows applications is to mirror the files to a ZFS file system using robocopy and then snapshot the file system to preserve its state.  I use this primarily for nightly backups and during application maintenance because it typically requires that the service be stopped for the duration of the backup.

There are a number of features about ZFS that makes it great for backups.  Among them are snapshots, compression, efficient incremental sending of file systems and block storage, etc.  Dedup will make its appearance in build 128 which will add further benefits as well.  All of these help to conserve disk space and speed up backup and restore operations.

This assumes a recent, working OpenSolaris system with the CIFS service already configured.  The latest version of OpenSolaris at this time is build 127.  For documentation on how to setup the CIFS service, see Getting Started With the Solaris CIFS Service.

To start off, create a parent file system for the backups.  The purpose of this file system is to allow properties to be set once and then be inherited by the descendant file systems created for the backup sets.  Enable both mixed case sensitivity and non-blocking mandatory locks to enhance compatibility between POSIX and Windows file semantics.  Set the sharesmb property to share the file system via CIFS and to shorten the names of the shares.  The name specified below turns into the backups_ prefix for the descendant file system share names.  Without it, the prefix would be the full file system path, in this case, tank_backups_.  In addition, allow the backup user access to create snapshots on the descendant file systems so that snapshots can be created by simply creating a directory from the script.

# zfs create -o casesensitivity=mixed -o nbmand=on -o sharesmb=name=backups tank/backups
# zfs allow -d snapshot,mount tank/backups

With the initial setup completed, begin creating the backup sets.  Create a descendant file system under tank/backups for each backup set and give the backup user write access to it.  This is a simple example and it might be worthwhile to give other users read access to it as well or add more advanced ACLs to the file systems.

# zfs create tank/backups/someservice
# chown /tank/backups/someservice
# chmod 700 /tank/backups/someservice

Normally, I enable compression for the entire pool and then disable it for file systems that won’t see any benefit from it, such as those holding only multimedia files.  If compression isn’t inherited by the backup file systems, it might be beneficial to enable it on them.  Those that can spare performance for additional disk space might try gzip compression instead of the default lzjb.

# zfs set compression=on tank/backups

Finally, create a customized Windows batch file and set it to run automatically with the Windows Task Scheduler.

@echo off
set src="D:\Data\SomeService"
set dst="\\opensolaris\backups_someservice"
set service="SomeService"
set timestamp="%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%-%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%"
set timestamp="%timestamp: =0%"

net stop "%service%"
robocopy "%src%" "%dst%" /MIR
net start "%service%"
mkdir "%dst%\.zfs\snapshot\%timestamp%"

The script is straight-forward, and the only complicated lines are the timestamp ones.  Between the two of them they build a timestamp of the form YYYYMMDD-HHMMSS.  The second line fixes single digits that occur, replacing the leading spaces with zeros.

The last line is interesting in that instead of simply creating a directory, a ZFS snapshot is taken instead.

For restoration, navigate to the share on the server, right-click, select Properties, and then click on the Previous Versions tab.  From here, you can easily browse through the snapshots.  You can also right-click on individual files and then click on Restore previous version and it will only list the versions of the file that differ rather than displaying every snapshot.

Previous Versions

There are, or course, a number of ways to improve this backup scheme.  Here are a few to test out.

Take a look at some of the other options for robocopy.  There are a bunch to go through, but a couple notable ones are:

  • /B – Enable the backup privilege, allowing it to backup files it doesn’t normally have permission to.
  • /COPYALL – Copy NTFS security information including file ownership and the data and audit ACLs.

Instead of stopping the necessary services, create and mount a volume shadow copy of the NTFS volume and mirror from that location.

The flexibility for ZFS is astounding when it comes to backups and it’s amazing what a simple script can accomplish.