{"id":12,"date":"2009-11-18T22:38:14","date_gmt":"2009-11-19T04:38:14","guid":{"rendered":"http:\/\/www.edplese.com\/blog\/?p=12"},"modified":"2009-11-18T22:38:14","modified_gmt":"2009-11-19T04:38:14","slug":"windows-backups-to-zfs","status":"publish","type":"post","link":"https:\/\/www.edplese.com\/blog\/2009\/11\/18\/windows-backups-to-zfs\/","title":{"rendered":"Windows Backups to ZFS"},"content":{"rendered":"<p>One of the methods I use for backing up Windows applications is to mirror the files to a ZFS file system using <code>robocopy<\/code> and then snapshot the file system to preserve its state.\u00a0 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.<\/p>\n<p>There are a number of features about ZFS that makes it great for backups.\u00a0 Among them are snapshots, compression, efficient incremental sending of file systems and block storage, etc.\u00a0 Dedup will make its appearance in build 128 which will add further benefits as well.\u00a0 All of these help to conserve disk space and speed up backup and restore operations.<\/p>\n<p>This assumes a recent, working OpenSolaris system with the CIFS service already configured.\u00a0 The latest version of OpenSolaris at this time is build 127.\u00a0 For documentation on how to setup the CIFS service, see <a title=\"Getting Started With the Solaris CIFS Service\" href=\"http:\/\/wiki.genunix.org\/wiki\/index.php\/Getting_Started_With_the_Solaris_CIFS_Service\">Getting Started With the Solaris CIFS Service<\/a>.<\/p>\n<p>To start off, create a parent file system for the backups.\u00a0 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.\u00a0 Enable both mixed case sensitivity and non-blocking mandatory locks to enhance compatibility between POSIX and Windows file semantics.\u00a0 Set the <code>sharesmb<\/code> property to share the file system via CIFS and to shorten the names of the shares.\u00a0 The name specified below turns into the <code>backups_<\/code> prefix for the descendant file system share names.\u00a0 Without it, the prefix would be the full file system path, in this case, <code>tank_backups_<\/code>.\u00a0 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.<\/p>\n<pre># zfs create -o casesensitivity=mixed -o nbmand=on -o sharesmb=name=backups tank\/backups\r\n# zfs allow -d backup@edplese.com snapshot,mount tank\/backups<\/pre>\n<p>With the initial setup completed, begin creating the backup sets.\u00a0 Create a descendant file system under <code>tank\/backups<\/code> for each backup set and give the backup user write access to it.\u00a0 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.<\/p>\n<pre># zfs create tank\/backups\/someservice\r\n# chown backup@edplese.com \/tank\/backups\/someservice\r\n# chmod 700 \/tank\/backups\/someservice<\/pre>\n<p>Normally, I enable compression for the entire pool and then disable it for file systems that won&#8217;t see any benefit from it, such as those holding only multimedia files.\u00a0 If compression isn&#8217;t inherited by the backup file systems, it might be beneficial to enable it on them.\u00a0 Those that can spare performance for additional disk space might try <code>gzip<\/code> compression instead of the default <code>lzjb<\/code>.<\/p>\n<pre># zfs set compression=on tank\/backups<\/pre>\n<p>Finally, create a customized Windows batch file and set it to run automatically with the Windows Task Scheduler.<\/p>\n<pre>@echo off\r\nset src=\"D:\\Data\\SomeService\"\r\nset dst=\"\\\\opensolaris\\backups_someservice\"\r\nset service=\"SomeService\"\r\nset timestamp=\"%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%-%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%\"\r\nset timestamp=\"%timestamp: =0%\"\r\n\r\nnet stop \"%service%\"\r\nrobocopy \"%src%\" \"%dst%\" \/MIR\r\nnet start \"%service%\"\r\nmkdir \"%dst%\\.zfs\\snapshot\\%timestamp%\"<\/pre>\n<p>The script is straight-forward, and the only complicated lines are the timestamp ones.\u00a0 Between the two of them they build a timestamp of the form <code>YYYYMMDD-HHMMSS<\/code>.\u00a0 The second line fixes single digits that occur, replacing the leading spaces with zeros.<\/p>\n<p>The last line is interesting in that instead of simply creating a directory, a ZFS snapshot is taken instead.<\/p>\n<p>For restoration, navigate to the share on the server, right-click, select <strong>Properties<\/strong>, and then click on the <strong>Previous Versions<\/strong> tab.\u00a0 From here, you can easily browse through the snapshots.\u00a0 You can also right-click on individual files and then click on <strong>Restore previous version<\/strong> and it will only list the versions of the file that differ rather than displaying every snapshot.<\/p>\n<p><img loading=\"lazy\" class=\"aligncenter size-full wp-image-54\" title=\"Previous Versions\" src=\"http:\/\/edplese.com\/blog\/wp-content\/uploads\/2009\/11\/previousversions.png\" alt=\"Previous Versions\" width=\"368\" height=\"502\" srcset=\"https:\/\/www.edplese.com\/blog\/wp-content\/uploads\/2009\/11\/previousversions.png 368w, https:\/\/www.edplese.com\/blog\/wp-content\/uploads\/2009\/11\/previousversions-219x300.png 219w\" sizes=\"(max-width: 368px) 100vw, 368px\" \/><\/p>\n<p>There are, or course, a number of ways to improve this backup scheme.\u00a0 Here are a few to test out.<\/p>\n<p>Take a look at some of the other options for <code>robocopy<\/code>.\u00a0 There are a bunch to go through, but a couple notable ones are:<\/p>\n<ul>\n<li><code>\/B<\/code> &#8211; Enable the backup privilege, allowing it to backup files it doesn&#8217;t normally have permission to.<\/li>\n<li><code>\/COPYALL<\/code> &#8211; Copy NTFS security information including file ownership and the data and audit ACLs.<\/li>\n<\/ul>\n<p>Instead of stopping the necessary services, create and mount a volume shadow copy of the NTFS volume and mirror from that location.<\/p>\n<p>The flexibility for ZFS is astounding when it comes to backups and it&#8217;s amazing what a simple script can accomplish.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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.\u00a0 I use this primarily for nightly backups and during application maintenance because it typically requires that the service be stopped for the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[4,3,5],"_links":{"self":[{"href":"https:\/\/www.edplese.com\/blog\/wp-json\/wp\/v2\/posts\/12"}],"collection":[{"href":"https:\/\/www.edplese.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.edplese.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.edplese.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.edplese.com\/blog\/wp-json\/wp\/v2\/comments?post=12"}],"version-history":[{"count":49,"href":"https:\/\/www.edplese.com\/blog\/wp-json\/wp\/v2\/posts\/12\/revisions"}],"predecessor-version":[{"id":64,"href":"https:\/\/www.edplese.com\/blog\/wp-json\/wp\/v2\/posts\/12\/revisions\/64"}],"wp:attachment":[{"href":"https:\/\/www.edplese.com\/blog\/wp-json\/wp\/v2\/media?parent=12"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.edplese.com\/blog\/wp-json\/wp\/v2\/categories?post=12"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.edplese.com\/blog\/wp-json\/wp\/v2\/tags?post=12"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}